ibcs2_xenix.c revision 36582
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.14 1997/11/06 19:28:46 phk 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, 8); 161 strncpy(ibcs2_sco_uname.nodename, hostname, 8); 162 strncpy(ibcs2_sco_uname.release, osrelease, 15); 163 strncpy(ibcs2_sco_uname.kernelid, version, 19); 164 strncpy(ibcs2_sco_uname.machine, machine, 8); 165 bcopy("ISA/EISA", ibcs2_sco_uname.bustype, 8); 166 bcopy("no charge", ibcs2_sco_uname.sysserial, 9); 167 bcopy("unlim", ibcs2_sco_uname.numusers, 8); 168 ibcs2_sco_uname.sysorigin = 0xFFFF; 169 ibcs2_sco_uname.sysoem = 0xFFFF; 170 ibcs2_sco_uname.numcpu = 1; 171 return copyout((caddr_t)&ibcs2_sco_uname, (caddr_t)uap->addr, 172 sizeof(struct ibcs2_sco_utsname)); 173} 174 175int 176xenix_scoinfo(struct proc *p, struct xenix_scoinfo_args *uap) 177{ 178 /* scoinfo (not documented) */ 179 p->p_retval[0] = 0; 180 return 0; 181} 182 183int 184xenix_eaccess(struct proc *p, struct xenix_eaccess_args *uap) 185{ 186 struct ucred *cred = p->p_ucred; 187 struct vnode *vp; 188 struct nameidata nd; 189 int error, flags; 190 caddr_t sg = stackgap_init(); 191 192 CHECKALTEXIST(p, &sg, SCARG(uap, path)); 193 194 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, 195 SCARG(uap, path), p); 196 if (error = namei(&nd)) 197 return error; 198 vp = nd.ni_vp; 199 200 /* Flags == 0 means only check for existence. */ 201 if (SCARG(uap, flags)) { 202 flags = 0; 203 if (SCARG(uap, flags) & IBCS2_R_OK) 204 flags |= VREAD; 205 if (SCARG(uap, flags) & IBCS2_W_OK) 206 flags |= VWRITE; 207 if (SCARG(uap, flags) & IBCS2_X_OK) 208 flags |= VEXEC; 209 if ((flags & VWRITE) == 0 || (error = vn_writechk(vp)) == 0) 210 error = VOP_ACCESS(vp, flags, cred, p); 211 } 212 vput(vp); 213 return error; 214} 215