ibcs2_xenix.c revision 41514
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 withough 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 *	$Id: ibcs2_xenix.c,v 1.16 1998/08/16 01:21:49 bde Exp $
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/kernel.h>
38#include <sys/filio.h>
39#include <sys/vnode.h>
40#include <sys/sysctl.h>
41
42#include <machine/cpu.h>
43
44#include <i386/ibcs2/ibcs2_types.h>
45#include <i386/ibcs2/ibcs2_unistd.h>
46#include <i386/ibcs2/ibcs2_signal.h>
47#include <i386/ibcs2/ibcs2_util.h>
48#include <i386/ibcs2/ibcs2_proto.h>
49#include <i386/ibcs2/ibcs2_xenix.h>
50#include <i386/ibcs2/ibcs2_xenix_syscall.h>
51
52extern struct sysent xenix_sysent[];
53
54int
55ibcs2_xenix(struct proc *p, struct ibcs2_xenix_args *uap)
56{
57	struct trapframe *tf = p->p_md.md_regs;
58        struct sysent *callp;
59        u_int code;
60
61	code = (tf->tf_eax & 0xff00) >> 8;
62	callp = &xenix_sysent[code];
63
64	if(code < IBCS2_XENIX_MAXSYSCALL)
65	  return((*callp->sy_call)(p, (void *)uap));
66	else
67	  return ENOSYS;
68}
69
70int
71xenix_rdchk(p, uap)
72	struct proc *p;
73	struct xenix_rdchk_args *uap;
74{
75	int error;
76	struct ioctl_args sa;
77	caddr_t sg = stackgap_init();
78
79	DPRINTF(("IBCS2: 'xenix rdchk'\n"));
80	SCARG(&sa, fd) = SCARG(uap, fd);
81	SCARG(&sa, com) = FIONREAD;
82	SCARG(&sa, data) = stackgap_alloc(&sg, sizeof(int));
83	if (error = ioctl(p, &sa))
84		return error;
85	p->p_retval[0] = (*((int*)SCARG(&sa, data))) ? 1 : 0;
86	return 0;
87}
88
89int
90xenix_chsize(p, uap)
91	struct proc *p;
92	struct xenix_chsize_args *uap;
93{
94	struct ftruncate_args sa;
95
96	DPRINTF(("IBCS2: 'xenix chsize'\n"));
97	SCARG(&sa, fd) = SCARG(uap, fd);
98	SCARG(&sa, pad) = 0;
99	SCARG(&sa, length) = SCARG(uap, size);
100	return ftruncate(p, &sa);
101}
102
103
104int
105xenix_ftime(p, uap)
106	struct proc *p;
107	struct xenix_ftime_args *uap;
108{
109	struct timeval tv;
110	struct ibcs2_timeb {
111		unsigned long time __attribute__((packed));
112		unsigned short millitm;
113		short timezone;
114		short dstflag;
115	} itb;
116
117	DPRINTF(("IBCS2: 'xenix ftime'\n"));
118	microtime(&tv);
119	itb.time = tv.tv_sec;
120	itb.millitm = (tv.tv_usec / 1000);
121	itb.timezone = tz.tz_minuteswest;
122	itb.dstflag = tz.tz_dsttime != DST_NONE;
123
124	return copyout((caddr_t)&itb, (caddr_t)SCARG(uap, tp),
125		       sizeof(struct ibcs2_timeb));
126}
127
128int
129xenix_nap(struct proc *p, struct xenix_nap_args *uap)
130{
131	long period;
132
133	DPRINTF(("IBCS2: 'xenix nap %d ms'\n", SCARG(uap, millisec)));
134	period = (long)SCARG(uap, millisec) / (1000/hz);
135	if (period)
136		while (tsleep(&period, PPAUSE, "nap", period)
137		       != EWOULDBLOCK) ;
138	return 0;
139}
140
141int
142xenix_utsname(struct proc *p, struct xenix_utsname_args *uap)
143{
144	struct ibcs2_sco_utsname {
145		char sysname[9];
146		char nodename[9];
147		char release[16];
148		char kernelid[20];
149		char machine[9];
150		char bustype[9];
151		char sysserial[10];
152		unsigned short sysorigin;
153		unsigned short sysoem;
154		char numusers[9];
155		unsigned short numcpu;
156	} ibcs2_sco_uname;
157
158	DPRINTF(("IBCS2: 'xenix sco_utsname'\n"));
159	bzero(&ibcs2_sco_uname, sizeof(struct ibcs2_sco_utsname));
160	strncpy(ibcs2_sco_uname.sysname, ostype,
161		sizeof(ibcs2_sco_uname.sysname) - 1);
162	strncpy(ibcs2_sco_uname.nodename, hostname,
163		sizeof(ibcs2_sco_uname.nodename) - 1);
164	strncpy(ibcs2_sco_uname.release, osrelease,
165		sizeof(ibcs2_sco_uname.release) - 1);
166	strncpy(ibcs2_sco_uname.kernelid, version,
167		sizeof(ibcs2_sco_uname.kernelid) - 1);
168	strncpy(ibcs2_sco_uname.machine, machine,
169		sizeof(ibcs2_sco_uname.machine) - 1);
170	strncpy(ibcs2_sco_uname.bustype, "ISA/EISA",
171		sizeof(ibcs2_sco_uname.bustype) - 1);
172	strncpy(ibcs2_sco_uname.sysserial, "no charge",
173		sizeof(ibcs2_sco_uname.sysserial) - 1);
174	strncpy(ibcs2_sco_uname.numusers, "unlim",
175		sizeof(ibcs2_sco_uname.numusers) - 1);
176	ibcs2_sco_uname.sysorigin = 0xFFFF;
177	ibcs2_sco_uname.sysoem = 0xFFFF;
178	ibcs2_sco_uname.numcpu = 1;
179	return copyout((caddr_t)&ibcs2_sco_uname,
180		       (caddr_t)(void *)(intptr_t)uap->addr,
181		       sizeof(struct ibcs2_sco_utsname));
182}
183
184int
185xenix_scoinfo(struct proc *p, struct xenix_scoinfo_args *uap)
186{
187  /* scoinfo (not documented) */
188  p->p_retval[0] = 0;
189  return 0;
190}
191
192int
193xenix_eaccess(struct proc *p, struct xenix_eaccess_args *uap)
194{
195	struct ucred *cred = p->p_ucred;
196	struct vnode *vp;
197        struct nameidata nd;
198        int error, flags;
199	caddr_t sg = stackgap_init();
200
201	CHECKALTEXIST(p, &sg, SCARG(uap, path));
202
203        NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
204            SCARG(uap, path), p);
205        if (error = namei(&nd))
206                return error;
207        vp = nd.ni_vp;
208
209        /* Flags == 0 means only check for existence. */
210        if (SCARG(uap, flags)) {
211                flags = 0;
212                if (SCARG(uap, flags) & IBCS2_R_OK)
213                        flags |= VREAD;
214                if (SCARG(uap, flags) & IBCS2_W_OK)
215                        flags |= VWRITE;
216                if (SCARG(uap, flags) & IBCS2_X_OK)
217                        flags |= VEXEC;
218                if ((flags & VWRITE) == 0 || (error = vn_writechk(vp)) == 0)
219                        error = VOP_ACCESS(vp, flags, cred, p);
220        }
221        vput(vp);
222        return error;
223}
224