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