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 $
52 * IBCS2 compatibility module.
54 * IBCS2 system calls that are implemented differently in BSD are
57 #include <sys/param.h>
58 #include <sys/dirent.h>
59 #include <sys/fcntl.h>
61 #include <sys/filedesc.h>
62 #include <sys/kernel.h>
64 #include <sys/malloc.h>
65 #include <sys/reboot.h>
66 #include <sys/resourcevar.h>
68 #include <sys/sysctl.h>
69 #include <sys/sysproto.h>
70 #include <sys/systm.h>
72 #include <sys/times.h>
73 #include <sys/vnode.h>
76 #include <machine/cpu.h>
78 #include <i386/ibcs2/ibcs2_dirent.h>
79 #include <i386/ibcs2/ibcs2_signal.h>
80 #include <i386/ibcs2/ibcs2_proto.h>
81 #include <i386/ibcs2/ibcs2_unistd.h>
82 #include <i386/ibcs2/ibcs2_util.h>
83 #include <i386/ibcs2/ibcs2_utime.h>
84 #include <i386/ibcs2/ibcs2_xenix.h>
89 struct ibcs2_ulimit_args *uap;
94 struct setrlimit_args {
99 #define IBCS2_GETFSIZE 1
100 #define IBCS2_SETFSIZE 2
101 #define IBCS2_GETPSIZE 3
102 #define IBCS2_GETDTABLESIZE 4
104 switch (SCARG(uap, cmd)) {
106 p->p_retval[0] = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
107 if (p->p_retval[0] == -1) p->p_retval[0] = 0x7fffffff;
109 case IBCS2_SETFSIZE: /* XXX - fix this */
111 rl.rlim_cur = SCARG(uap, newlimit);
112 sra.resource = RLIMIT_FSIZE;
114 error = setrlimit(p, &sra);
116 p->p_retval[0] = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
118 DPRINTF(("failed "));
121 p->p_retval[0] = SCARG(uap, newlimit);
125 p->p_retval[0] = p->p_rlimit[RLIMIT_RSS].rlim_cur; /* XXX */
127 case IBCS2_GETDTABLESIZE:
128 uap->cmd = IBCS2_SC_OPEN_MAX;
129 return ibcs2_sysconf(p, (struct ibcs2_sysconf_args *)uap);
135 #define IBCS2_WSTOPPED 0177
136 #define IBCS2_STOPCODE(sig) ((sig) << 8 | IBCS2_WSTOPPED)
140 struct ibcs2_wait_args *uap;
144 struct trapframe *tf = p->p_md.md_regs;
146 SCARG(&w4, rusage) = NULL;
147 if ((tf->tf_eflags & (PSL_Z|PSL_PF|PSL_N|PSL_V))
148 == (PSL_Z|PSL_PF|PSL_N|PSL_V)) {
150 SCARG(&w4, pid) = SCARG(uap, a1);
151 SCARG(&w4, status) = (int *)SCARG(uap, a2);
152 SCARG(&w4, options) = SCARG(uap, a3);
155 SCARG(&w4, pid) = WAIT_ANY;
156 SCARG(&w4, status) = (int *)SCARG(uap, a1);
157 SCARG(&w4, options) = 0;
159 if ((error = wait4(p, &w4)) != 0)
161 if (SCARG(&w4, status)) { /* this is real iBCS brain-damage */
162 error = copyin((caddr_t)SCARG(&w4, status), (caddr_t)&status,
163 sizeof(SCARG(&w4, status)));
167 /* convert status/signal result */
168 if(WIFSTOPPED(status))
170 IBCS2_STOPCODE(bsd_to_ibcs2_sig[_SIG_IDX(WSTOPSIG(status))]);
171 else if(WIFSIGNALED(status))
172 status = bsd_to_ibcs2_sig[_SIG_IDX(WTERMSIG(status))];
173 /* else exit status -- identical */
175 /* record result/status */
176 p->p_retval[1] = status;
177 return copyout((caddr_t)&status, (caddr_t)SCARG(&w4, status),
178 sizeof(SCARG(&w4, status)));
187 struct ibcs2_execv_args *uap;
189 struct execve_args ea;
190 caddr_t sg = stackgap_init();
192 CHECKALTEXIST(p, &sg, SCARG(uap, path));
193 SCARG(&ea, fname) = SCARG(uap, path);
194 SCARG(&ea, argv) = SCARG(uap, argp);
195 SCARG(&ea, envv) = NULL;
196 return execve(p, &ea);
202 struct ibcs2_execve_args *uap;
204 caddr_t sg = stackgap_init();
205 CHECKALTEXIST(p, &sg, SCARG(uap, path));
206 return execve(p, (struct execve_args *)uap);
212 struct ibcs2_umount_args *uap;
214 struct unmount_args um;
216 SCARG(&um, path) = SCARG(uap, name);
217 SCARG(&um, flags) = 0;
218 return unmount(p, &um);
224 struct ibcs2_mount_args *uap;
227 int oflags = SCARG(uap, flags), nflags, error;
228 char fsname[MFSNAMELEN];
230 if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5))
232 if ((oflags & IBCS2_MS_NEWTYPE) == 0)
235 if (oflags & IBCS2_MS_RDONLY)
236 nflags |= MNT_RDONLY;
237 if (oflags & IBCS2_MS_NOSUID)
238 nflags |= MNT_NOSUID;
239 if (oflags & IBCS2_MS_REMOUNT)
240 nflags |= MNT_UPDATE;
241 SCARG(uap, flags) = nflags;
243 if (error = copyinstr((caddr_t)SCARG(uap, type), fsname, sizeof fsname,
247 if (strcmp(fsname, "4.2") == 0) {
248 SCARG(uap, type) = (caddr_t)STACK_ALLOC();
249 if (error = copyout("ufs", SCARG(uap, type), sizeof("ufs")))
251 } else if (strcmp(fsname, "nfs") == 0) {
252 struct ibcs2_nfs_args sna;
253 struct sockaddr_in sain;
257 if (error = copyin(SCARG(uap, data), &sna, sizeof sna))
259 if (error = copyin(sna.addr, &sain, sizeof sain))
261 bcopy(&sain, &sa, sizeof sa);
262 sa.sa_len = sizeof(sain);
263 SCARG(uap, data) = (caddr_t)STACK_ALLOC();
264 na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na);
265 na.sotype = SOCK_DGRAM;
266 na.proto = IPPROTO_UDP;
267 na.fh = (nfsv2fh_t *)sna.fh;
268 na.flags = sna.flags;
269 na.wsize = sna.wsize;
270 na.rsize = sna.rsize;
271 na.timeo = sna.timeo;
272 na.retrans = sna.retrans;
273 na.hostname = sna.hostname;
275 if (error = copyout(&sa, na.addr, sizeof sa))
277 if (error = copyout(&na, SCARG(uap, data), sizeof na))
280 return (mount(p, uap));
287 * Read iBCS2-style directory entries. We suck them into kernel space so
288 * that they can be massaged before being copied out to user code. Like
289 * SunOS, we squish out `empty' entries.
291 * This is quite ugly, but what do you expect from compatibility code?
295 ibcs2_getdents(p, uap)
297 register struct ibcs2_getdents_args *uap;
299 register struct vnode *vp;
300 register caddr_t inp, buf; /* BSD-format */
301 register int len, reclen; /* BSD-format */
302 register caddr_t outp; /* iBCS2-format */
303 register int resid; /* iBCS2-format */
307 struct ibcs2_dirent idb;
308 off_t off; /* true file offset */
309 int buflen, error, eofflag;
310 u_long *cookies = NULL, *cookiep;
312 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
313 #define IBCS2_RECLEN(reclen) (reclen + sizeof(u_short))
315 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
317 if ((fp->f_flag & FREAD) == 0)
319 vp = (struct vnode *)fp->f_data;
320 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
324 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
325 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
326 buflen = min(buflen, MAXBSIZE);
327 buf = malloc(buflen, M_TEMP, M_WAITOK);
328 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
331 aiov.iov_len = buflen;
332 auio.uio_iov = &aiov;
334 auio.uio_rw = UIO_READ;
335 auio.uio_segflg = UIO_SYSSPACE;
337 auio.uio_resid = buflen;
338 auio.uio_offset = off;
341 free(cookies, M_TEMP);
346 * First we read into the malloc'ed buffer, then
347 * we massage it into user space, one record at a time.
349 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0)
352 outp = SCARG(uap, buf);
353 resid = SCARG(uap, nbytes);
354 if ((len = buflen - auio.uio_resid) <= 0)
361 * When using cookies, the vfs has the option of reading from
362 * a different offset than that supplied (UFS truncates the
363 * offset to a block boundary to make sure that it never reads
364 * partway through a directory entry, even if the directory
365 * has been compacted).
367 while (len > 0 && ncookies > 0 && *cookiep <= off) {
368 len -= BSD_DIRENT(inp)->d_reclen;
369 inp += BSD_DIRENT(inp)->d_reclen;
375 for (; len > 0; len -= reclen) {
376 if (cookiep && ncookies == 0)
378 reclen = BSD_DIRENT(inp)->d_reclen;
380 printf("ibcs2_getdents: reclen=%d\n", reclen);
384 if (BSD_DIRENT(inp)->d_fileno == 0) {
385 inp += reclen; /* it is a hole; squish it out */
393 if (reclen > len || resid < IBCS2_RECLEN(reclen)) {
394 /* entry too big for buffer, so just stop */
399 * Massage in place to make a iBCS2-shaped dirent (otherwise
400 * we have to worry about touching user memory outside of
401 * the copyout() call).
403 idb.d_ino = (ibcs2_ino_t)BSD_DIRENT(inp)->d_fileno;
404 idb.d_off = (ibcs2_off_t)off;
405 idb.d_reclen = (u_short)IBCS2_RECLEN(reclen);
406 if ((error = copyout((caddr_t)&idb, outp, 10)) != 0 ||
407 (error = copyout(BSD_DIRENT(inp)->d_name, outp + 10,
408 BSD_DIRENT(inp)->d_namlen + 1)) != 0)
410 /* advance past this real entry */
417 /* advance output past iBCS2-shaped entry */
418 outp += IBCS2_RECLEN(reclen);
419 resid -= IBCS2_RECLEN(reclen);
421 /* if we squished out the whole block, try again */
422 if (outp == SCARG(uap, buf))
424 fp->f_offset = off; /* update the vnode offset */
426 p->p_retval[0] = SCARG(uap, nbytes) - resid;
429 free(cookies, M_TEMP);
430 VOP_UNLOCK(vp, 0, p);
438 struct ibcs2_read_args *uap;
440 register struct vnode *vp;
441 register caddr_t inp, buf; /* BSD-format */
442 register int len, reclen; /* BSD-format */
443 register caddr_t outp; /* iBCS2-format */
444 register int resid; /* iBCS2-format */
448 struct ibcs2_direct {
452 off_t off; /* true file offset */
453 int buflen, error, eofflag, size;
454 u_long *cookies = NULL, *cookiep;
457 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) {
459 return read(p, (struct read_args *)uap);
463 if ((fp->f_flag & FREAD) == 0)
465 vp = (struct vnode *)fp->f_data;
466 if (vp->v_type != VDIR)
467 return read(p, (struct read_args *)uap);
469 DPRINTF(("ibcs2_read: read directory\n"));
472 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
473 buflen = min(buflen, MAXBSIZE);
474 buf = malloc(buflen, M_TEMP, M_WAITOK);
475 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
478 aiov.iov_len = buflen;
479 auio.uio_iov = &aiov;
481 auio.uio_rw = UIO_READ;
482 auio.uio_segflg = UIO_SYSSPACE;
484 auio.uio_resid = buflen;
485 auio.uio_offset = off;
488 free(cookies, M_TEMP);
493 * First we read into the malloc'ed buffer, then
494 * we massage it into user space, one record at a time.
496 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0) {
497 DPRINTF(("VOP_READDIR failed: %d\n", error));
501 outp = SCARG(uap, buf);
502 resid = SCARG(uap, nbytes);
503 if ((len = buflen - auio.uio_resid) <= 0)
510 * When using cookies, the vfs has the option of reading from
511 * a different offset than that supplied (UFS truncates the
512 * offset to a block boundary to make sure that it never reads
513 * partway through a directory entry, even if the directory
514 * has been compacted).
516 while (len > 0 && ncookies > 0 && *cookiep <= off) {
517 len -= BSD_DIRENT(inp)->d_reclen;
518 inp += BSD_DIRENT(inp)->d_reclen;
524 for (; len > 0 && resid > 0; len -= reclen) {
525 if (cookiep && ncookies == 0)
527 reclen = BSD_DIRENT(inp)->d_reclen;
529 printf("ibcs2_read: reclen=%d\n", reclen);
533 if (BSD_DIRENT(inp)->d_fileno == 0) {
534 inp += reclen; /* it is a hole; squish it out */
542 if (reclen > len || resid < sizeof(struct ibcs2_direct)) {
543 /* entry too big for buffer, so just stop */
548 * Massage in place to make a iBCS2-shaped dirent (otherwise
549 * we have to worry about touching user memory outside of
550 * the copyout() call).
552 * TODO: if length(filename) > 14, then break filename into
553 * multiple entries and set inode = 0xffff except last
555 idb.ino = (BSD_DIRENT(inp)->d_fileno > 0xfffe) ? 0xfffe :
556 BSD_DIRENT(inp)->d_fileno;
557 (void)copystr(BSD_DIRENT(inp)->d_name, idb.name, 14, &size);
558 bzero(idb.name + size, 14 - size);
559 if ((error = copyout(&idb, outp, sizeof(struct ibcs2_direct))) != 0)
561 /* advance past this real entry */
568 /* advance output past iBCS2-shaped entry */
569 outp += sizeof(struct ibcs2_direct);
570 resid -= sizeof(struct ibcs2_direct);
572 /* if we squished out the whole block, try again */
573 if (outp == SCARG(uap, buf))
575 fp->f_offset = off; /* update the vnode offset */
577 p->p_retval[0] = SCARG(uap, nbytes) - resid;
580 free(cookies, M_TEMP);
581 VOP_UNLOCK(vp, 0, p);
589 struct ibcs2_mknod_args *uap;
591 caddr_t sg = stackgap_init();
593 CHECKALTCREAT(p, &sg, SCARG(uap, path));
594 if (S_ISFIFO(SCARG(uap, mode))) {
595 struct mkfifo_args ap;
596 SCARG(&ap, path) = SCARG(uap, path);
597 SCARG(&ap, mode) = SCARG(uap, mode);
598 return mkfifo(p, &ap);
600 struct mknod_args ap;
601 SCARG(&ap, path) = SCARG(uap, path);
602 SCARG(&ap, mode) = SCARG(uap, mode);
603 SCARG(&ap, dev) = SCARG(uap, dev);
604 return mknod(p, &ap);
609 ibcs2_getgroups(p, uap)
611 struct ibcs2_getgroups_args *uap;
614 ibcs2_gid_t *iset = NULL;
615 struct getgroups_args sa;
617 caddr_t sg = stackgap_init();
619 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
620 if (SCARG(uap, gidsetsize)) {
621 SCARG(&sa, gidset) = stackgap_alloc(&sg, NGROUPS_MAX *
623 iset = stackgap_alloc(&sg, SCARG(uap, gidsetsize) *
624 sizeof(ibcs2_gid_t));
626 if ((error = getgroups(p, &sa)) != 0)
628 if (SCARG(uap, gidsetsize) == 0)
631 for (i = 0, gp = SCARG(&sa, gidset); i < p->p_retval[0]; i++)
632 iset[i] = (ibcs2_gid_t)*gp++;
633 if (p->p_retval[0] && (error = copyout((caddr_t)iset,
634 (caddr_t)SCARG(uap, gidset),
635 sizeof(ibcs2_gid_t) * p->p_retval[0])))
641 ibcs2_setgroups(p, uap)
643 struct ibcs2_setgroups_args *uap;
647 struct setgroups_args sa;
649 caddr_t sg = stackgap_init();
651 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
652 SCARG(&sa, gidset) = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
654 iset = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
655 sizeof(ibcs2_gid_t *));
656 if (SCARG(&sa, gidsetsize)) {
657 if ((error = copyin((caddr_t)SCARG(uap, gidset), (caddr_t)iset,
658 sizeof(ibcs2_gid_t *) *
659 SCARG(uap, gidsetsize))) != 0)
662 for (i = 0, gp = SCARG(&sa, gidset); i < SCARG(&sa, gidsetsize); i++)
663 *gp++ = (gid_t)iset[i];
664 return setgroups(p, &sa);
670 struct ibcs2_setuid_args *uap;
672 struct setuid_args sa;
674 SCARG(&sa, uid) = (uid_t)SCARG(uap, uid);
675 return setuid(p, &sa);
681 struct ibcs2_setgid_args *uap;
683 struct setgid_args sa;
685 SCARG(&sa, gid) = (gid_t)SCARG(uap, gid);
686 return setgid(p, &sa);
692 struct ibcs2_time_args *uap;
697 p->p_retval[0] = tv.tv_sec;
699 return copyout((caddr_t)&tv.tv_sec, (caddr_t)SCARG(uap, tp),
700 sizeof(ibcs2_time_t));
706 ibcs2_pathconf(p, uap)
708 struct ibcs2_pathconf_args *uap;
710 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
711 return pathconf(p, (struct pathconf_args *)uap);
715 ibcs2_fpathconf(p, uap)
717 struct ibcs2_fpathconf_args *uap;
719 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
720 return fpathconf(p, (struct fpathconf_args *)uap);
724 ibcs2_sysconf(p, uap)
726 struct ibcs2_sysconf_args *uap;
728 int mib[2], value, len, error;
729 struct sysctl_args sa;
730 struct __getrlimit_args ga;
732 switch(SCARG(uap, name)) {
733 case IBCS2_SC_ARG_MAX:
734 mib[1] = KERN_ARGMAX;
737 case IBCS2_SC_CHILD_MAX:
739 caddr_t sg = stackgap_init();
741 SCARG(&ga, which) = RLIMIT_NPROC;
742 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
743 if ((error = getrlimit(p, &ga)) != 0)
745 p->p_retval[0] = SCARG(&ga, rlp)->rlim_cur;
749 case IBCS2_SC_CLK_TCK:
753 case IBCS2_SC_NGROUPS_MAX:
754 mib[1] = KERN_NGROUPS;
757 case IBCS2_SC_OPEN_MAX:
759 caddr_t sg = stackgap_init();
761 SCARG(&ga, which) = RLIMIT_NOFILE;
762 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
763 if ((error = getrlimit(p, &ga)) != 0)
765 p->p_retval[0] = SCARG(&ga, rlp)->rlim_cur;
769 case IBCS2_SC_JOB_CONTROL:
770 mib[1] = KERN_JOB_CONTROL;
773 case IBCS2_SC_SAVED_IDS:
774 mib[1] = KERN_SAVED_IDS;
777 case IBCS2_SC_VERSION:
778 mib[1] = KERN_POSIX1;
781 case IBCS2_SC_PASS_MAX:
782 p->p_retval[0] = 128; /* XXX - should we create PASS_MAX ? */
785 case IBCS2_SC_XOPEN_VERSION:
786 p->p_retval[0] = 2; /* XXX: What should that be? */
795 SCARG(&sa, name) = mib;
796 SCARG(&sa, namelen) = 2;
797 SCARG(&sa, old) = &value;
798 SCARG(&sa, oldlenp) = &len;
799 SCARG(&sa, new) = NULL;
800 SCARG(&sa, newlen) = 0;
801 if ((error = __sysctl(p, &sa)) != 0)
803 p->p_retval[0] = value;
810 struct ibcs2_alarm_args *uap;
813 struct itimerval *itp, *oitp;
814 struct setitimer_args sa;
815 caddr_t sg = stackgap_init();
817 itp = stackgap_alloc(&sg, sizeof(*itp));
818 oitp = stackgap_alloc(&sg, sizeof(*oitp));
819 timevalclear(&itp->it_interval);
820 itp->it_value.tv_sec = SCARG(uap, sec);
821 itp->it_value.tv_usec = 0;
823 SCARG(&sa, which) = ITIMER_REAL;
824 SCARG(&sa, itv) = itp;
825 SCARG(&sa, oitv) = oitp;
826 error = setitimer(p, &sa);
829 if (oitp->it_value.tv_usec)
830 oitp->it_value.tv_sec++;
831 p->p_retval[0] = oitp->it_value.tv_sec;
838 struct ibcs2_times_args *uap;
841 struct getrusage_args ga;
844 caddr_t sg = stackgap_init();
845 struct rusage *ru = stackgap_alloc(&sg, sizeof(*ru));
846 #define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
848 SCARG(&ga, who) = RUSAGE_SELF;
849 SCARG(&ga, rusage) = ru;
850 error = getrusage(p, &ga);
853 tms.tms_utime = CONVTCK(ru->ru_utime);
854 tms.tms_stime = CONVTCK(ru->ru_stime);
856 SCARG(&ga, who) = RUSAGE_CHILDREN;
857 error = getrusage(p, &ga);
860 tms.tms_cutime = CONVTCK(ru->ru_utime);
861 tms.tms_cstime = CONVTCK(ru->ru_stime);
864 p->p_retval[0] = CONVTCK(t);
866 return copyout((caddr_t)&tms, (caddr_t)SCARG(uap, tp),
873 struct ibcs2_stime_args *uap;
876 struct settimeofday_args sa;
877 caddr_t sg = stackgap_init();
879 SCARG(&sa, tv) = stackgap_alloc(&sg, sizeof(*SCARG(&sa, tv)));
880 SCARG(&sa, tzp) = NULL;
881 if ((error = copyin((caddr_t)SCARG(uap, timep),
882 &(SCARG(&sa, tv)->tv_sec), sizeof(long))) != 0)
884 SCARG(&sa, tv)->tv_usec = 0;
885 if ((error = settimeofday(p, &sa)) != 0)
893 struct ibcs2_utime_args *uap;
896 struct utimes_args sa;
898 caddr_t sg = stackgap_init();
900 CHECKALTEXIST(p, &sg, SCARG(uap, path));
901 SCARG(&sa, path) = SCARG(uap, path);
902 if (SCARG(uap, buf)) {
903 struct ibcs2_utimbuf ubuf;
905 if ((error = copyin((caddr_t)SCARG(uap, buf), (caddr_t)&ubuf,
908 SCARG(&sa, tptr) = stackgap_alloc(&sg,
909 2 * sizeof(struct timeval *));
910 tp = (struct timeval *)SCARG(&sa, tptr);
911 tp->tv_sec = ubuf.actime;
914 tp->tv_sec = ubuf.modtime;
917 SCARG(&sa, tptr) = NULL;
918 return utimes(p, &sa);
924 struct ibcs2_nice_args *uap;
927 struct setpriority_args sa;
929 SCARG(&sa, which) = PRIO_PROCESS;
931 SCARG(&sa, prio) = p->p_nice + SCARG(uap, incr);
932 if ((error = setpriority(p, &sa)) != 0)
934 p->p_retval[0] = p->p_nice;
939 * iBCS2 getpgrp, setpgrp, setsid, and setpgid
943 ibcs2_pgrpsys(p, uap)
945 struct ibcs2_pgrpsys_args *uap;
947 switch (SCARG(uap, type)) {
948 case 0: /* getpgrp */
949 p->p_retval[0] = p->p_pgrp->pg_id;
952 case 1: /* setpgrp */
954 struct setpgid_args sa;
957 SCARG(&sa, pgid) = 0;
959 p->p_retval[0] = p->p_pgrp->pg_id;
963 case 2: /* setpgid */
965 struct setpgid_args sa;
967 SCARG(&sa, pid) = SCARG(uap, pid);
968 SCARG(&sa, pgid) = SCARG(uap, pgid);
969 return setpgid(p, &sa);
973 return setsid(p, NULL);
981 * XXX - need to check for nested calls
987 struct ibcs2_plock_args *uap;
990 #define IBCS2_UNLOCK 0
991 #define IBCS2_PROCLOCK 1
992 #define IBCS2_TEXTLOCK 2
993 #define IBCS2_DATALOCK 4
996 if ((error = suser(p)) != 0)
998 switch(SCARG(uap, cmd)) {
1000 case IBCS2_PROCLOCK:
1001 case IBCS2_TEXTLOCK:
1002 case IBCS2_DATALOCK:
1003 return 0; /* XXX - TODO */
1009 ibcs2_uadmin(p, uap)
1011 struct ibcs2_uadmin_args *uap;
1013 #define SCO_A_REBOOT 1
1014 #define SCO_A_SHUTDOWN 2
1015 #define SCO_A_REMOUNT 4
1016 #define SCO_A_CLOCK 8
1017 #define SCO_A_SETCONFIG 128
1018 #define SCO_A_GETDEV 130
1020 #define SCO_AD_HALT 0
1021 #define SCO_AD_BOOT 1
1022 #define SCO_AD_IBOOT 2
1023 #define SCO_AD_PWRDOWN 3
1024 #define SCO_AD_PWRNAP 4
1026 #define SCO_AD_PANICBOOT 1
1028 #define SCO_AD_GETBMAJ 0
1029 #define SCO_AD_GETCMAJ 1
1034 switch(SCARG(uap, cmd)) {
1036 case SCO_A_SHUTDOWN:
1037 switch(SCARG(uap, func)) {
1038 struct reboot_args r;
1040 case SCO_AD_PWRDOWN:
1046 r.opt = RB_AUTOBOOT;
1052 case SCO_A_SETCONFIG:
1055 return EINVAL; /* XXX - TODO */
1063 struct ibcs2_sysfs_args *uap;
1065 #define IBCS2_GETFSIND 1
1066 #define IBCS2_GETFSTYP 2
1067 #define IBCS2_GETNFSTYP 3
1069 switch(SCARG(uap, cmd)) {
1070 case IBCS2_GETFSIND:
1071 case IBCS2_GETFSTYP:
1072 case IBCS2_GETNFSTYP:
1075 return EINVAL; /* XXX - TODO */
1079 ibcs2_unlink(p, uap)
1081 struct ibcs2_unlink_args *uap;
1083 caddr_t sg = stackgap_init();
1085 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1086 return unlink(p, (struct unlink_args *)uap);
1092 struct ibcs2_chdir_args *uap;
1094 caddr_t sg = stackgap_init();
1096 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1097 return chdir(p, (struct chdir_args *)uap);
1103 struct ibcs2_chmod_args *uap;
1105 caddr_t sg = stackgap_init();
1107 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1108 return chmod(p, (struct chmod_args *)uap);
1114 struct ibcs2_chown_args *uap;
1116 caddr_t sg = stackgap_init();
1118 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1119 return chown(p, (struct chown_args *)uap);
1125 struct ibcs2_rmdir_args *uap;
1127 caddr_t sg = stackgap_init();
1129 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1130 return rmdir(p, (struct rmdir_args *)uap);
1136 struct ibcs2_mkdir_args *uap;
1138 caddr_t sg = stackgap_init();
1140 CHECKALTCREAT(p, &sg, SCARG(uap, path));
1141 return mkdir(p, (struct mkdir_args *)uap);
1145 ibcs2_symlink(p, uap)
1147 struct ibcs2_symlink_args *uap;
1149 caddr_t sg = stackgap_init();
1151 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1152 CHECKALTCREAT(p, &sg, SCARG(uap, link));
1153 return symlink(p, (struct symlink_args *)uap);
1157 ibcs2_rename(p, uap)
1159 struct ibcs2_rename_args *uap;
1161 caddr_t sg = stackgap_init();
1163 CHECKALTEXIST(p, &sg, SCARG(uap, from));
1164 CHECKALTCREAT(p, &sg, SCARG(uap, to));
1165 return rename(p, (struct rename_args *)uap);
1169 ibcs2_readlink(p, uap)
1171 struct ibcs2_readlink_args *uap;
1173 caddr_t sg = stackgap_init();
1175 CHECKALTEXIST(p, &sg, SCARG(uap, path));
1176 return readlink(p, (struct readlink_args *) uap);