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