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
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD$");
53 * IBCS2 compatibility module.
55 * IBCS2 system calls that are implemented differently in BSD are
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/capsicum.h>
61 #include <sys/dirent.h>
62 #include <sys/fcntl.h>
63 #include <sys/filedesc.h>
64 #include <sys/imgact.h>
65 #include <sys/kernel.h>
67 #include <sys/malloc.h>
68 #include <sys/file.h> /* Must come after sys/malloc.h */
69 #include <sys/mutex.h>
70 #include <sys/namei.h>
72 #include <sys/reboot.h>
73 #include <sys/resourcevar.h>
75 #include <sys/sysctl.h>
76 #include <sys/syscallsubr.h>
77 #include <sys/sysproto.h>
79 #include <sys/times.h>
80 #include <sys/vnode.h>
83 #include <machine/cpu.h>
85 #include <i386/ibcs2/ibcs2_dirent.h>
86 #include <i386/ibcs2/ibcs2_signal.h>
87 #include <i386/ibcs2/ibcs2_proto.h>
88 #include <i386/ibcs2/ibcs2_unistd.h>
89 #include <i386/ibcs2/ibcs2_util.h>
90 #include <i386/ibcs2/ibcs2_utime.h>
91 #include <i386/ibcs2/ibcs2_xenix.h>
93 #include <security/mac/mac_framework.h>
96 ibcs2_ulimit(struct thread *td, struct ibcs2_ulimit_args *uap)
100 #define IBCS2_GETFSIZE 1
101 #define IBCS2_SETFSIZE 2
102 #define IBCS2_GETPSIZE 3
103 #define IBCS2_GETDTABLESIZE 4
107 td->td_retval[0] = lim_cur(td, RLIMIT_FSIZE);
108 if (td->td_retval[0] == -1)
109 td->td_retval[0] = 0x7fffffff;
112 rl.rlim_max = lim_max(td, RLIMIT_FSIZE);
113 rl.rlim_cur = uap->newlimit;
114 error = kern_setrlimit(td, RLIMIT_FSIZE, &rl);
116 td->td_retval[0] = lim_cur(td, RLIMIT_FSIZE);
118 DPRINTF(("failed "));
122 td->td_retval[0] = lim_cur(td, RLIMIT_RSS); /* XXX */
124 case IBCS2_GETDTABLESIZE:
125 uap->cmd = IBCS2_SC_OPEN_MAX;
126 return ibcs2_sysconf(td, (struct ibcs2_sysconf_args *)uap);
132 #define IBCS2_WSTOPPED 0177
133 #define IBCS2_STOPCODE(sig) ((sig) << 8 | IBCS2_WSTOPPED)
135 ibcs2_wait(struct thread *td, struct ibcs2_wait_args *uap)
137 int error, options, status;
140 struct trapframe *tf = td->td_frame;
142 if ((tf->tf_eflags & (PSL_Z|PSL_PF|PSL_N|PSL_V))
143 == (PSL_Z|PSL_PF|PSL_N|PSL_V)) {
146 statusp = (int *)uap->a2;
151 statusp = (int *)uap->a1;
154 error = kern_wait(td, pid, &status, options, NULL);
159 * Convert status/signal result.
161 if (WIFSTOPPED(status)) {
162 if (WSTOPSIG(status) <= 0 ||
163 WSTOPSIG(status) > IBCS2_SIGTBLSZ)
166 IBCS2_STOPCODE(bsd_to_ibcs2_sig[_SIG_IDX(WSTOPSIG(status))]);
167 } else if (WIFSIGNALED(status)) {
168 if (WTERMSIG(status) <= 0 ||
169 WTERMSIG(status) > IBCS2_SIGTBLSZ)
171 status = bsd_to_ibcs2_sig[_SIG_IDX(WTERMSIG(status))];
173 /* else exit status -- identical */
175 /* record result/status */
176 td->td_retval[1] = status;
177 return copyout(&status, statusp, sizeof(status));
184 ibcs2_execv(struct thread *td, struct ibcs2_execv_args *uap)
186 struct image_args eargs;
187 struct vmspace *oldvmspace;
191 CHECKALTEXIST(td, uap->path, &path);
193 error = pre_execve(td, &oldvmspace);
198 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
201 error = kern_execve(td, &eargs, NULL);
202 post_execve(td, error, oldvmspace);
207 ibcs2_execve(struct thread *td, struct ibcs2_execve_args *uap)
209 struct image_args eargs;
210 struct vmspace *oldvmspace;
214 CHECKALTEXIST(td, uap->path, &path);
216 error = pre_execve(td, &oldvmspace);
221 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
225 error = kern_execve(td, &eargs, NULL);
226 post_execve(td, error, oldvmspace);
231 ibcs2_umount(struct thread *td, struct ibcs2_umount_args *uap)
233 struct unmount_args um;
237 return sys_unmount(td, &um);
241 ibcs2_mount(struct thread *td, struct ibcs2_mount_args *uap)
244 int oflags = uap->flags, nflags, error;
245 char fsname[MFSNAMELEN];
247 if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5))
249 if ((oflags & IBCS2_MS_NEWTYPE) == 0)
252 if (oflags & IBCS2_MS_RDONLY)
253 nflags |= MNT_RDONLY;
254 if (oflags & IBCS2_MS_NOSUID)
255 nflags |= MNT_NOSUID;
256 if (oflags & IBCS2_MS_REMOUNT)
257 nflags |= MNT_UPDATE;
260 if (error = copyinstr((caddr_t)uap->type, fsname, sizeof fsname,
264 if (strcmp(fsname, "4.2") == 0) {
265 uap->type = (caddr_t)STACK_ALLOC();
266 if (error = copyout("ufs", uap->type, sizeof("ufs")))
268 } else if (strcmp(fsname, "nfs") == 0) {
269 struct ibcs2_nfs_args sna;
270 struct sockaddr_in sain;
274 if (error = copyin(uap->data, &sna, sizeof sna))
276 if (error = copyin(sna.addr, &sain, sizeof sain))
278 bcopy(&sain, &sa, sizeof sa);
279 sa.sa_len = sizeof(sain);
280 uap->data = (caddr_t)STACK_ALLOC();
281 na.addr = (struct sockaddr *)((int)uap->data + sizeof na);
282 na.sotype = SOCK_DGRAM;
283 na.proto = IPPROTO_UDP;
284 na.fh = (nfsv2fh_t *)sna.fh;
285 na.flags = sna.flags;
286 na.wsize = sna.wsize;
287 na.rsize = sna.rsize;
288 na.timeo = sna.timeo;
289 na.retrans = sna.retrans;
290 na.hostname = sna.hostname;
292 if (error = copyout(&sa, na.addr, sizeof sa))
294 if (error = copyout(&na, uap->data, sizeof na))
297 return (mount(td, uap));
304 * Read iBCS2-style directory entries. We suck them into kernel space so
305 * that they can be massaged before being copied out to user code. Like
306 * SunOS, we squish out `empty' entries.
308 * This is quite ugly, but what do you expect from compatibility code?
312 ibcs2_getdents(struct thread *td, struct ibcs2_getdents_args *uap)
315 caddr_t inp, buf; /* BSD-format */
316 int len, reclen; /* BSD-format */
317 caddr_t outp; /* iBCS2-format */
318 int resid; /* iBCS2-format */
323 struct ibcs2_dirent idb;
324 off_t off; /* true file offset */
325 int buflen, error, eofflag;
326 u_long *cookies = NULL, *cookiep;
328 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
329 #define IBCS2_RECLEN(reclen) (reclen + sizeof(u_short))
331 memset(&idb, 0, sizeof(idb));
332 error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
335 if ((fp->f_flag & FREAD) == 0) {
340 if (vp->v_type != VDIR) { /* XXX vnode readdir op should do this */
346 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
347 buflen = max(DIRBLKSIZ, uap->nbytes);
348 buflen = min(buflen, MAXBSIZE);
349 buf = malloc(buflen, M_TEMP, M_WAITOK);
350 vn_lock(vp, LK_SHARED | LK_RETRY);
353 aiov.iov_len = buflen;
354 auio.uio_iov = &aiov;
356 auio.uio_rw = UIO_READ;
357 auio.uio_segflg = UIO_SYSSPACE;
359 auio.uio_resid = buflen;
360 auio.uio_offset = off;
363 free(cookies, M_TEMP);
368 error = mac_vnode_check_readdir(td->td_ucred, vp);
374 * First we read into the malloc'ed buffer, then
375 * we massage it into user space, one record at a time.
377 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0)
382 if ((len = buflen - auio.uio_resid) <= 0)
389 * When using cookies, the vfs has the option of reading from
390 * a different offset than that supplied (UFS truncates the
391 * offset to a block boundary to make sure that it never reads
392 * partway through a directory entry, even if the directory
393 * has been compacted).
395 while (len > 0 && ncookies > 0 && *cookiep <= off) {
396 len -= BSD_DIRENT(inp)->d_reclen;
397 inp += BSD_DIRENT(inp)->d_reclen;
403 for (; len > 0; len -= reclen) {
404 if (cookiep && ncookies == 0)
406 reclen = BSD_DIRENT(inp)->d_reclen;
408 printf("ibcs2_getdents: reclen=%d\n", reclen);
412 if (BSD_DIRENT(inp)->d_fileno == 0) {
413 inp += reclen; /* it is a hole; squish it out */
421 if (reclen > len || resid < IBCS2_RECLEN(reclen)) {
422 /* entry too big for buffer, so just stop */
427 * Massage in place to make an iBCS2-shaped dirent (otherwise
428 * we have to worry about touching user memory outside of
429 * the copyout() call).
431 idb.d_ino = (ibcs2_ino_t)BSD_DIRENT(inp)->d_fileno;
432 idb.d_off = (ibcs2_off_t)off;
433 idb.d_reclen = (u_short)IBCS2_RECLEN(reclen);
434 if ((error = copyout((caddr_t)&idb, outp, 10)) != 0 ||
435 (error = copyout(BSD_DIRENT(inp)->d_name, outp + 10,
436 BSD_DIRENT(inp)->d_namlen + 1)) != 0)
438 /* advance past this real entry */
445 /* advance output past iBCS2-shaped entry */
446 outp += IBCS2_RECLEN(reclen);
447 resid -= IBCS2_RECLEN(reclen);
449 /* if we squished out the whole block, try again */
450 if (outp == uap->buf)
452 fp->f_offset = off; /* update the vnode offset */
454 td->td_retval[0] = uap->nbytes - resid;
459 free(cookies, M_TEMP);
465 ibcs2_read(struct thread *td, struct ibcs2_read_args *uap)
468 caddr_t inp, buf; /* BSD-format */
469 int len, reclen; /* BSD-format */
470 caddr_t outp; /* iBCS2-format */
471 int resid; /* iBCS2-format */
476 struct ibcs2_direct {
480 off_t off; /* true file offset */
481 int buflen, error, eofflag, size;
482 u_long *cookies = NULL, *cookiep;
485 error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
488 return sys_read(td, (struct read_args *)uap);
492 if ((fp->f_flag & FREAD) == 0) {
497 if (vp->v_type != VDIR) {
499 return sys_read(td, (struct read_args *)uap);
504 DPRINTF(("ibcs2_read: read directory\n"));
506 buflen = max(DIRBLKSIZ, uap->nbytes);
507 buflen = min(buflen, MAXBSIZE);
508 buf = malloc(buflen, M_TEMP, M_WAITOK);
509 vn_lock(vp, LK_SHARED | LK_RETRY);
512 aiov.iov_len = buflen;
513 auio.uio_iov = &aiov;
515 auio.uio_rw = UIO_READ;
516 auio.uio_segflg = UIO_SYSSPACE;
518 auio.uio_resid = buflen;
519 auio.uio_offset = off;
522 free(cookies, M_TEMP);
527 error = mac_vnode_check_readdir(td->td_ucred, vp);
533 * First we read into the malloc'ed buffer, then
534 * we massage it into user space, one record at a time.
536 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0) {
537 DPRINTF(("VOP_READDIR failed: %d\n", error));
543 if ((len = buflen - auio.uio_resid) <= 0)
550 * When using cookies, the vfs has the option of reading from
551 * a different offset than that supplied (UFS truncates the
552 * offset to a block boundary to make sure that it never reads
553 * partway through a directory entry, even if the directory
554 * has been compacted).
556 while (len > 0 && ncookies > 0 && *cookiep <= off) {
557 len -= BSD_DIRENT(inp)->d_reclen;
558 inp += BSD_DIRENT(inp)->d_reclen;
564 for (; len > 0 && resid > 0; len -= reclen) {
565 if (cookiep && ncookies == 0)
567 reclen = BSD_DIRENT(inp)->d_reclen;
569 printf("ibcs2_read: reclen=%d\n", reclen);
573 if (BSD_DIRENT(inp)->d_fileno == 0) {
574 inp += reclen; /* it is a hole; squish it out */
582 if (reclen > len || resid < sizeof(struct ibcs2_direct)) {
583 /* entry too big for buffer, so just stop */
588 * Massage in place to make an iBCS2-shaped dirent (otherwise
589 * we have to worry about touching user memory outside of
590 * the copyout() call).
592 * TODO: if length(filename) > 14, then break filename into
593 * multiple entries and set inode = 0xffff except last
595 idb.ino = (BSD_DIRENT(inp)->d_fileno > 0xfffe) ? 0xfffe :
596 BSD_DIRENT(inp)->d_fileno;
597 (void)copystr(BSD_DIRENT(inp)->d_name, idb.name, 14, &size);
598 bzero(idb.name + size, 14 - size);
599 if ((error = copyout(&idb, outp, sizeof(struct ibcs2_direct))) != 0)
601 /* advance past this real entry */
608 /* advance output past iBCS2-shaped entry */
609 outp += sizeof(struct ibcs2_direct);
610 resid -= sizeof(struct ibcs2_direct);
612 /* if we squished out the whole block, try again */
613 if (outp == uap->buf)
615 fp->f_offset = off; /* update the vnode offset */
617 td->td_retval[0] = uap->nbytes - resid;
622 free(cookies, M_TEMP);
628 ibcs2_mknod(struct thread *td, struct ibcs2_mknod_args *uap)
633 CHECKALTCREAT(td, uap->path, &path);
634 if (S_ISFIFO(uap->mode)) {
635 error = kern_mkfifoat(td, AT_FDCWD, path,
636 UIO_SYSSPACE, uap->mode);
638 error = kern_mknodat(td, AT_FDCWD, path, UIO_SYSSPACE,
639 uap->mode, uap->dev);
646 ibcs2_getgroups(struct thread *td, struct ibcs2_getgroups_args *uap)
654 ngrp = cred->cr_ngroups;
656 if (uap->gidsetsize == 0) {
660 if (uap->gidsetsize < ngrp)
663 iset = malloc(ngrp * sizeof(*iset), M_TEMP, M_WAITOK);
664 for (i = 0; i < ngrp; i++)
665 iset[i] = (ibcs2_gid_t)cred->cr_groups[i];
666 error = copyout(iset, uap->gidset, ngrp * sizeof(ibcs2_gid_t));
669 td->td_retval[0] = ngrp;
674 ibcs2_setgroups(struct thread *td, struct ibcs2_setgroups_args *uap)
680 if (uap->gidsetsize < 0 || uap->gidsetsize > ngroups_max + 1)
682 if (uap->gidsetsize && uap->gidset == NULL)
684 gp = malloc(uap->gidsetsize * sizeof(*gp), M_TEMP, M_WAITOK);
685 if (uap->gidsetsize) {
686 iset = malloc(uap->gidsetsize * sizeof(*iset), M_TEMP, M_WAITOK);
687 error = copyin(uap->gidset, iset, sizeof(ibcs2_gid_t) *
693 for (i = 0; i < uap->gidsetsize; i++)
694 gp[i] = (gid_t)iset[i];
697 error = kern_setgroups(td, uap->gidsetsize, gp);
704 ibcs2_setuid(struct thread *td, struct ibcs2_setuid_args *uap)
706 struct setuid_args sa;
708 sa.uid = (uid_t)uap->uid;
709 return sys_setuid(td, &sa);
713 ibcs2_setgid(struct thread *td, struct ibcs2_setgid_args *uap)
715 struct setgid_args sa;
717 sa.gid = (gid_t)uap->gid;
718 return sys_setgid(td, &sa);
722 ibcs2_time(struct thread *td, struct ibcs2_time_args *uap)
727 td->td_retval[0] = tv.tv_sec;
729 return copyout((caddr_t)&tv.tv_sec, (caddr_t)uap->tp,
730 sizeof(ibcs2_time_t));
736 ibcs2_pathconf(struct thread *td, struct ibcs2_pathconf_args *uap)
741 CHECKALTEXIST(td, uap->path, &path);
742 uap->name++; /* iBCS2 _PC_* defines are offset by one */
743 error = kern_pathconf(td, path, UIO_SYSSPACE, uap->name, FOLLOW);
749 ibcs2_fpathconf(struct thread *td, struct ibcs2_fpathconf_args *uap)
751 uap->name++; /* iBCS2 _PC_* defines are offset by one */
752 return sys_fpathconf(td, (struct fpathconf_args *)uap);
756 ibcs2_sysconf(struct thread *td, struct ibcs2_sysconf_args *uap)
758 int mib[2], value, len, error;
761 case IBCS2_SC_ARG_MAX:
762 mib[1] = KERN_ARGMAX;
765 case IBCS2_SC_CHILD_MAX:
766 td->td_retval[0] = lim_cur(td, RLIMIT_NPROC);
769 case IBCS2_SC_CLK_TCK:
770 td->td_retval[0] = hz;
773 case IBCS2_SC_NGROUPS_MAX:
774 mib[1] = KERN_NGROUPS;
777 case IBCS2_SC_OPEN_MAX:
778 td->td_retval[0] = lim_cur(td, RLIMIT_NOFILE);
781 case IBCS2_SC_JOB_CONTROL:
782 mib[1] = KERN_JOB_CONTROL;
785 case IBCS2_SC_SAVED_IDS:
786 mib[1] = KERN_SAVED_IDS;
789 case IBCS2_SC_VERSION:
790 mib[1] = KERN_POSIX1;
793 case IBCS2_SC_PASS_MAX:
794 td->td_retval[0] = 128; /* XXX - should we create PASS_MAX ? */
797 case IBCS2_SC_XOPEN_VERSION:
798 td->td_retval[0] = 2; /* XXX: What should that be? */
807 error = kernel_sysctl(td, mib, 2, &value, &len, NULL, 0, NULL, 0);
810 td->td_retval[0] = value;
815 ibcs2_alarm(struct thread *td, struct ibcs2_alarm_args *uap)
817 struct itimerval itv, oitv;
820 timevalclear(&itv.it_interval);
821 itv.it_value.tv_sec = uap->sec;
822 itv.it_value.tv_usec = 0;
823 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
826 if (oitv.it_value.tv_usec != 0)
827 oitv.it_value.tv_sec++;
828 td->td_retval[0] = oitv.it_value.tv_sec;
833 ibcs2_times(struct thread *td, struct ibcs2_times_args *uap)
840 #define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
842 error = kern_getrusage(td, RUSAGE_SELF, &ru);
845 tms.tms_utime = CONVTCK(ru.ru_utime);
846 tms.tms_stime = CONVTCK(ru.ru_stime);
848 error = kern_getrusage(td, RUSAGE_CHILDREN, &ru);
851 tms.tms_cutime = CONVTCK(ru.ru_utime);
852 tms.tms_cstime = CONVTCK(ru.ru_stime);
855 td->td_retval[0] = CONVTCK(t);
857 return (copyout(&tms, uap->tp, sizeof(struct tms)));
861 ibcs2_stime(struct thread *td, struct ibcs2_stime_args *uap)
867 error = copyin(uap->timep, &secs, sizeof(long));
872 error = kern_settimeofday(td, &tv, NULL);
879 ibcs2_utime(struct thread *td, struct ibcs2_utime_args *uap)
881 struct ibcs2_utimbuf ubuf;
882 struct timeval tbuf[2], *tp;
887 error = copyin(uap->buf, &ubuf, sizeof(ubuf));
890 tbuf[0].tv_sec = ubuf.actime;
892 tbuf[1].tv_sec = ubuf.modtime;
898 CHECKALTEXIST(td, uap->path, &path);
899 error = kern_utimesat(td, AT_FDCWD, path, UIO_SYSSPACE,
906 ibcs2_nice(struct thread *td, struct ibcs2_nice_args *uap)
909 struct setpriority_args sa;
911 sa.which = PRIO_PROCESS;
913 sa.prio = td->td_proc->p_nice + uap->incr;
914 if ((error = sys_setpriority(td, &sa)) != 0)
916 td->td_retval[0] = td->td_proc->p_nice;
921 * iBCS2 getpgrp, setpgrp, setsid, and setpgid
925 ibcs2_pgrpsys(struct thread *td, struct ibcs2_pgrpsys_args *uap)
927 struct proc *p = td->td_proc;
929 case 0: /* getpgrp */
931 td->td_retval[0] = p->p_pgrp->pg_id;
935 case 1: /* setpgrp */
937 struct setpgid_args sa;
941 sys_setpgid(td, &sa);
943 td->td_retval[0] = p->p_pgrp->pg_id;
948 case 2: /* setpgid */
950 struct setpgid_args sa;
954 return sys_setpgid(td, &sa);
958 return sys_setsid(td, NULL);
966 * XXX - need to check for nested calls
970 ibcs2_plock(struct thread *td, struct ibcs2_plock_args *uap)
973 #define IBCS2_UNLOCK 0
974 #define IBCS2_PROCLOCK 1
975 #define IBCS2_TEXTLOCK 2
976 #define IBCS2_DATALOCK 4
981 error = priv_check(td, PRIV_VM_MUNLOCK);
990 error = priv_check(td, PRIV_VM_MLOCK);
1000 ibcs2_uadmin(struct thread *td, struct ibcs2_uadmin_args *uap)
1002 #define SCO_A_REBOOT 1
1003 #define SCO_A_SHUTDOWN 2
1004 #define SCO_A_REMOUNT 4
1005 #define SCO_A_CLOCK 8
1006 #define SCO_A_SETCONFIG 128
1007 #define SCO_A_GETDEV 130
1009 #define SCO_AD_HALT 0
1010 #define SCO_AD_BOOT 1
1011 #define SCO_AD_IBOOT 2
1012 #define SCO_AD_PWRDOWN 3
1013 #define SCO_AD_PWRNAP 4
1015 #define SCO_AD_PANICBOOT 1
1017 #define SCO_AD_GETBMAJ 0
1018 #define SCO_AD_GETCMAJ 1
1022 case SCO_A_SHUTDOWN:
1024 struct reboot_args r;
1026 case SCO_AD_PWRDOWN:
1029 return (sys_reboot(td, &r));
1032 r.opt = RB_AUTOBOOT;
1033 return (sys_reboot(td, &r));
1038 case SCO_A_SETCONFIG:
1041 return EINVAL; /* XXX - TODO */
1047 ibcs2_sysfs(struct thread *td, struct ibcs2_sysfs_args *uap)
1049 #define IBCS2_GETFSIND 1
1050 #define IBCS2_GETFSTYP 2
1051 #define IBCS2_GETNFSTYP 3
1054 case IBCS2_GETFSIND:
1055 case IBCS2_GETFSTYP:
1056 case IBCS2_GETNFSTYP:
1059 return EINVAL; /* XXX - TODO */
1063 ibcs2_unlink(struct thread *td, struct ibcs2_unlink_args *uap)
1068 CHECKALTEXIST(td, uap->path, &path);
1069 error = kern_unlinkat(td, AT_FDCWD, path, UIO_SYSSPACE, 0);
1075 ibcs2_chdir(struct thread *td, struct ibcs2_chdir_args *uap)
1080 CHECKALTEXIST(td, uap->path, &path);
1081 error = kern_chdir(td, path, UIO_SYSSPACE);
1087 ibcs2_chmod(struct thread *td, struct ibcs2_chmod_args *uap)
1092 CHECKALTEXIST(td, uap->path, &path);
1093 error = kern_fchmodat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->mode, 0);
1099 ibcs2_chown(struct thread *td, struct ibcs2_chown_args *uap)
1104 CHECKALTEXIST(td, uap->path, &path);
1105 error = kern_fchownat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->uid,
1112 ibcs2_rmdir(struct thread *td, struct ibcs2_rmdir_args *uap)
1117 CHECKALTEXIST(td, uap->path, &path);
1118 error = kern_rmdirat(td, AT_FDCWD, path, UIO_SYSSPACE);
1124 ibcs2_mkdir(struct thread *td, struct ibcs2_mkdir_args *uap)
1129 CHECKALTEXIST(td, uap->path, &path);
1130 error = kern_mkdirat(td, AT_FDCWD, path, UIO_SYSSPACE, uap->mode);
1136 ibcs2_symlink(struct thread *td, struct ibcs2_symlink_args *uap)
1141 CHECKALTEXIST(td, uap->path, &path);
1144 * Have to expand CHECKALTCREAT() so that 'path' can be freed on
1147 error = ibcs2_emul_find(td, uap->link, UIO_USERSPACE, &link, 1);
1152 error = kern_symlinkat(td, path, AT_FDCWD, link, UIO_SYSSPACE);
1159 ibcs2_rename(struct thread *td, struct ibcs2_rename_args *uap)
1164 CHECKALTEXIST(td, uap->from, &from);
1167 * Have to expand CHECKALTCREAT() so that 'from' can be freed on
1170 error = ibcs2_emul_find(td, uap->to, UIO_USERSPACE, &to, 1);
1175 error = kern_renameat(td, AT_FDCWD, from, AT_FDCWD, to, UIO_SYSSPACE);
1182 ibcs2_readlink(struct thread *td, struct ibcs2_readlink_args *uap)
1187 CHECKALTEXIST(td, uap->path, &path);
1188 error = kern_readlinkat(td, AT_FDCWD, path, UIO_SYSSPACE,
1189 uap->buf, UIO_USERSPACE, uap->count);