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