1 /*-
2 * Copyright (c) 1994 Sean Eric Fagan
3 * Copyright (c) 1994 Søren Schmidt
4 * Copyright (c) 1995 Steven Wallace
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer
12 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $FreeBSD: releng/5.0/sys/i386/ibcs2/ibcs2_xenix.c 108086 2002-12-19 09:40:13Z alfred $
31 */
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/namei.h>
36 #include <sys/sysproto.h>
37 #include <sys/jail.h>
38 #include <sys/kernel.h>
39 #include <sys/filio.h>
40 #include <sys/vnode.h>
41 #include <sys/sysctl.h>
42
43 #include <machine/cpu.h>
44
45 #include <i386/ibcs2/ibcs2_types.h>
46 #include <i386/ibcs2/ibcs2_unistd.h>
47 #include <i386/ibcs2/ibcs2_signal.h>
48 #include <i386/ibcs2/ibcs2_util.h>
49 #include <i386/ibcs2/ibcs2_proto.h>
50 #include <i386/ibcs2/ibcs2_xenix.h>
51 #include <i386/ibcs2/ibcs2_xenix_syscall.h>
52
53
54 extern struct sysent xenix_sysent[];
55
56 int
57 ibcs2_xenix(struct thread *td, struct ibcs2_xenix_args *uap)
58 {
59 struct trapframe *tf = td->td_frame;
60 struct sysent *callp;
61 u_int code;
62
63 code = (tf->tf_eax & 0xff00) >> 8;
64 callp = &xenix_sysent[code];
65
66 if(code < IBCS2_XENIX_MAXSYSCALL)
67 return((*callp->sy_call)(td, (void *)uap));
68 else
69 return ENOSYS;
70 }
71
72 int
73 xenix_rdchk(td, uap)
74 struct thread *td;
75 struct xenix_rdchk_args *uap;
76 {
77 int error;
78 struct ioctl_args sa;
79 caddr_t sg = stackgap_init();
80
81 DPRINTF(("IBCS2: 'xenix rdchk'\n"));
82 sa.fd = uap->fd;
83 sa.com = FIONREAD;
84 sa.data = stackgap_alloc(&sg, sizeof(int));
85 if ((error = ioctl(td, &sa)) != 0)
86 return error;
87 td->td_retval[0] = (*((int*)sa.data)) ? 1 : 0;
88 return 0;
89 }
90
91 int
92 xenix_chsize(td, uap)
93 struct thread *td;
94 struct xenix_chsize_args *uap;
95 {
96 struct ftruncate_args sa;
97
98 DPRINTF(("IBCS2: 'xenix chsize'\n"));
99 sa.fd = uap->fd;
100 sa.pad = 0;
101 sa.length = uap->size;
102 return ftruncate(td, &sa);
103 }
104
105
106 int
107 xenix_ftime(td, uap)
108 struct thread *td;
109 struct xenix_ftime_args *uap;
110 {
111 struct timeval tv;
112 struct ibcs2_timeb {
113 unsigned long time __packed;
114 unsigned short millitm;
115 short timezone;
116 short dstflag;
117 } itb;
118
119 DPRINTF(("IBCS2: 'xenix ftime'\n"));
120 microtime(&tv);
121 itb.time = tv.tv_sec;
122 itb.millitm = (tv.tv_usec / 1000);
123 itb.timezone = tz.tz_minuteswest;
124 itb.dstflag = tz.tz_dsttime != DST_NONE;
125
126 return copyout((caddr_t)&itb, (caddr_t)uap->tp,
127 sizeof(struct ibcs2_timeb));
128 }
129
130 int
131 xenix_nap(struct thread *td, struct xenix_nap_args *uap)
132 {
133 long period;
134
135 DPRINTF(("IBCS2: 'xenix nap %d ms'\n", uap->millisec));
136 period = (long)uap->millisec / (1000/hz);
137 if (period)
138 while (tsleep(&period, PPAUSE, "nap", period)
139 != EWOULDBLOCK) ;
140 return 0;
141 }
142
143 int
144 xenix_utsname(struct thread *td, struct xenix_utsname_args *uap)
145 {
146 struct ibcs2_sco_utsname {
147 char sysname[9];
148 char nodename[9];
149 char release[16];
150 char kernelid[20];
151 char machine[9];
152 char bustype[9];
153 char sysserial[10];
154 unsigned short sysorigin;
155 unsigned short sysoem;
156 char numusers[9];
157 unsigned short numcpu;
158 } ibcs2_sco_uname;
159
160 DPRINTF(("IBCS2: 'xenix sco_utsname'\n"));
161 bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname));
162 strncpy(ibcs2_sco_uname.sysname, ostype,
163 sizeof(ibcs2_sco_uname.sysname) - 1);
164 getcredhostname(td->td_ucred, ibcs2_sco_uname.nodename,
165 sizeof(ibcs2_sco_uname.nodename) - 1);
166 strncpy(ibcs2_sco_uname.release, osrelease,
167 sizeof(ibcs2_sco_uname.release) - 1);
168 strncpy(ibcs2_sco_uname.kernelid, version,
169 sizeof(ibcs2_sco_uname.kernelid) - 1);
170 strncpy(ibcs2_sco_uname.machine, machine,
171 sizeof(ibcs2_sco_uname.machine) - 1);
172 strncpy(ibcs2_sco_uname.bustype, "ISA/EISA",
173 sizeof(ibcs2_sco_uname.bustype) - 1);
174 strncpy(ibcs2_sco_uname.sysserial, "no charge",
175 sizeof(ibcs2_sco_uname.sysserial) - 1);
176 strncpy(ibcs2_sco_uname.numusers, "unlim",
177 sizeof(ibcs2_sco_uname.numusers) - 1);
178 ibcs2_sco_uname.sysorigin = 0xFFFF;
179 ibcs2_sco_uname.sysoem = 0xFFFF;
180 ibcs2_sco_uname.numcpu = 1;
181 return copyout((caddr_t)&ibcs2_sco_uname,
182 (caddr_t)(void *)(intptr_t)uap->addr,
183 sizeof(struct ibcs2_sco_utsname));
184 }
185
186 int
187 xenix_scoinfo(struct thread *td, struct xenix_scoinfo_args *uap)
188 {
189 /* scoinfo (not documented) */
190 td->td_retval[0] = 0;
191 return 0;
192 }
193
194 int
195 xenix_eaccess(struct thread *td, struct xenix_eaccess_args *uap)
196 {
197 struct ucred *cred = td->td_ucred;
198 struct vnode *vp;
199 struct nameidata nd;
200 int error, flags;
201 caddr_t sg = stackgap_init();
202
203 CHECKALTEXIST(td, &sg, uap->path);
204
205 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
206 uap->path, td);
207 if ((error = namei(&nd)) != 0)
208 return error;
209 vp = nd.ni_vp;
210
211 /* Flags == 0 means only check for existence. */
212 if (uap->flags) {
213 flags = 0;
214 if (uap->flags & IBCS2_R_OK)
215 flags |= VREAD;
216 if (uap->flags & IBCS2_W_OK)
217 flags |= VWRITE;
218 if (uap->flags & IBCS2_X_OK)
219 flags |= VEXEC;
220 if ((flags & VWRITE) == 0 || (error = vn_writechk(vp)) == 0)
221 error = VOP_ACCESS(vp, flags, cred, td);
222 }
223 NDFREE(&nd, NDF_ONLY_PNBUF);
224 vput(vp);
225 return error;
226 }
Cache object: 88fa31603b3280e849b2378c8c65a457
|