ibcs2_xenix.c revision 27537
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.12 1997/06/22 19:04:03 sef 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, int *retval) 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, retval)); 66 else 67 return ENOSYS; 68} 69 70int 71xenix_rdchk(p, uap, retval) 72 struct proc *p; 73 struct xenix_rdchk_args *uap; 74 int *retval; 75{ 76 int error; 77 struct ioctl_args sa; 78 caddr_t sg = stackgap_init(); 79 80 DPRINTF(("IBCS2: 'xenix rdchk'\n")); 81 SCARG(&sa, fd) = SCARG(uap, fd); 82 SCARG(&sa, com) = FIONREAD; 83 SCARG(&sa, data) = stackgap_alloc(&sg, sizeof(int)); 84 if (error = ioctl(p, &sa, retval)) 85 return error; 86 *retval = (*((int*)SCARG(&sa, data))) ? 1 : 0; 87 return 0; 88} 89 90int 91xenix_chsize(p, uap, retval) 92 struct proc *p; 93 struct xenix_chsize_args *uap; 94 int *retval; 95{ 96 struct ftruncate_args sa; 97 98 DPRINTF(("IBCS2: 'xenix chsize'\n")); 99 SCARG(&sa, fd) = SCARG(uap, fd); 100 SCARG(&sa, pad) = 0; 101 SCARG(&sa, length) = SCARG(uap, size); 102 return ftruncate(p, &sa, retval); 103} 104 105 106int 107xenix_ftime(p, uap, retval) 108 struct proc *p; 109 struct xenix_ftime_args *uap; 110 int *retval; 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 131int 132xenix_nap(struct proc *p, struct xenix_nap_args *uap, int *retval) 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, PUSER, "nap", period) 140 != EWOULDBLOCK) ; 141 return 0; 142} 143 144int 145xenix_utsname(struct proc *p, struct xenix_utsname_args *uap, int *retval) 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, 8); 164 strncpy(ibcs2_sco_uname.nodename, hostname, 8); 165 strncpy(ibcs2_sco_uname.release, osrelease, 15); 166 strncpy(ibcs2_sco_uname.kernelid, version, 19); 167 strncpy(ibcs2_sco_uname.machine, machine, 8); 168 bcopy("ISA/EISA", ibcs2_sco_uname.bustype, 8); 169 bcopy("no charge", ibcs2_sco_uname.sysserial, 9); 170 bcopy("unlim", ibcs2_sco_uname.numusers, 8); 171 ibcs2_sco_uname.sysorigin = 0xFFFF; 172 ibcs2_sco_uname.sysoem = 0xFFFF; 173 ibcs2_sco_uname.numcpu = 1; 174 return copyout((caddr_t)&ibcs2_sco_uname, (caddr_t)uap->addr, 175 sizeof(struct ibcs2_sco_utsname)); 176} 177 178int 179xenix_scoinfo(struct proc *p, struct xenix_scoinfo_args *uap, int *retval) 180{ 181 /* scoinfo (not documented) */ 182 *retval = 0; 183 return 0; 184} 185 186int 187xenix_eaccess(struct proc *p, struct xenix_eaccess_args *uap, int *retval) 188{ 189 struct ucred *cred = p->p_ucred; 190 struct vnode *vp; 191 struct nameidata nd; 192 int error, flags; 193 caddr_t sg = stackgap_init(); 194 195 CHECKALTEXIST(p, &sg, SCARG(uap, path)); 196 197 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, 198 SCARG(uap, path), p); 199 if (error = namei(&nd)) 200 return error; 201 vp = nd.ni_vp; 202 203 /* Flags == 0 means only check for existence. */ 204 if (SCARG(uap, flags)) { 205 flags = 0; 206 if (SCARG(uap, flags) & IBCS2_R_OK) 207 flags |= VREAD; 208 if (SCARG(uap, flags) & IBCS2_W_OK) 209 flags |= VWRITE; 210 if (SCARG(uap, flags) & IBCS2_X_OK) 211 flags |= VEXEC; 212 if ((flags & VWRITE) == 0 || (error = vn_writechk(vp)) == 0) 213 error = VOP_ACCESS(vp, flags, cred, p); 214 } 215 vput(vp); 216 return error; 217} 218