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.5 2003/07/26 18:12:43 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>
88 ibcs2_ulimit(struct ibcs2_ulimit_args *uap)
93 struct setrlimit_args {
98 struct proc *p = curproc;
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 uap->lmsg.u.ms_result = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
108 if (uap->lmsg.u.ms_result == -1)
109 uap->lmsg.u.ms_result = 0x7fffffff;
111 case IBCS2_SETFSIZE: /* XXX - fix this */
113 rl.rlim_cur = SCARG(uap, newlimit);
114 sra.resource = RLIMIT_FSIZE;
116 error = setrlimit(&sra);
118 uap->lmsg.u.ms_result = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
120 DPRINTF(("failed "));
123 uap->lmsg.u.ms_result = SCARG(uap, newlimit);
127 uap->lmsg.u.ms_result = p->p_rlimit[RLIMIT_RSS].rlim_cur; /* XXX */
129 case IBCS2_GETDTABLESIZE:
130 uap->cmd = IBCS2_SC_OPEN_MAX;
131 return ibcs2_sysconf((struct ibcs2_sysconf_args *)uap);
137 #define IBCS2_WSTOPPED 0177
138 #define IBCS2_STOPCODE(sig) ((sig) << 8 | IBCS2_WSTOPPED)
140 ibcs2_wait(struct ibcs2_wait_args *uap)
142 struct proc *p = curproc;
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(&w4)) != 0)
162 uap->lmsg.u.ms_fds[0] = w4.lmsg.u.ms_fds[0];
163 if (SCARG(&w4, status)) { /* this is real iBCS brain-damage */
164 error = copyin((caddr_t)SCARG(&w4, status), (caddr_t)&status,
165 sizeof(SCARG(&w4, status)));
169 /* convert status/signal result */
170 if(WIFSTOPPED(status))
172 IBCS2_STOPCODE(bsd_to_ibcs2_sig[_SIG_IDX(WSTOPSIG(status))]);
173 else if(WIFSIGNALED(status))
174 status = bsd_to_ibcs2_sig[_SIG_IDX(WTERMSIG(status))];
175 /* else exit status -- identical */
177 /* record result/status */
178 uap->lmsg.u.ms_fds[1] = status;
179 return copyout((caddr_t)&status, (caddr_t)SCARG(&w4, status),
180 sizeof(SCARG(&w4, status)));
187 ibcs2_execv(struct ibcs2_execv_args *uap)
189 struct execve_args ea;
190 caddr_t sg = stackgap_init();
193 CHECKALTEXIST(&sg, SCARG(uap, path));
194 SCARG(&ea, fname) = SCARG(uap, path);
195 SCARG(&ea, argv) = SCARG(uap, argp);
196 SCARG(&ea, envv) = NULL;
198 uap->lmsg.u.ms_result = ea.lmsg.u.ms_result;
203 ibcs2_execve(struct ibcs2_execve_args *uap)
205 caddr_t sg = stackgap_init();
206 CHECKALTEXIST(&sg, SCARG(uap, path));
207 return execve((struct execve_args *)uap);
211 ibcs2_umount(struct ibcs2_umount_args *uap)
213 struct unmount_args um;
216 SCARG(&um, path) = SCARG(uap, name);
217 SCARG(&um, flags) = 0;
218 error = unmount(&um);
219 uap->lmsg.u.ms_result = um.lmsg.u.ms_result;
224 ibcs2_mount(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))
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(struct ibcs2_getdents_args *uap)
297 struct thread *td = curthread;
298 struct proc *p = td->td_proc;
300 caddr_t inp, buf; /* BSD-format */
301 int len, reclen; /* BSD-format */
302 caddr_t outp; /* iBCS2-format */
303 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))
317 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
319 if ((fp->f_flag & FREAD) == 0)
321 vp = (struct vnode *)fp->f_data;
322 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
326 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
327 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
328 buflen = min(buflen, MAXBSIZE);
329 buf = malloc(buflen, M_TEMP, M_WAITOK);
330 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
333 aiov.iov_len = buflen;
334 auio.uio_iov = &aiov;
336 auio.uio_rw = UIO_READ;
337 auio.uio_segflg = UIO_SYSSPACE;
339 auio.uio_resid = buflen;
340 auio.uio_offset = off;
343 free(cookies, M_TEMP);
348 * First we read into the malloc'ed buffer, then
349 * we massage it into user space, one record at a time.
351 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0)
354 outp = SCARG(uap, buf);
355 resid = SCARG(uap, nbytes);
356 if ((len = buflen - auio.uio_resid) <= 0)
363 * When using cookies, the vfs has the option of reading from
364 * a different offset than that supplied (UFS truncates the
365 * offset to a block boundary to make sure that it never reads
366 * partway through a directory entry, even if the directory
367 * has been compacted).
369 while (len > 0 && ncookies > 0 && *cookiep <= off) {
370 len -= BSD_DIRENT(inp)->d_reclen;
371 inp += BSD_DIRENT(inp)->d_reclen;
377 for (; len > 0; len -= reclen) {
378 if (cookiep && ncookies == 0)
380 reclen = BSD_DIRENT(inp)->d_reclen;
382 printf("ibcs2_getdents: reclen=%d\n", reclen);
386 if (BSD_DIRENT(inp)->d_fileno == 0) {
387 inp += reclen; /* it is a hole; squish it out */
395 if (reclen > len || resid < IBCS2_RECLEN(reclen)) {
396 /* entry too big for buffer, so just stop */
401 * Massage in place to make a iBCS2-shaped dirent (otherwise
402 * we have to worry about touching user memory outside of
403 * the copyout() call).
405 idb.d_ino = (ibcs2_ino_t)BSD_DIRENT(inp)->d_fileno;
406 idb.d_off = (ibcs2_off_t)off;
407 idb.d_reclen = (u_short)IBCS2_RECLEN(reclen);
408 if ((error = copyout((caddr_t)&idb, outp, 10)) != 0 ||
409 (error = copyout(BSD_DIRENT(inp)->d_name, outp + 10,
410 BSD_DIRENT(inp)->d_namlen + 1)) != 0)
412 /* advance past this real entry */
419 /* advance output past iBCS2-shaped entry */
420 outp += IBCS2_RECLEN(reclen);
421 resid -= IBCS2_RECLEN(reclen);
423 /* if we squished out the whole block, try again */
424 if (outp == SCARG(uap, buf))
426 fp->f_offset = off; /* update the vnode offset */
428 uap->lmsg.u.ms_result = SCARG(uap, nbytes) - resid;
431 free(cookies, M_TEMP);
432 VOP_UNLOCK(vp, 0, td);
438 ibcs2_read(struct ibcs2_read_args *uap)
440 struct thread *td = curthread;
441 struct proc *p = td->td_proc;
443 caddr_t inp, buf; /* BSD-format */
444 int len, reclen; /* BSD-format */
445 caddr_t outp; /* iBCS2-format */
446 int resid; /* iBCS2-format */
450 struct ibcs2_direct {
454 off_t off; /* true file offset */
455 int buflen, error, eofflag, size;
456 u_long *cookies = NULL, *cookiep;
461 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0) {
463 return read((struct read_args *)uap);
467 if ((fp->f_flag & FREAD) == 0)
469 vp = (struct vnode *)fp->f_data;
470 if (vp->v_type != VDIR)
471 return read((struct read_args *)uap);
473 DPRINTF(("ibcs2_read: read directory\n"));
476 buflen = max(DIRBLKSIZ, SCARG(uap, nbytes));
477 buflen = min(buflen, MAXBSIZE);
478 buf = malloc(buflen, M_TEMP, M_WAITOK);
479 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
482 aiov.iov_len = buflen;
483 auio.uio_iov = &aiov;
485 auio.uio_rw = UIO_READ;
486 auio.uio_segflg = UIO_SYSSPACE;
488 auio.uio_resid = buflen;
489 auio.uio_offset = off;
492 free(cookies, M_TEMP);
497 * First we read into the malloc'ed buffer, then
498 * we massage it into user space, one record at a time.
500 if ((error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies, &cookies)) != 0) {
501 DPRINTF(("VOP_READDIR failed: %d\n", error));
505 outp = SCARG(uap, buf);
506 resid = SCARG(uap, nbytes);
507 if ((len = buflen - auio.uio_resid) <= 0)
514 * When using cookies, the vfs has the option of reading from
515 * a different offset than that supplied (UFS truncates the
516 * offset to a block boundary to make sure that it never reads
517 * partway through a directory entry, even if the directory
518 * has been compacted).
520 while (len > 0 && ncookies > 0 && *cookiep <= off) {
521 len -= BSD_DIRENT(inp)->d_reclen;
522 inp += BSD_DIRENT(inp)->d_reclen;
528 for (; len > 0 && resid > 0; len -= reclen) {
529 if (cookiep && ncookies == 0)
531 reclen = BSD_DIRENT(inp)->d_reclen;
533 printf("ibcs2_read: reclen=%d\n", reclen);
537 if (BSD_DIRENT(inp)->d_fileno == 0) {
538 inp += reclen; /* it is a hole; squish it out */
546 if (reclen > len || resid < sizeof(struct ibcs2_direct)) {
547 /* entry too big for buffer, so just stop */
552 * Massage in place to make a iBCS2-shaped dirent (otherwise
553 * we have to worry about touching user memory outside of
554 * the copyout() call).
556 * TODO: if length(filename) > 14, then break filename into
557 * multiple entries and set inode = 0xffff except last
559 idb.ino = (BSD_DIRENT(inp)->d_fileno > 0xfffe) ? 0xfffe :
560 BSD_DIRENT(inp)->d_fileno;
561 (void)copystr(BSD_DIRENT(inp)->d_name, idb.name, 14, &size);
562 bzero(idb.name + size, 14 - size);
563 if ((error = copyout(&idb, outp, sizeof(struct ibcs2_direct))) != 0)
565 /* advance past this real entry */
572 /* advance output past iBCS2-shaped entry */
573 outp += sizeof(struct ibcs2_direct);
574 resid -= sizeof(struct ibcs2_direct);
576 /* if we squished out the whole block, try again */
577 if (outp == SCARG(uap, buf))
579 fp->f_offset = off; /* update the vnode offset */
581 uap->lmsg.u.ms_result = SCARG(uap, nbytes) - resid;
584 free(cookies, M_TEMP);
585 VOP_UNLOCK(vp, 0, td);
591 ibcs2_mknod(struct ibcs2_mknod_args *uap)
593 caddr_t sg = stackgap_init();
596 CHECKALTCREAT(&sg, SCARG(uap, path));
597 if (S_ISFIFO(SCARG(uap, mode))) {
598 struct mkfifo_args ap;
599 SCARG(&ap, path) = SCARG(uap, path);
600 SCARG(&ap, mode) = SCARG(uap, mode);
602 uap->lmsg.u.ms_result = ap.lmsg.u.ms_result;
604 struct mknod_args ap;
605 SCARG(&ap, path) = SCARG(uap, path);
606 SCARG(&ap, mode) = SCARG(uap, mode);
607 SCARG(&ap, dev) = SCARG(uap, dev);
609 uap->lmsg.u.ms_result = ap.lmsg.u.ms_result;
615 ibcs2_getgroups(struct ibcs2_getgroups_args *uap)
618 ibcs2_gid_t *iset = NULL;
619 struct getgroups_args sa;
621 caddr_t sg = stackgap_init();
623 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
624 if (SCARG(uap, gidsetsize)) {
625 SCARG(&sa, gidset) = stackgap_alloc(&sg, NGROUPS_MAX *
627 iset = stackgap_alloc(&sg, SCARG(uap, gidsetsize) *
628 sizeof(ibcs2_gid_t));
630 if ((error = getgroups(&sa)) != 0)
632 uap->lmsg.u.ms_result = sa.lmsg.u.ms_result;
633 if (SCARG(uap, gidsetsize) == 0)
636 for (i = 0, gp = SCARG(&sa, gidset); i < uap->lmsg.u.ms_result; i++)
637 iset[i] = (ibcs2_gid_t)*gp++;
638 if (uap->lmsg.u.ms_result && (error = copyout((caddr_t)iset,
639 (caddr_t)SCARG(uap, gidset),
640 sizeof(ibcs2_gid_t) * uap->lmsg.u.ms_result)))
646 ibcs2_setgroups(struct ibcs2_setgroups_args *uap)
650 struct setgroups_args sa;
652 caddr_t sg = stackgap_init();
654 SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
655 SCARG(&sa, gidset) = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
657 iset = stackgap_alloc(&sg, SCARG(&sa, gidsetsize) *
658 sizeof(ibcs2_gid_t *));
659 if (SCARG(&sa, gidsetsize)) {
660 if ((error = copyin((caddr_t)SCARG(uap, gidset), (caddr_t)iset,
661 sizeof(ibcs2_gid_t *) *
662 SCARG(uap, gidsetsize))) != 0)
665 for (i = 0, gp = SCARG(&sa, gidset); i < SCARG(&sa, gidsetsize); i++)
666 *gp++ = (gid_t)iset[i];
667 error = setgroups(&sa);
668 uap->lmsg.u.ms_result = sa.lmsg.u.ms_result;
673 ibcs2_setuid(struct ibcs2_setuid_args *uap)
675 struct setuid_args sa;
678 SCARG(&sa, uid) = (uid_t)SCARG(uap, uid);
680 uap->lmsg.u.ms_result = sa.lmsg.u.ms_result;
685 ibcs2_setgid(struct ibcs2_setgid_args *uap)
687 struct setgid_args sa;
690 SCARG(&sa, gid) = (gid_t)SCARG(uap, gid);
692 uap->lmsg.u.ms_result = sa.lmsg.u.ms_result;
697 ibcs2_time(struct ibcs2_time_args *uap)
702 uap->lmsg.u.ms_result = tv.tv_sec;
704 return copyout((caddr_t)&tv.tv_sec, (caddr_t)SCARG(uap, tp),
705 sizeof(ibcs2_time_t));
711 ibcs2_pathconf(struct ibcs2_pathconf_args *uap)
713 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
714 return pathconf((struct pathconf_args *)uap);
718 ibcs2_fpathconf(struct ibcs2_fpathconf_args *uap)
720 SCARG(uap, name)++; /* iBCS2 _PC_* defines are offset by one */
721 return fpathconf((struct fpathconf_args *)uap);
725 ibcs2_sysconf(struct ibcs2_sysconf_args *uap)
727 int mib[2], value, len, error;
728 struct sysctl_args sa;
729 struct __getrlimit_args ga;
731 switch(SCARG(uap, name)) {
732 case IBCS2_SC_ARG_MAX:
733 mib[1] = KERN_ARGMAX;
736 case IBCS2_SC_CHILD_MAX:
738 caddr_t sg = stackgap_init();
740 SCARG(&ga, which) = RLIMIT_NPROC;
741 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
742 if ((error = getrlimit(&ga)) != 0)
744 uap->lmsg.u.ms_result = SCARG(&ga, rlp)->rlim_cur;
748 case IBCS2_SC_CLK_TCK:
749 uap->lmsg.u.ms_result = hz;
752 case IBCS2_SC_NGROUPS_MAX:
753 mib[1] = KERN_NGROUPS;
756 case IBCS2_SC_OPEN_MAX:
758 caddr_t sg = stackgap_init();
760 SCARG(&ga, which) = RLIMIT_NOFILE;
761 SCARG(&ga, rlp) = stackgap_alloc(&sg, sizeof(struct rlimit *));
762 if ((error = getrlimit(&ga)) != 0)
764 uap->lmsg.u.ms_result = SCARG(&ga, rlp)->rlim_cur;
768 case IBCS2_SC_JOB_CONTROL:
769 mib[1] = KERN_JOB_CONTROL;
772 case IBCS2_SC_SAVED_IDS:
773 mib[1] = KERN_SAVED_IDS;
776 case IBCS2_SC_VERSION:
777 mib[1] = KERN_POSIX1;
780 case IBCS2_SC_PASS_MAX:
781 uap->lmsg.u.ms_result = 128; /* XXX - should we create PASS_MAX ? */
784 case IBCS2_SC_XOPEN_VERSION:
785 uap->lmsg.u.ms_result = 2; /* XXX: What should that be? */
794 SCARG(&sa, name) = mib;
795 SCARG(&sa, namelen) = 2;
796 SCARG(&sa, old) = &value;
797 SCARG(&sa, oldlenp) = &len;
798 SCARG(&sa, new) = NULL;
799 SCARG(&sa, newlen) = 0;
800 if ((error = __sysctl(&sa)) != 0)
802 uap->lmsg.u.ms_result = value;
807 ibcs2_alarm(struct ibcs2_alarm_args *uap)
810 struct itimerval *itp, *oitp;
811 struct setitimer_args sa;
812 caddr_t sg = stackgap_init();
814 itp = stackgap_alloc(&sg, sizeof(*itp));
815 oitp = stackgap_alloc(&sg, sizeof(*oitp));
816 timevalclear(&itp->it_interval);
817 itp->it_value.tv_sec = SCARG(uap, sec);
818 itp->it_value.tv_usec = 0;
820 SCARG(&sa, which) = ITIMER_REAL;
821 SCARG(&sa, itv) = itp;
822 SCARG(&sa, oitv) = oitp;
823 error = setitimer(&sa);
826 if (oitp->it_value.tv_usec)
827 oitp->it_value.tv_sec++;
828 uap->lmsg.u.ms_result = oitp->it_value.tv_sec;
833 ibcs2_times(struct ibcs2_times_args *uap)
836 struct getrusage_args ga;
839 caddr_t sg = stackgap_init();
840 struct rusage *ru = stackgap_alloc(&sg, sizeof(*ru));
841 #define CONVTCK(r) (r.tv_sec * hz + r.tv_usec / (1000000 / hz))
843 SCARG(&ga, who) = RUSAGE_SELF;
844 SCARG(&ga, rusage) = ru;
845 error = getrusage(&ga);
848 tms.tms_utime = CONVTCK(ru->ru_utime);
849 tms.tms_stime = CONVTCK(ru->ru_stime);
851 SCARG(&ga, who) = RUSAGE_CHILDREN;
852 error = getrusage(&ga);
855 tms.tms_cutime = CONVTCK(ru->ru_utime);
856 tms.tms_cstime = CONVTCK(ru->ru_stime);
859 uap->lmsg.u.ms_result = CONVTCK(t);
861 return copyout((caddr_t)&tms, (caddr_t)SCARG(uap, tp),
866 ibcs2_stime(struct ibcs2_stime_args *uap)
869 struct settimeofday_args sa;
870 caddr_t sg = stackgap_init();
872 SCARG(&sa, tv) = stackgap_alloc(&sg, sizeof(*SCARG(&sa, tv)));
873 SCARG(&sa, tzp) = NULL;
874 if ((error = copyin((caddr_t)SCARG(uap, timep),
875 &(SCARG(&sa, tv)->tv_sec), sizeof(long))) != 0)
877 SCARG(&sa, tv)->tv_usec = 0;
878 if ((error = settimeofday(&sa)) != 0)
880 uap->lmsg.u.ms_result = sa.lmsg.u.ms_result;
885 ibcs2_utime(struct ibcs2_utime_args *uap)
888 struct utimes_args sa;
890 caddr_t sg = stackgap_init();
892 CHECKALTEXIST(&sg, SCARG(uap, path));
893 SCARG(&sa, path) = SCARG(uap, path);
894 if (SCARG(uap, buf)) {
895 struct ibcs2_utimbuf ubuf;
897 if ((error = copyin((caddr_t)SCARG(uap, buf), (caddr_t)&ubuf,
900 SCARG(&sa, tptr) = stackgap_alloc(&sg,
901 2 * sizeof(struct timeval *));
902 tp = (struct timeval *)SCARG(&sa, tptr);
903 tp->tv_sec = ubuf.actime;
906 tp->tv_sec = ubuf.modtime;
909 SCARG(&sa, tptr) = NULL;
911 uap->lmsg.u.ms_result = sa.lmsg.u.ms_result;
916 ibcs2_nice(struct ibcs2_nice_args *uap)
918 struct proc *p = curproc;
920 struct setpriority_args sa;
922 SCARG(&sa, which) = PRIO_PROCESS;
924 SCARG(&sa, prio) = p->p_nice + SCARG(uap, incr);
925 if ((error = setpriority(&sa)) != 0)
927 uap->lmsg.u.ms_result = p->p_nice;
932 * iBCS2 getpgrp, setpgrp, setsid, and setpgid
936 ibcs2_pgrpsys(struct ibcs2_pgrpsys_args *uap)
938 struct proc *p = curproc;
940 switch (SCARG(uap, type)) {
941 case 0: /* getpgrp */
942 uap->lmsg.u.ms_result = p->p_pgrp->pg_id;
945 case 1: /* setpgrp */
947 struct setpgid_args sa;
950 SCARG(&sa, pgid) = 0;
952 uap->lmsg.u.ms_result = p->p_pgrp->pg_id;
956 case 2: /* setpgid */
958 struct setpgid_args sa;
961 SCARG(&sa, pid) = SCARG(uap, pid);
962 SCARG(&sa, pgid) = SCARG(uap, pgid);
963 error = setpgid(&sa);
964 uap->lmsg.u.ms_result = sa.lmsg.u.ms_result;
970 struct setsid_args sida;
973 error = setsid(&sida);
974 uap->lmsg.u.ms_result = sida.lmsg.u.ms_result;
984 * XXX - need to check for nested calls
988 ibcs2_plock(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(curthread)) != 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(struct ibcs2_uadmin_args *uap)
1012 #define SCO_A_REBOOT 1
1013 #define SCO_A_SHUTDOWN 2
1014 #define SCO_A_REMOUNT 4
1015 #define SCO_A_CLOCK 8
1016 #define SCO_A_SETCONFIG 128
1017 #define SCO_A_GETDEV 130
1019 #define SCO_AD_HALT 0
1020 #define SCO_AD_BOOT 1
1021 #define SCO_AD_IBOOT 2
1022 #define SCO_AD_PWRDOWN 3
1023 #define SCO_AD_PWRNAP 4
1025 #define SCO_AD_PANICBOOT 1
1027 #define SCO_AD_GETBMAJ 0
1028 #define SCO_AD_GETCMAJ 1
1030 if (suser(curthread))
1033 switch(SCARG(uap, cmd)) {
1035 case SCO_A_SHUTDOWN:
1036 switch(SCARG(uap, func)) {
1037 struct reboot_args r;
1039 case SCO_AD_PWRDOWN:
1045 r.opt = RB_AUTOBOOT;
1051 case SCO_A_SETCONFIG:
1054 return EINVAL; /* XXX - TODO */
1060 ibcs2_sysfs(struct ibcs2_sysfs_args *uap)
1062 #define IBCS2_GETFSIND 1
1063 #define IBCS2_GETFSTYP 2
1064 #define IBCS2_GETNFSTYP 3
1066 switch(SCARG(uap, cmd)) {
1067 case IBCS2_GETFSIND:
1068 case IBCS2_GETFSTYP:
1069 case IBCS2_GETNFSTYP:
1072 return EINVAL; /* XXX - TODO */
1076 ibcs2_unlink(struct ibcs2_unlink_args *uap)
1078 caddr_t sg = stackgap_init();
1080 CHECKALTEXIST(&sg, SCARG(uap, path));
1081 return unlink((struct unlink_args *)uap);
1085 ibcs2_chdir(struct ibcs2_chdir_args *uap)
1087 caddr_t sg = stackgap_init();
1089 CHECKALTEXIST(&sg, SCARG(uap, path));
1090 return chdir((struct chdir_args *)uap);
1094 ibcs2_chmod(struct ibcs2_chmod_args *uap)
1096 caddr_t sg = stackgap_init();
1098 CHECKALTEXIST(&sg, SCARG(uap, path));
1099 return chmod((struct chmod_args *)uap);
1103 ibcs2_chown(struct ibcs2_chown_args *uap)
1105 caddr_t sg = stackgap_init();
1107 CHECKALTEXIST(&sg, SCARG(uap, path));
1108 return chown((struct chown_args *)uap);
1112 ibcs2_rmdir(struct ibcs2_rmdir_args *uap)
1114 caddr_t sg = stackgap_init();
1116 CHECKALTEXIST(&sg, SCARG(uap, path));
1117 return rmdir((struct rmdir_args *)uap);
1121 ibcs2_mkdir(struct ibcs2_mkdir_args *uap)
1123 caddr_t sg = stackgap_init();
1125 CHECKALTCREAT(&sg, SCARG(uap, path));
1126 return mkdir((struct mkdir_args *)uap);
1130 ibcs2_symlink(struct ibcs2_symlink_args *uap)
1132 caddr_t sg = stackgap_init();
1134 CHECKALTEXIST(&sg, SCARG(uap, path));
1135 CHECKALTCREAT(&sg, SCARG(uap, link));
1136 return symlink((struct symlink_args *)uap);
1140 ibcs2_rename(struct ibcs2_rename_args *uap)
1142 caddr_t sg = stackgap_init();
1144 CHECKALTEXIST(&sg, SCARG(uap, from));
1145 CHECKALTCREAT(&sg, SCARG(uap, to));
1146 return rename((struct rename_args *)uap);
1150 ibcs2_readlink(struct ibcs2_readlink_args *uap)
1152 caddr_t sg = stackgap_init();
1154 CHECKALTEXIST(&sg, SCARG(uap, path));
1155 return readlink((struct readlink_args *) uap);