2 * Copyright (c) 1995 Steven Wallace
3 * Copyright (c) 1994, 1995 Scott Bartram
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
46 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
48 * $FreeBSD: src/sys/i386/ibcs2/ibcs2_misc.c,v 1.34 1999/09/29 15:12:09 marcel Exp $
49 * $DragonFly: src/sys/emulation/ibcs2/i386/Attic/ibcs2_misc.c,v 1.2 2003/06/17 04:28:35 dillon Exp $
53 * IBCS2 compatibility module.
55 * IBCS2 system calls that are implemented differently in BSD are
58 #include <sys/param.h>
59 #include <sys/dirent.h>
60 #include <sys/fcntl.h>
62 #include <sys/filedesc.h>
63 #include <sys/kernel.h>
65 #include <sys/malloc.h>
66 #include <sys/reboot.h>
67 #include <sys/resourcevar.h>
69 #include <sys/sysctl.h>
70 #include <sys/sysproto.h>
71 #include <sys/systm.h>
73 #include <sys/times.h>
74 #include <sys/vnode.h>
77 #include <machine/cpu.h>
79 #include <i386/ibcs2/ibcs2_dirent.h>
80 #include <i386/ibcs2/ibcs2_signal.h>
81 #include <i386/ibcs2/ibcs2_proto.h>
82 #include <i386/ibcs2/ibcs2_unistd.h>
83 #include <i386/ibcs2/ibcs2_util.h>
84 #include <i386/ibcs2/ibcs2_utime.h>
85 #include <i386/ibcs2/ibcs2_xenix.h>
90 struct ibcs2_ulimit_args *uap;
95 struct setrlimit_args {
100 #define IBCS2_GETFSIZE 1
101 #define IBCS2_SETFSIZE 2
102 #define IBCS2_GETPSIZE 3
103 #define IBCS2_GETDTABLESIZE 4
105 switch (SCARG(uap, cmd)) {
107 p->p_retval[0] = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
108 if (p->p_retval[0] == -1) p->p_retval[0] = 0x7fffffff;
110 case IBCS2_SETFSIZE: /* XXX - fix this */
112 rl.rlim_cur = SCARG(uap, newlimit);
113 sra.resource = RLIMIT_FSIZE;
115 error = setrlimit(p, &sra);
117 p->p_retval[0] = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
119 DPRINTF(("failed "));
122 p->p_retval[0] = SCARG(uap, newlimit);
126 p->p_retval[0] = p->p_rlimit[RLIMIT_RSS].rlim_cur; /* XXX */
128 case IBCS2_GETDTABLESIZE:
129 uap->cmd = IBCS2_SC_OPEN_MAX;
130 return ibcs2_sysconf(p, (struct ibcs2_sysconf_args *)uap);
136 #define IBCS2_WSTOPPED 0177
137 #define IBCS2_STOPCODE(sig) ((sig) << 8 | IBCS2_WSTOPPED)
141 struct ibcs2_wait_args *uap;
145 struct trapframe *tf = p->p_md.md_regs;
147 SCARG(&w4, rusage) = NULL;
148 if ((tf->tf_eflags & (PSL_Z|PSL_PF|PSL_N|PSL_V))
149 == (PSL_Z|PSL_PF|PSL_N|PSL_V)) {
151 SCARG(&w4, pid) = SCARG(uap, a1);
152 SCARG(&w4, status) = (int *)SCARG(uap, a2);
153 SCARG(&w4, options) = SCARG(uap, a3);
156 SCARG(&w4, pid) = WAIT_ANY;
157 SCARG(&w4, status) = (int *)SCARG(uap, a1);
158 SCARG(&w4, options) = 0;
160 if ((error = wait4(p, &w4)) != 0)
162 if (SCARG(&w4, status)) { /* this is real iBCS brain-damage */
163 error = copyin((caddr_t)SCARG(&w4, status), (caddr_t)&status,
164 sizeof(SCARG(&w4, status)));
168 /* convert status/signal result */
169 if(WIFSTOPPED(status))
171 IBCS2_STOPCODE(bsd_to_ibcs2_sig[_SIG_IDX(WSTOPSIG(status))]);
172 else if(WIFSIGNALED(status))
173 status = bsd_to_ibcs2_sig[_SIG_IDX(WTERMSIG(status))];
174 /* else exit status -- identical */
176 /* record result/status */
177 p->p_retval[1] = status;
178 return copyout((caddr_t)&status, (caddr_t)SCARG(&w4, status),
179 sizeof(SCARG(&w4, status)));
188 struct ibcs2_execv_args *uap;
190 struct execve_args ea;
191 caddr_t sg = stackgap_init();
193 CHECKALTEXIST(p, &sg, SCARG(uap, path));
194 SCARG(&ea, fname) = SCARG(uap, path);
195 SCARG(&ea, argv) = SCARG(uap, argp);
196 SCARG(&ea, envv) = NULL;
197 return execve(p, &ea);
203 struct ibcs2_execve_args *uap;
205 caddr_t sg = stackgap_init();
206 CHECKALTEXIST(p, &sg, SCARG(uap, path));
207 return execve(p, (struct execve_args *)uap);
213 struct ibcs2_umount_args *uap;
215 struct unmount_args um;
217 SCARG(&um, path) = SCARG(uap, name);
218 SCARG(&um, flags) = 0;
219 return unmount(p, &um);
225 struct ibcs2_mount_args *uap;
228 int oflags = SCARG(uap, flags), nflags, error;
229 char fsname[MFSNAMELEN];
231 if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5))
233 if ((oflags & IBCS2_MS_NEWTYPE) == 0)
236 if (oflags & IBCS2_MS_RDONLY)
237 nflags |= MNT_RDONLY;
238 if (oflags & IBCS2_MS_NOSUID)
239 nflags |= MNT_NOSUID;
240 if (oflags & IBCS2_MS_REMOUNT)
241 nflags |= MNT_UPDATE;
242 SCARG(uap, flags) = nflags;
244 if (error = copyinstr((caddr_t)SCARG(uap, type), fsname, sizeof fsname,
248 if (strcmp(fsname, "4.2") == 0) {
249 SCARG(uap, type) = (caddr_t)STACK_ALLOC();
250 if (error = copyout("ufs", SCARG(uap, type), sizeof("ufs")))
252 } else if (strcmp(fsname, "nfs") == 0) {
253 struct ibcs2_nfs_args sna;
254 struct sockaddr_in sain;
258 if (error = copyin(SCARG(uap, data), &sna, sizeof sna))
260 if (error = copyin(sna.addr, &sain, sizeof sain))
262 bcopy(&sain, &sa, sizeof sa);
263 sa.sa_len = sizeof(sain);
264 SCARG(uap, data) = (caddr_t)STACK_ALLOC();
265 na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na);
266 na.sotype = SOCK_DGRAM;
267 na.proto = IPPROTO_UDP;
268 na.fh = (nfsv2fh_t *)sna.fh;
269 na.flags = sna.flags;
270 na.wsize = sna.wsize;
271 na.rsize = sna.rsize;
272 na.timeo = sna.timeo;
273 na.retrans = sna.retrans;
274 na.hostname = sna.hostname;
276 if (error = copyout(&sa, na.addr, sizeof sa))
278 if (error = copyout(&na, SCARG(uap, data), sizeof na))
281 return (mount(p, uap));
288 * Read iBCS2-style directory entries. We suck them into kernel space so
289 * that they can be massaged before being copied out to user code. Like
290 * SunOS, we squish out `empty' entries.
292 * This is quite ugly, but what do you expect from compatibility code?
296 ibcs2_getdents(p, uap)
298 register struct ibcs2_getdents_args *uap;
300 register struct vnode *vp;
301 register caddr_t inp, buf; /* BSD-format */
302 register int len, reclen; /* BSD-format */
303 register caddr_t outp; /* iBCS2-format */
304 register int resid; /* iBCS2-format */
308 struct ibcs2_dirent idb;
309 off_t off; /* true file offset */
310 int buflen, error, eofflag;
311 u_long *cookies = NULL, *cookiep;
313 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
314 #define IBCS2_RECLEN(reclen) (reclen + sizeof(u_short))
316 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
318 if ((fp->f_flag & FREAD) == 0)
320 vp = (struct vnode *)fp->f_data;
321 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
325 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
326 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
327 buflen = min(buflen, MAXBSIZE);
328 buf = malloc(buflen, M_TEMP, M_WAITOK);
329 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
332 aiov.iov_len = buflen;
333 auio.uio_iov = &aiov;
335 auio.uio_rw = UIO_READ;
336 auio.uio_segflg = UIO_SYSSPACE;
338 auio.uio_resid = buflen;
339 auio.uio_offset = off;
342 free(cookies, M_TEMP);
347 * First we read into the malloc'ed buffer, then
348 * we massage it into user space, one record at a time.
350 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0)
353 outp = SCARG(uap, buf);
354 resid = SCARG(uap, nbytes);
355 if ((len = buflen - auio.uio_resid) <= 0)
362 * When using cookies, the vfs has the option of reading from
363 * a different offset than that supplied (UFS truncates the
364 * offset to a block boundary to make sure that it never reads
365 * partway through a directory entry, even if the directory
366 * has been compacted).
368 while (len > 0 && ncookies > 0 && *cookiep <= off) {
369 len -= BSD_DIRENT(inp)->d_reclen;
370 inp += BSD_DIRENT(inp)->d_reclen;
376 for (; len > 0; len -= reclen) {
377 if (cookiep && ncookies == 0)
379 reclen = BSD_DIRENT(inp)->d_reclen;
381 printf("ibcs2_getdents: reclen=%d\n", reclen);
385 if (BSD_DIRENT(inp)->d_fileno == 0) {
386 inp += reclen; /* it is a hole; squish it out */
394 if (reclen > len || resid < IBCS2_RECLEN(reclen)) {
395 /* entry too big for buffer, so just stop */
400 * Massage in place to make a iBCS2-shaped dirent (otherwise
401 * we have to worry about touching user memory outside of
402 * the copyout() call).
404 idb.d_ino = (ibcs2_ino_t)BSD_DIRENT(inp)->d_fileno;
405 idb.d_off = (ibcs2_off_t)off;
406 idb.d_reclen = (u_short)IBCS2_RECLEN(reclen);
407 if ((error = copyout((caddr_t)&idb, outp, 10)) != 0 ||
408 (error = copyout(BSD_DIRENT(inp)->d_name, outp + 10,
409 BSD_DIRENT(inp)->d_namlen + 1)) != 0)
411 /* advance past this real entry */
418 /* advance output past iBCS2-shaped entry */
419 outp += IBCS2_RECLEN(reclen);
420 resid -= IBCS2_RECLEN(reclen);
422 /* if we squished out the whole block, try again */
423 if (outp == SCARG(uap, buf))
425 fp->f_offset = off; /* update the vnode offset */
427 p->p_retval[0] = SCARG(uap, nbytes) - resid;
430 free(cookies, M_TEMP);
431 VOP_UNLOCK(vp, 0, p);
439 struct ibcs2_read_args *uap;
441 register struct vnode *vp;
442 register caddr_t inp, buf; /* BSD-format */
443 register int len, reclen; /* BSD-format */
444 register caddr_t outp; /* iBCS2-format */
445 register int resid; /* iBCS2-format */
449 struct ibcs2_direct {
453 off_t off; /* true file offset */
454 int buflen, error, eofflag, size;
455 u_long *cookies = NULL, *cookiep;
458 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) {
460 return read(p, (struct read_args *)uap);
464 if ((fp->f_flag & FREAD) == 0)
466 vp = (struct vnode *)fp->f_data;
467 if (vp->v_type != VDIR)
468 return read(p, (struct read_args *)uap);
470 DPRINTF(("ibcs2_read: read directory\n"));
473 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
474 buflen = min(buflen, MAXBSIZE);
475 buf = malloc(buflen, M_TEMP, M_WAITOK);
476 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
479 aiov.iov_len = buflen;
480 auio.uio_iov = &aiov;
482 auio.uio_rw = UIO_READ;
483 auio.uio_segflg = UIO_SYSSPACE;
485 auio.uio_resid = buflen;
486 auio.uio_offset = off;
489 free(cookies, M_TEMP);
494 * First we read into the malloc'ed buffer, then
495 * we massage it into user space, one record at a time.
497 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0) {
498 DPRINTF(("VOP_READDIR failed: %d\n", error));
502 outp = SCARG(uap, buf);
503 resid = SCARG(uap, nbytes);
504 if ((len = buflen - auio.uio_resid) <= 0)
511 * When using cookies, the vfs has the option of reading from
512 * a different offset than that supplied (UFS truncates the
513 * offset to a block boundary to make sure that it never reads
514 * partway through a directory entry, even if the directory
515 * has been compacted).
517 while (len > 0 && ncookies > 0 && *cookiep <= off) {
518 len -= BSD_DIRENT(inp)->d_reclen;
519 inp += BSD_DIRENT(inp)->d_reclen;
525 for (; len > 0 && resid > 0; len -= reclen) {
526 if (cookiep && ncookies == 0)
528 reclen = BSD_DIRENT(inp)->d_reclen;
530 printf("ibcs2_read: reclen=%d\n", reclen);
534 if (BSD_DIRENT(inp)->d_fileno == 0) {
535 inp += reclen; /* it is a hole; squish it out */
543 if (reclen > len || resid < sizeof(struct ibcs2_direct)) {
544 /* entry too big for buffer, so just stop */
549 * Massage in place to make a iBCS2-shaped dirent (otherwise
550 * we have to worry about touching user memory outside of
551 * the copyout() call).
553 * TODO: if length(filename) > 14, then break filename into
554 * multiple entries and set inode = 0xffff except last
556 idb.ino = (BSD_DIRENT(inp)->d_fileno > 0xfffe) ? 0xfffe :
557 BSD_DIRENT(inp)->d_fileno;
558 (void)copystr(BSD_DIRENT(inp)->d_name, idb.name, 14, &size);
559 bzero(idb.name + size, 14 - size);
560 if ((error = copyout(&idb, outp, sizeof(struct ibcs2_direct))) != 0)
562 /* advance past this real entry */
569 /* advance output past iBCS2-shaped entry */
570 outp += sizeof(struct ibcs2_direct);
571 resid -= sizeof(struct ibcs2_direct);
573 /* if we squished out the whole block, try again */
574 if (outp == SCARG(uap, buf))
576 fp->f_offset = off; /* update the vnode offset */
578 p->p_retval[0] = SCARG(uap, nbytes) - resid;
581 free(cookies, M_TEMP);
582 VOP_UNLOCK(vp, 0, p);
590 struct ibcs2_mknod_args *uap;
592 caddr_t sg = stackgap_init();
594 CHECKALTCREAT(p, &sg, SCARG(uap, path));
595 if (S_ISFIFO(SCARG(uap, mode))) {
596 struct mkfifo_args ap;
597 SCARG(&ap, path) = SCARG(uap, path);
598 SCARG(&ap, mode) = SCARG(uap, mode);
599 return mkfifo(p, &ap);
601 struct mknod_args ap;
602 SCARG(&ap, path) = SCARG(uap, path);
603 SCARG(&ap, mode) = SCARG(uap, mode);
604 SCARG(&ap, dev) = SCARG(uap, dev);
605 return mknod(p, &ap);
610 ibcs2_getgroups(p, uap)
612 struct ibcs2_getgroups_args *uap;
615 ibcs2_gid_t *iset = NULL;
616 struct getgroups_args sa;
618 caddr_t sg = stackgap_init();
620 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
621 if (SCARG(uap, gidsetsize)) {
622 SCARG(&sa, gidset) = stackgap_alloc(&sg, NGROUPS_MAX *
624 iset = stackgap_alloc(&sg, SCARG(uap, gidsetsize) *
625 sizeof(ibcs2_gid_t));
627 if ((error = getgroups(p, &sa)) != 0)
629 if (SCARG(uap, gidsetsize) == 0)
632 for (i = 0, gp = SCARG(&sa, gidset); i < p->p_retval[0]; i++)
633 iset[i] = (ibcs2_gid_t)*gp++;
634 if (p->p_retval[0] && (error = copyout((caddr_t)iset,
635 (caddr_t)SCARG(uap, gidset),
636 sizeof(ibcs2_gid_t) * p->p_retval[0])))
642 ibcs2_setgroups(p, uap)
644 struct ibcs2_setgroups_args *uap;
648 struct setgroups_args sa;
650 caddr_t sg = stackgap_init();
652 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
653 SCARG(&sa, gidset) = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
655 iset = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
656 sizeof(ibcs2_gid_t *));
657 if (SCARG(&sa, gidsetsize)) {
658 if ((error = copyin((caddr_t)SCARG(uap, gidset), (caddr_t)iset,
659 sizeof(ibcs2_gid_t *) *
660 SCARG(uap, gidsetsize))) != 0)
663 for (i = 0, gp = SCARG(&sa, gidset); i < SCARG(&sa, gidsetsize); i++)
664 *gp++ = (gid_t)iset[i];
665 return setgroups(p, &sa);
671 struct ibcs2_setuid_args *uap;
673 struct setuid_args sa;
675 SCARG(&sa, uid) = (uid_t)SCARG(uap, uid);
676 return setuid(p, &sa);
682 struct ibcs2_setgid_args *uap;
684 struct setgid_args sa;
686 SCARG(&sa, gid) = (gid_t)SCARG(uap, gid);
687 return setgid(p, &sa);
693 struct ibcs2_time_args *uap;
698 p->p_retval[0] = tv.tv_sec;
700 return copyout((caddr_t)&tv.tv_sec, (caddr_t)SCARG(uap, tp),
701 sizeof(ibcs2_time_t));
707 ibcs2_pathconf(p, uap)
709 struct ibcs2_pathconf_args *uap;
711 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
712 return pathconf(p, (struct pathconf_args *)uap);
716 ibcs2_fpathconf(p, uap)
718 struct ibcs2_fpathconf_args *uap;
720 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
721 return fpathconf(p, (struct fpathconf_args *)uap);
725 ibcs2_sysconf(p, uap)
727 struct ibcs2_sysconf_args *uap;
729 int mib[2], value, len, error;
730 struct sysctl_args sa;
731 struct __getrlimit_args ga;
733 switch(SCARG(uap, name)) {
734 case IBCS2_SC_ARG_MAX:
735 mib[1] = KERN_ARGMAX;
738 case IBCS2_SC_CHILD_MAX:
740 caddr_t sg = stackgap_init();
742 SCARG(&ga, which) = RLIMIT_NPROC;
743 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
744 if ((error = getrlimit(p, &ga)) != 0)
746 p->p_retval[0] = SCARG(&ga, rlp)->rlim_cur;
750 case IBCS2_SC_CLK_TCK:
754 case IBCS2_SC_NGROUPS_MAX:
755 mib[1] = KERN_NGROUPS;
758 case IBCS2_SC_OPEN_MAX:
760 caddr_t sg = stackgap_init();
762 SCARG(&ga, which) = RLIMIT_NOFILE;
763 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
764 if ((error = getrlimit(p, &ga)) != 0)
766 p->p_retval[0] = SCARG(&ga, rlp)->rlim_cur;
770 case IBCS2_SC_JOB_CONTROL:
771 mib[1] = KERN_JOB_CONTROL;
774 case IBCS2_SC_SAVED_IDS:
775 mib[1] = KERN_SAVED_IDS;
778 case IBCS2_SC_VERSION:
779 mib[1] = KERN_POSIX1;
782 case IBCS2_SC_PASS_MAX:
783 p->p_retval[0] = 128; /* XXX - should we create PASS_MAX ? */
786 case IBCS2_SC_XOPEN_VERSION:
787 p->p_retval[0] = 2; /* XXX: What should that be? */
796 SCARG(&sa, name) = mib;
797 SCARG(&sa, namelen) = 2;
798 SCARG(&sa, old) = &value;
799 SCARG(&sa, oldlenp) = &len;
800 SCARG(&sa, new) = NULL;
801 SCARG(&sa, newlen) = 0;
802 if ((error = __sysctl(p, &sa)) != 0)
804 p->p_retval[0] = value;
811 struct ibcs2_alarm_args *uap;
814 struct itimerval *itp, *oitp;
815 struct setitimer_args sa;
816 caddr_t sg = stackgap_init();
818 itp = stackgap_alloc(&sg, sizeof(*itp));
819 oitp = stackgap_alloc(&sg, sizeof(*oitp));
820 timevalclear(&itp->it_interval);
821 itp->it_value.tv_sec = SCARG(uap, sec);
822 itp->it_value.tv_usec = 0;
824 SCARG(&sa, which) = ITIMER_REAL;
825 SCARG(&sa, itv) = itp;
826 SCARG(&sa, oitv) = oitp;
827 error = setitimer(p, &sa);
830 if (oitp->it_value.tv_usec)
831 oitp->it_value.tv_sec++;
832 p->p_retval[0] = oitp->it_value.tv_sec;
839 struct ibcs2_times_args *uap;
842 struct getrusage_args ga;
845 caddr_t sg = stackgap_init();
846 struct rusage *ru = stackgap_alloc(&sg, sizeof(*ru));
847 #define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
849 SCARG(&ga, who) = RUSAGE_SELF;
850 SCARG(&ga, rusage) = ru;
851 error = getrusage(p, &ga);
854 tms.tms_utime = CONVTCK(ru->ru_utime);
855 tms.tms_stime = CONVTCK(ru->ru_stime);
857 SCARG(&ga, who) = RUSAGE_CHILDREN;
858 error = getrusage(p, &ga);
861 tms.tms_cutime = CONVTCK(ru->ru_utime);
862 tms.tms_cstime = CONVTCK(ru->ru_stime);
865 p->p_retval[0] = CONVTCK(t);
867 return copyout((caddr_t)&tms, (caddr_t)SCARG(uap, tp),
874 struct ibcs2_stime_args *uap;
877 struct settimeofday_args sa;
878 caddr_t sg = stackgap_init();
880 SCARG(&sa, tv) = stackgap_alloc(&sg, sizeof(*SCARG(&sa, tv)));
881 SCARG(&sa, tzp) = NULL;
882 if ((error = copyin((caddr_t)SCARG(uap, timep),
883 &(SCARG(&sa, tv)->tv_sec), sizeof(long))) != 0)
885 SCARG(&sa, tv)->tv_usec = 0;
886 if ((error = settimeofday(p, &sa)) != 0)
894 struct ibcs2_utime_args *uap;
897 struct utimes_args sa;
899 caddr_t sg = stackgap_init();
901 CHECKALTEXIST(p, &sg, SCARG(uap, path));
902 SCARG(&sa, path) = SCARG(uap, path);
903 if (SCARG(uap, buf)) {
904 struct ibcs2_utimbuf ubuf;
906 if ((error = copyin((caddr_t)SCARG(uap, buf), (caddr_t)&ubuf,
909 SCARG(&sa, tptr) = stackgap_alloc(&sg,
910 2 * sizeof(struct timeval *));
911 tp = (struct timeval *)SCARG(&sa, tptr);
912 tp->tv_sec = ubuf.actime;
915 tp->tv_sec = ubuf.modtime;
918 SCARG(&sa, tptr) = NULL;
919 return utimes(p, &sa);
925 struct ibcs2_nice_args *uap;
928 struct setpriority_args sa;
930 SCARG(&sa, which) = PRIO_PROCESS;
932 SCARG(&sa, prio) = p->p_nice + SCARG(uap, incr);
933 if ((error = setpriority(p, &sa)) != 0)
935 p->p_retval[0] = p->p_nice;
940 * iBCS2 getpgrp, setpgrp, setsid, and setpgid
944 ibcs2_pgrpsys(p, uap)
946 struct ibcs2_pgrpsys_args *uap;
948 switch (SCARG(uap, type)) {
949 case 0: /* getpgrp */
950 p->p_retval[0] = p->p_pgrp->pg_id;
953 case 1: /* setpgrp */
955 struct setpgid_args sa;
958 SCARG(&sa, pgid) = 0;
960 p->p_retval[0] = p->p_pgrp->pg_id;
964 case 2: /* setpgid */
966 struct setpgid_args sa;
968 SCARG(&sa, pid) = SCARG(uap, pid);
969 SCARG(&sa, pgid) = SCARG(uap, pgid);
970 return setpgid(p, &sa);
974 return setsid(p, NULL);
982 * XXX - need to check for nested calls
988 struct ibcs2_plock_args *uap;
991 #define IBCS2_UNLOCK 0
992 #define IBCS2_PROCLOCK 1
993 #define IBCS2_TEXTLOCK 2
994 #define IBCS2_DATALOCK 4
997 if ((error = suser(p)) != 0)
999 switch(SCARG(uap, cmd)) {
1001 case IBCS2_PROCLOCK:
1002 case IBCS2_TEXTLOCK:
1003 case IBCS2_DATALOCK:
1004 return 0; /* XXX - TODO */
1010 ibcs2_uadmin(p, uap)
1012 struct ibcs2_uadmin_args *uap;
1014 #define SCO_A_REBOOT 1
1015 #define SCO_A_SHUTDOWN 2
1016 #define SCO_A_REMOUNT 4
1017 #define SCO_A_CLOCK 8
1018 #define SCO_A_SETCONFIG 128
1019 #define SCO_A_GETDEV 130
1021 #define SCO_AD_HALT 0
1022 #define SCO_AD_BOOT 1
1023 #define SCO_AD_IBOOT 2
1024 #define SCO_AD_PWRDOWN 3
1025 #define SCO_AD_PWRNAP 4
1027 #define SCO_AD_PANICBOOT 1
1029 #define SCO_AD_GETBMAJ 0
1030 #define SCO_AD_GETCMAJ 1
1035 switch(SCARG(uap, cmd)) {
1037 case SCO_A_SHUTDOWN:
1038 switch(SCARG(uap, func)) {
1039 struct reboot_args r;
1041 case SCO_AD_PWRDOWN:
1047 r.opt = RB_AUTOBOOT;
1053 case SCO_A_SETCONFIG:
1056 return EINVAL; /* XXX - TODO */
1064 struct ibcs2_sysfs_args *uap;
1066 #define IBCS2_GETFSIND 1
1067 #define IBCS2_GETFSTYP 2
1068 #define IBCS2_GETNFSTYP 3
1070 switch(SCARG(uap, cmd)) {
1071 case IBCS2_GETFSIND:
1072 case IBCS2_GETFSTYP:
1073 case IBCS2_GETNFSTYP:
1076 return EINVAL; /* XXX - TODO */
1080 ibcs2_unlink(p, uap)
1082 struct ibcs2_unlink_args *uap;
1084 caddr_t sg = stackgap_init();
1086 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1087 return unlink(p, (struct unlink_args *)uap);
1093 struct ibcs2_chdir_args *uap;
1095 caddr_t sg = stackgap_init();
1097 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1098 return chdir(p, (struct chdir_args *)uap);
1104 struct ibcs2_chmod_args *uap;
1106 caddr_t sg = stackgap_init();
1108 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1109 return chmod(p, (struct chmod_args *)uap);
1115 struct ibcs2_chown_args *uap;
1117 caddr_t sg = stackgap_init();
1119 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1120 return chown(p, (struct chown_args *)uap);
1126 struct ibcs2_rmdir_args *uap;
1128 caddr_t sg = stackgap_init();
1130 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1131 return rmdir(p, (struct rmdir_args *)uap);
1137 struct ibcs2_mkdir_args *uap;
1139 caddr_t sg = stackgap_init();
1141 CHECKALTCREAT(p, &sg, SCARG(uap, path));
1142 return mkdir(p, (struct mkdir_args *)uap);
1146 ibcs2_symlink(p, uap)
1148 struct ibcs2_symlink_args *uap;
1150 caddr_t sg = stackgap_init();
1152 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1153 CHECKALTCREAT(p, &sg, SCARG(uap, link));
1154 return symlink(p, (struct symlink_args *)uap);
1158 ibcs2_rename(p, uap)
1160 struct ibcs2_rename_args *uap;
1162 caddr_t sg = stackgap_init();
1164 CHECKALTEXIST(p, &sg, SCARG(uap, from));
1165 CHECKALTCREAT(p, &sg, SCARG(uap, to));
1166 return rename(p, (struct rename_args *)uap);
1170 ibcs2_readlink(p, uap)
1172 struct ibcs2_readlink_args *uap;
1174 caddr_t sg = stackgap_init();
1176 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1177 return readlink(p, (struct readlink_args *) uap);