1 /* $NetBSD: ultrix_misc.c,v 1.6 1994/08/01 14:15:08 glass Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 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. 10 * 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. 15 * 16 * Redistribution and use in source and binary forms, with or without 17 * modification, are permitted provided that the following conditions 18 * are met: 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. 31 * 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 42 * SUCH DAMAGE. 43 * 44 * 45 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93 46 * 47 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp 48 */ 49 50 /* 51 * SunOS compatibility module. 52 * 53 * SunOS system calls that are implemented differently in BSD are 54 * handled here. 55 */ 56 57 #include <sys/param.h> 58 #include <sys/systm.h> 59 #include <sys/namei.h> 60 #include <sys/dir.h> 61 #include <sys/proc.h> 62 #include <sys/file.h> 63 #include <sys/stat.h> 64 #include <sys/filedesc.h> 65 #include <sys/ioctl.h> 66 #include <sys/kernel.h> 67 #include <sys/exec.h> 68 #include <sys/malloc.h> 69 #include <sys/mbuf.h> 70 #include <sys/mman.h> 71 #include <sys/mount.h> 72 #include <sys/resource.h> 73 #include <sys/resourcevar.h> 74 #include <sys/signal.h> 75 #include <sys/signalvar.h> 76 #include <sys/socket.h> 77 #include <sys/vnode.h> 78 #include <sys/uio.h> 79 #include <sys/wait.h> 80 #include <sys/utsname.h> 81 #include <sys/unistd.h> 82 83 #include <netinet/in.h> 84 85 #include <miscfs/specfs/specdev.h> 86 87 #include <nfs/rpcv2.h> 88 #include <nfs/nfsv2.h> 89 #include <nfs/nfs.h> 90 91 #include <vm/vm.h> 92 93 #define GSI_PROG_ENV 1 94 95 struct ultrix_getsysinfo_args { 96 unsigned op; 97 char *buffer; 98 unsigned nbytes; 99 int *start; 100 char *arg; 101 }; 102 103 ultrix_getsysinfo(p, uap, retval) 104 struct proc *p; 105 struct ultrix_getsysinfo_args *uap; 106 int *retval; 107 { 108 static short progenv = 0; 109 110 switch (uap->op) { 111 /* operations implemented: */ 112 case GSI_PROG_ENV: 113 if (uap->nbytes < sizeof(short)) 114 return EINVAL; 115 *retval = 1; 116 return(copyout(&progenv, uap->buffer, sizeof(short))); 117 default: 118 *retval = 0; /* info unavail */ 119 return 0; 120 } 121 } 122 123 struct ultrix_setsysinfo_args { 124 unsigned op; 125 char *buffer; 126 unsigned nbytes; 127 unsigned arg; 128 unsigned flag; 129 }; 130 131 ultrix_setsysinfo(p, uap, retval) 132 struct proc *p; 133 struct ultrix_setsysinfo_args *uap; 134 int *retval; 135 { 136 *retval = 0; 137 return 0; 138 } 139 140 struct ultrix_waitpid_args { 141 int pid; 142 int *status; 143 int options; 144 struct rusage *rusage; 145 }; 146 147 ultrix_waitpid(p, uap, retval) 148 struct proc *p; 149 struct ultrix_waitpid_args *uap; 150 int *retval; 151 { 152 153 uap->rusage = 0; 154 return (wait4(p, uap, retval)); 155 } 156 struct sun_wait4_args { 157 int pid; 158 int *status; 159 int options; 160 struct rusage *rusage; 161 int compat; 162 }; 163 sun_wait4(p, uap, retval) 164 struct proc *p; 165 struct sun_wait4_args *uap; 166 int *retval; 167 { 168 169 if (uap->pid == 0) 170 uap->pid = WAIT_ANY; 171 return (wait4(p, uap, retval)); 172 } 173 174 struct sun_wait3_args { 175 int *status; 176 int options; 177 struct rusage *rusage; 178 }; 179 180 sun_wait3(p, uap, retval) 181 struct proc *p; 182 struct sun_wait3_args *uap; 183 int *retval; 184 { 185 struct sun_wait4_args ua; 186 187 if (uap == NULL) 188 panic("uap == NULL"); 189 ua.pid = -1; 190 ua.status = uap->status; 191 ua.options = uap->options; 192 ua.rusage = uap->rusage; 193 194 return (wait4(p, &ua, retval)); 195 } 196 197 struct sun_creat_args { 198 char *fname; 199 int fmode; 200 }; 201 sun_creat(p, uap, retval) 202 struct proc *p; 203 struct sun_creat_args *uap; 204 int *retval; 205 { 206 struct args { 207 char *fname; 208 int mode; 209 int crtmode; 210 } openuap; 211 212 openuap.fname = uap->fname; 213 openuap.crtmode = uap->fmode; 214 openuap.mode = O_WRONLY | O_CREAT | O_TRUNC; 215 return (open(p, &openuap, retval)); 216 } 217 218 struct sun_execv_args { 219 char *fname; 220 char **argp; 221 char **envp; /* pseudo */ 222 }; 223 sun_execv(p, uap, retval) 224 struct proc *p; 225 struct sun_execv_args *uap; 226 int *retval; 227 { 228 229 uap->envp = NULL; 230 return (execve(p, uap, retval)); 231 } 232 233 struct sun_omsync_args { 234 caddr_t addr; 235 int len; 236 int flags; 237 }; 238 sun_omsync(p, uap, retval) 239 struct proc *p; 240 struct sun_omsync_args *uap; 241 int *retval; 242 { 243 244 if (uap->flags) 245 return (EINVAL); 246 return (msync(p, uap, retval)); 247 } 248 249 struct sun_unmount_args { 250 char *name; 251 int flags; /* pseudo */ 252 }; 253 sun_unmount(p, uap, retval) 254 struct proc *p; 255 struct sun_unmount_args *uap; 256 int *retval; 257 { 258 259 uap->flags = 0; 260 return (unmount(p, uap, retval)); 261 } 262 263 #define SUNM_RDONLY 0x01 /* mount fs read-only */ 264 #define SUNM_NOSUID 0x02 /* mount fs with setuid disallowed */ 265 #define SUNM_NEWTYPE 0x04 /* type is string (char *), not int */ 266 #define SUNM_GRPID 0x08 /* (bsd semantics; ignored) */ 267 #define SUNM_REMOUNT 0x10 /* update existing mount */ 268 #define SUNM_NOSUB 0x20 /* prevent submounts (rejected) */ 269 #define SUNM_MULTI 0x40 /* (ignored) */ 270 #define SUNM_SYS5 0x80 /* Sys 5-specific semantics (rejected) */ 271 272 struct sun_nfs_args { 273 struct sockaddr_in *addr; /* file server address */ 274 caddr_t fh; /* file handle to be mounted */ 275 int flags; /* flags */ 276 int wsize; /* write size in bytes */ 277 int rsize; /* read size in bytes */ 278 int timeo; /* initial timeout in .1 secs */ 279 int retrans; /* times to retry send */ 280 char *hostname; /* server's hostname */ 281 int acregmin; /* attr cache file min secs */ 282 int acregmax; /* attr cache file max secs */ 283 int acdirmin; /* attr cache dir min secs */ 284 int acdirmax; /* attr cache dir max secs */ 285 char *netname; /* server's netname */ 286 struct pathcnf *pathconf; /* static pathconf kludge */ 287 }; 288 289 struct sun_mount_args { 290 char *type; 291 char *dir; 292 int flags; 293 caddr_t data; 294 }; 295 sun_mount(p, uap, retval) 296 struct proc *p; 297 struct sun_mount_args *uap; 298 int *retval; 299 { 300 int oflags = uap->flags, nflags, error; 301 extern char sigcode[], esigcode[]; 302 char fsname[MFSNAMELEN]; 303 304 #define szsigcode (esigcode - sigcode) 305 306 if (oflags & (SUNM_NOSUB | SUNM_SYS5)) 307 return (EINVAL); 308 if ((oflags & SUNM_NEWTYPE) == 0) 309 return (EINVAL); 310 nflags = 0; 311 if (oflags & SUNM_RDONLY) 312 nflags |= MNT_RDONLY; 313 if (oflags & SUNM_NOSUID) 314 nflags |= MNT_NOSUID; 315 if (oflags & SUNM_REMOUNT) 316 nflags |= MNT_UPDATE; 317 uap->flags = nflags; 318 319 if (error = copyinstr((caddr_t)uap->type, fsname, sizeof fsname, (u_int *)0)) 320 return (error); 321 322 if (strcmp(fsname, "4.2") == 0) { 323 uap->type = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN); 324 if (error = copyout("ufs", uap->type, sizeof("ufs"))) 325 return (error); 326 } else if (strcmp(fsname, "nfs") == 0) { 327 struct sun_nfs_args sna; 328 struct sockaddr_in sain; 329 struct nfs_args na; 330 struct sockaddr sa; 331 332 if (error = copyin(uap->data, &sna, sizeof sna)) 333 return (error); 334 if (error = copyin(sna.addr, &sain, sizeof sain)) 335 return (error); 336 bcopy(&sain, &sa, sizeof sa); 337 sa.sa_len = sizeof(sain); 338 uap->data = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN); 339 na.addr = (struct sockaddr *)((int)uap->data + sizeof na); 340 na.sotype = SOCK_DGRAM; 341 na.proto = IPPROTO_UDP; 342 na.fh = (nfsv2fh_t *)sna.fh; 343 na.flags = sna.flags; 344 na.wsize = sna.wsize; 345 na.rsize = sna.rsize; 346 na.timeo = sna.timeo; 347 na.retrans = sna.retrans; 348 na.hostname = sna.hostname; 349 350 if (error = copyout(&sa, na.addr, sizeof sa)) 351 return (error); 352 if (error = copyout(&na, uap->data, sizeof na)) 353 return (error); 354 } 355 return (mount(p, uap, retval)); 356 } 357 358 #if defined(NFSCLIENT) 359 async_daemon(p, uap, retval) 360 struct proc *p; 361 void *uap; 362 int *retval; 363 { 364 struct nfssvc_args { 365 int flag; 366 caddr_t argp; 367 } args; 368 369 args.flag = NFSSVC_BIOD; 370 return nfssvc(p, &args, retval); 371 } 372 #endif /* NFSCLIENT */ 373 374 struct sun_sigpending_args { 375 int *mask; 376 }; 377 sun_sigpending(p, uap, retval) 378 struct proc *p; 379 struct sun_sigpending_args *uap; 380 int *retval; 381 { 382 int mask = p->p_siglist & p->p_sigmask; 383 384 return (copyout((caddr_t)&mask, (caddr_t)uap->mask, sizeof(int))); 385 } 386 387 #if 0 388 /* XXX: Temporary until sys/dir.h, include/dirent.h and sys/dirent.h are fixed */ 389 struct dirent { 390 u_long d_fileno; /* file number of entry */ 391 u_short d_reclen; /* length of this record */ 392 u_short d_namlen; /* length of string in d_name */ 393 char d_name[255 + 1]; /* name must be no longer than this */ 394 }; 395 #endif 396 397 /* 398 * Here is the sun layout. (Compare the BSD layout in <sys/dirent.h>.) 399 * We can assume big-endian, so the BSD d_type field is just the high 400 * byte of the SunOS d_namlen field, after adjusting for the extra "long". 401 */ 402 struct sun_dirent { 403 long d_off; 404 u_long d_fileno; 405 u_short d_reclen; 406 u_short d_namlen; 407 char d_name[256]; 408 }; 409 410 /* 411 * Read Sun-style directory entries. We suck them into kernel space so 412 * that they can be massaged before being copied out to user code. Like 413 * SunOS, we squish out `empty' entries. 414 * 415 * This is quite ugly, but what do you expect from compatibility code? 416 */ 417 struct sun_getdents_args { 418 int fd; 419 char *buf; 420 int nbytes; 421 }; 422 sun_getdents(p, uap, retval) 423 struct proc *p; 424 register struct sun_getdents_args *uap; 425 int *retval; 426 { 427 register struct vnode *vp; 428 register caddr_t inp, buf; /* BSD-format */ 429 register int len, reclen; /* BSD-format */ 430 register caddr_t outp; /* Sun-format */ 431 register int resid; /* Sun-format */ 432 struct file *fp; 433 struct uio auio; 434 struct iovec aiov; 435 off_t off; /* true file offset */ 436 long soff; /* Sun file offset */ 437 int buflen, error, eofflag; 438 #define BSD_DIRENT(cp) ((struct dirent *)(cp)) 439 #define SUN_RECLEN(reclen) (reclen + sizeof(long)) 440 441 if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0) 442 return (error); 443 if ((fp->f_flag & FREAD) == 0) 444 return (EBADF); 445 vp = (struct vnode *)fp->f_data; 446 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */ 447 return (EINVAL); 448 buflen = min(MAXBSIZE, uap->nbytes); 449 buf = malloc(buflen, M_TEMP, M_WAITOK); 450 VOP_LOCK(vp); 451 off = fp->f_offset; 452 again: 453 aiov.iov_base = buf; 454 aiov.iov_len = buflen; 455 auio.uio_iov = &aiov; 456 auio.uio_iovcnt = 1; 457 auio.uio_rw = UIO_READ; 458 auio.uio_segflg = UIO_SYSSPACE; 459 auio.uio_procp = p; 460 auio.uio_resid = buflen; 461 auio.uio_offset = off; 462 /* 463 * First we read into the malloc'ed buffer, then 464 * we massage it into user space, one record at a time. 465 */ 466 if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, (u_long *)0, 467 0)) 468 goto out; 469 inp = buf; 470 outp = uap->buf; 471 resid = uap->nbytes; 472 if ((len = buflen - auio.uio_resid) == 0) 473 goto eof; 474 for (; len > 0; len -= reclen) { 475 reclen = ((struct dirent *)inp)->d_reclen; 476 if (reclen & 3) 477 panic("sun_getdents"); 478 off += reclen; /* each entry points to next */ 479 if (BSD_DIRENT(inp)->d_fileno == 0) { 480 inp += reclen; /* it is a hole; squish it out */ 481 continue; 482 } 483 if (reclen > len || resid < SUN_RECLEN(reclen)) { 484 /* entry too big for buffer, so just stop */ 485 outp++; 486 break; 487 } 488 /* 489 * Massage in place to make a Sun-shaped dirent (otherwise 490 * we have to worry about touching user memory outside of 491 * the copyout() call). 492 */ 493 BSD_DIRENT(inp)->d_reclen = SUN_RECLEN(reclen); 494 #if notdef 495 BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */ 496 #endif 497 soff = off; 498 if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 || 499 (error = copyout(inp, outp + sizeof soff, reclen)) != 0) 500 goto out; 501 /* advance past this real entry */ 502 inp += reclen; 503 /* advance output past Sun-shaped entry */ 504 outp += SUN_RECLEN(reclen); 505 resid -= SUN_RECLEN(reclen); 506 } 507 /* if we squished out the whole block, try again */ 508 if (outp == uap->buf) 509 goto again; 510 fp->f_offset = off; /* update the vnode offset */ 511 eof: 512 *retval = uap->nbytes - resid; 513 out: 514 VOP_UNLOCK(vp); 515 free(buf, M_TEMP); 516 return (error); 517 } 518 519 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */ 520 521 struct sun_mmap_args { 522 caddr_t addr; 523 size_t len; 524 int prot; 525 int flags; 526 int fd; 527 long off; /* not off_t! */ 528 off_t qoff; /* created here and fed to mmap() */ 529 }; 530 sun_mmap(p, uap, retval) 531 register struct proc *p; 532 register struct sun_mmap_args *uap; 533 int *retval; 534 { 535 register struct filedesc *fdp; 536 register struct file *fp; 537 register struct vnode *vp; 538 539 /* 540 * Verify the arguments. 541 */ 542 if (uap->prot & ~(PROT_READ|PROT_WRITE|PROT_EXEC)) 543 return (EINVAL); /* XXX still needed? */ 544 545 if ((uap->flags & SUN__MAP_NEW) == 0) 546 return (EINVAL); 547 uap->flags &= ~SUN__MAP_NEW; 548 549 if ((uap->flags & MAP_FIXED) == 0 && 550 uap->addr != 0 && 551 uap->addr < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ)) 552 uap->addr = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ); 553 554 /* 555 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX) 556 */ 557 fdp = p->p_fd; 558 if ((unsigned)uap->fd < fdp->fd_nfiles && /*XXX*/ 559 (fp = fdp->fd_ofiles[uap->fd]) != NULL && /*XXX*/ 560 fp->f_type == DTYPE_VNODE && /*XXX*/ 561 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/ 562 iszerodev(vp->v_rdev)) { /*XXX*/ 563 uap->flags |= MAP_ANON; 564 uap->fd = -1; 565 } 566 567 uap->qoff = uap->off; 568 return (mmap(p, uap, retval)); 569 } 570 571 #define MC_SYNC 1 572 #define MC_LOCK 2 573 #define MC_UNLOCK 3 574 #define MC_ADVISE 4 575 #define MC_LOCKAS 5 576 #define MC_UNLOCKAS 6 577 578 struct sun_mctl_args { 579 caddr_t addr; 580 size_t len; 581 int func; 582 void *arg; 583 }; 584 sun_mctl(p, uap, retval) 585 register struct proc *p; 586 register struct sun_mctl_args *uap; 587 int *retval; 588 { 589 590 switch (uap->func) { 591 592 case MC_ADVISE: /* ignore for now */ 593 return (0); 594 595 case MC_SYNC: /* translate to msync */ 596 return (msync(p, uap, retval)); 597 598 default: 599 return (EINVAL); 600 } 601 } 602 603 struct sun_setsockopt_args { 604 int s; 605 int level; 606 int name; 607 caddr_t val; 608 int valsize; 609 }; 610 sun_setsockopt(p, uap, retval) 611 struct proc *p; 612 register struct sun_setsockopt_args *uap; 613 int *retval; 614 { 615 struct file *fp; 616 struct mbuf *m = NULL; 617 int error; 618 619 if (error = getsock(p->p_fd, uap->s, &fp)) 620 return (error); 621 #define SO_DONTLINGER (~SO_LINGER) 622 if (uap->name == SO_DONTLINGER) { 623 m = m_get(M_WAIT, MT_SOOPTS); 624 if (m == NULL) 625 return (ENOBUFS); 626 mtod(m, struct linger *)->l_onoff = 0; 627 m->m_len = sizeof(struct linger); 628 return (sosetopt((struct socket *)fp->f_data, uap->level, 629 SO_LINGER, m)); 630 } 631 if (uap->valsize > MLEN) 632 return (EINVAL); 633 if (uap->val) { 634 m = m_get(M_WAIT, MT_SOOPTS); 635 if (m == NULL) 636 return (ENOBUFS); 637 if (error = copyin(uap->val, mtod(m, caddr_t), 638 (u_int)uap->valsize)) { 639 (void) m_free(m); 640 return (error); 641 } 642 m->m_len = uap->valsize; 643 } 644 return (sosetopt((struct socket *)fp->f_data, uap->level, 645 uap->name, m)); 646 } 647 648 struct sun_fchroot_args { 649 int fdes; 650 }; 651 sun_fchroot(p, uap, retval) 652 register struct proc *p; 653 register struct sun_fchroot_args *uap; 654 int *retval; 655 { 656 register struct filedesc *fdp = p->p_fd; 657 register struct vnode *vp; 658 struct file *fp; 659 int error; 660 661 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) 662 return (error); 663 if ((error = getvnode(fdp, uap->fdes, &fp)) != 0) 664 return (error); 665 vp = (struct vnode *)fp->f_data; 666 VOP_LOCK(vp); 667 if (vp->v_type != VDIR) 668 error = ENOTDIR; 669 else 670 error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p); 671 VOP_UNLOCK(vp); 672 if (error) 673 return (error); 674 VREF(vp); 675 if (fdp->fd_rdir != NULL) 676 vrele(fdp->fd_rdir); 677 fdp->fd_rdir = vp; 678 return (0); 679 } 680 681 /* 682 * XXX: This needs cleaning up. 683 */ 684 sun_auditsys(...) 685 { 686 return 0; 687 } 688 689 struct sun_utsname { 690 char sysname[9]; 691 char nodename[9]; 692 char nodeext[65-9]; 693 char release[9]; 694 char version[9]; 695 char machine[9]; 696 }; 697 698 struct sun_uname_args { 699 struct sun_utsname *name; 700 }; 701 sun_uname(p, uap, retval) 702 struct proc *p; 703 struct sun_uname_args *uap; 704 int *retval; 705 { 706 struct sun_utsname sut; 707 extern char ostype[], machine[], osrelease[]; 708 709 bzero(&sut, sizeof(sut)); 710 711 bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1); 712 bcopy(hostname, sut.nodename, sizeof(sut.nodename)); 713 sut.nodename[sizeof(sut.nodename)-1] = '\0'; 714 bcopy(osrelease, sut.release, sizeof(sut.release) - 1); 715 bcopy("1", sut.version, sizeof(sut.version) - 1); 716 bcopy(machine, sut.machine, sizeof(sut.machine) - 1); 717 718 return copyout((caddr_t)&sut, (caddr_t)uap->name, sizeof(struct sun_utsname)); 719 } 720 721 struct sun_setpgid_args { 722 int pid; /* target process id */ 723 int pgid; /* target pgrp id */ 724 }; 725 int 726 sun_setpgid(p, uap, retval) 727 struct proc *p; 728 struct sun_setpgid_args *uap; 729 int *retval; 730 { 731 /* 732 * difference to our setpgid call is to include backwards 733 * compatibility to pre-setsid() binaries. Do setsid() 734 * instead of setpgid() in those cases where the process 735 * tries to create a new session the old way. 736 */ 737 if (!uap->pgid && (!uap->pid || uap->pid == p->p_pid)) 738 return setsid(p, uap, retval); 739 else 740 return setpgid(p, uap, retval); 741 } 742 743 struct sun_open_args { 744 char *fname; 745 int fmode; 746 int crtmode; 747 }; 748 sun_open(p, uap, retval) 749 struct proc *p; 750 struct sun_open_args *uap; 751 int *retval; 752 { 753 int l, r; 754 int noctty = uap->fmode & 0x8000; 755 int ret; 756 757 /* convert mode into NetBSD mode */ 758 l = uap->fmode; 759 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800)); 760 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0); 761 r |= ((l & 0x0080) ? O_SHLOCK : 0); 762 r |= ((l & 0x0100) ? O_EXLOCK : 0); 763 r |= ((l & 0x2000) ? O_FSYNC : 0); 764 765 uap->fmode = r; 766 ret = open(p, uap, retval); 767 768 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { 769 struct filedesc *fdp = p->p_fd; 770 struct file *fp = fdp->fd_ofiles[*retval]; 771 772 /* ignore any error, just give it a try */ 773 if (fp->f_type == DTYPE_VNODE) 774 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p); 775 } 776 return ret; 777 } 778 779 #if defined (NFSSERVER) 780 struct nfssvc_args { 781 int fd; 782 caddr_t mskval; 783 int msklen; 784 caddr_t mtchval; 785 int mtchlen; 786 }; 787 struct sun_nfssvc_args { 788 int fd; 789 }; 790 sun_nfssvc(p, uap, retval) 791 struct proc *p; 792 struct sun_nfssvc_args *uap; 793 int *retval; 794 { 795 struct nfssvc_args outuap; 796 struct sockaddr sa; 797 int error; 798 extern char sigcode[], esigcode[]; 799 800 bzero(&outuap, sizeof outuap); 801 outuap.fd = uap->fd; 802 outuap.mskval = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN); 803 outuap.msklen = sizeof sa; 804 outuap.mtchval = outuap.mskval + sizeof sa; 805 outuap.mtchlen = sizeof sa; 806 807 bzero(&sa, sizeof sa); 808 if (error = copyout(&sa, outuap.mskval, outuap.msklen)) 809 return (error); 810 if (error = copyout(&sa, outuap.mtchval, outuap.mtchlen)) 811 return (error); 812 813 return nfssvc(p, &outuap, retval); 814 } 815 #endif /* NFSSERVER */ 816 817 struct sun_ustat { 818 daddr_t f_tfree; /* total free */ 819 ino_t f_tinode; /* total inodes free */ 820 char f_fname[6]; /* filsys name */ 821 char f_fpack[6]; /* filsys pack name */ 822 }; 823 struct sun_ustat_args { 824 int dev; 825 struct sun_ustat *buf; 826 }; 827 sun_ustat(p, uap, retval) 828 struct proc *p; 829 struct sun_ustat_args *uap; 830 int *retval; 831 { 832 struct sun_ustat us; 833 int error; 834 835 bzero(&us, sizeof us); 836 837 /* 838 * XXX: should set f_tfree and f_tinode at least 839 * How do we translate dev -> fstat? (and then to sun_ustat) 840 */ 841 842 if (error = copyout(&us, uap->buf, sizeof us)) 843 return (error); 844 return 0; 845 } 846 847 struct sun_quotactl_args { 848 int cmd; 849 char *special; 850 int uid; 851 caddr_t addr; 852 }; 853 sun_quotactl(p, uap, retval) 854 struct proc *p; 855 struct sun_quotactl_args *uap; 856 int *retval; 857 { 858 return EINVAL; 859 } 860 861 sun_vhangup(p, uap, retval) 862 struct proc *p; 863 void *uap; 864 int *retval; 865 { 866 return 0; 867 } 868 869 struct sun_statfs { 870 long f_type; /* type of info, zero for now */ 871 long f_bsize; /* fundamental file system block size */ 872 long f_blocks; /* total blocks in file system */ 873 long f_bfree; /* free blocks */ 874 long f_bavail; /* free blocks available to non-super-user */ 875 long f_files; /* total file nodes in file system */ 876 long f_ffree; /* free file nodes in fs */ 877 fsid_t f_fsid; /* file system id */ 878 long f_spare[7]; /* spare for later */ 879 }; 880 static 881 sunstatfs(sp, buf) 882 struct statfs *sp; 883 caddr_t buf; 884 { 885 struct sun_statfs ssfs; 886 887 bzero(&ssfs, sizeof ssfs); 888 ssfs.f_type = 0; 889 ssfs.f_bsize = sp->f_bsize; 890 ssfs.f_blocks = sp->f_blocks; 891 ssfs.f_bfree = sp->f_bfree; 892 ssfs.f_bavail = sp->f_bavail; 893 ssfs.f_files = sp->f_files; 894 ssfs.f_ffree = sp->f_ffree; 895 ssfs.f_fsid = sp->f_fsid; 896 return copyout((caddr_t)&ssfs, buf, sizeof ssfs); 897 } 898 899 struct sun_statfs_args { 900 char *path; 901 struct sun_statfs *buf; 902 }; 903 sun_statfs(p, uap, retval) 904 struct proc *p; 905 struct sun_statfs_args *uap; 906 int *retval; 907 { 908 register struct mount *mp; 909 register struct statfs *sp; 910 int error; 911 struct nameidata nd; 912 913 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p); 914 if (error = namei(&nd)) 915 return (error); 916 mp = nd.ni_vp->v_mount; 917 sp = &mp->mnt_stat; 918 vrele(nd.ni_vp); 919 if (error = VFS_STATFS(mp, sp, p)) 920 return (error); 921 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; 922 return sunstatfs(sp, (caddr_t)uap->buf); 923 } 924 925 struct sun_fstatfs_args { 926 int fd; 927 struct sun_statfs *buf; 928 }; 929 sun_fstatfs(p, uap, retval) 930 struct proc *p; 931 struct sun_fstatfs_args *uap; 932 int *retval; 933 { 934 struct file *fp; 935 struct mount *mp; 936 register struct statfs *sp; 937 int error; 938 939 if (error = getvnode(p->p_fd, uap->fd, &fp)) 940 return (error); 941 mp = ((struct vnode *)fp->f_data)->v_mount; 942 sp = &mp->mnt_stat; 943 if (error = VFS_STATFS(mp, sp, p)) 944 return (error); 945 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; 946 return sunstatfs(sp, (caddr_t)uap->buf); 947 } 948 949 struct sun_exportfs_args { 950 char *path; 951 char *ex; /* struct sun_export * */ 952 }; 953 sun_exportfs(p, uap, retval) 954 struct proc *p; 955 struct sun_exportfs_args *uap; 956 int *retval; 957 { 958 /* 959 * XXX: should perhaps translate into a mount(2) 960 * with MOUNT_EXPORT? 961 */ 962 return 0; 963 } 964 965 struct sun_mknod_args { 966 char *fname; 967 int fmode; 968 int dev; 969 }; 970 971 sun_mknod(p, uap, retval) 972 struct proc *p; 973 struct sun_mknod_args *uap; 974 int *retval; 975 { 976 if (S_ISFIFO(uap->fmode)) 977 return mkfifo(p, uap, retval); 978 979 return mknod(p, uap, retval); 980 } 981 982 #define SUN_SC_ARG_MAX 1 983 #define SUN_SC_CHILD_MAX 2 984 #define SUN_SC_CLK_TCK 3 985 #define SUN_SC_NGROUPS_MAX 4 986 #define SUN_SC_OPEN_MAX 5 987 #define SUN_SC_JOB_CONTROL 6 988 #define SUN_SC_SAVED_IDS 7 989 #define SUN_SC_VERSION 8 990 991 struct sun_sysconf_args { 992 int name; 993 }; 994 995 sun_sysconf(p, uap, retval) 996 struct proc *p; 997 struct sun_sysconf_args *uap; 998 int *retval; 999 { 1000 extern int maxfiles; 1001 1002 switch(uap->name) { 1003 case SUN_SC_ARG_MAX: 1004 *retval = ARG_MAX; 1005 break; 1006 case SUN_SC_CHILD_MAX: 1007 *retval = maxproc; 1008 break; 1009 case SUN_SC_CLK_TCK: 1010 *retval = 60; /* should this be `hz', ie. 100? */ 1011 break; 1012 case SUN_SC_NGROUPS_MAX: 1013 *retval = NGROUPS_MAX; 1014 break; 1015 case SUN_SC_OPEN_MAX: 1016 *retval = maxfiles; 1017 break; 1018 case SUN_SC_JOB_CONTROL: 1019 *retval = 1; 1020 break; 1021 case SUN_SC_SAVED_IDS: 1022 #ifdef _POSIX_SAVED_IDS 1023 *retval = 1; 1024 #else 1025 *retval = 0; 1026 #endif 1027 break; 1028 case SUN_SC_VERSION: 1029 *retval = 198808; 1030 break; 1031 default: 1032 return EINVAL; 1033 } 1034 return 0; 1035 } 1036 1037 #define SUN_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */ 1038 #define SUN_RLIM_NLIMITS 7 1039 1040 struct sun_getrlimit_args { 1041 int which; 1042 struct orlimit *rlp; 1043 }; 1044 1045 sun_getrlimit(p, uap, retval) 1046 struct proc *p; 1047 struct sun_getrlimit_args *uap; 1048 int *retval; 1049 { 1050 if (uap->which >= SUN_RLIM_NLIMITS) 1051 return EINVAL; 1052 1053 if (uap->which == SUN_RLIMIT_NOFILE) 1054 uap->which = RLIMIT_NOFILE; 1055 1056 return ogetrlimit(p, uap, retval); 1057 } 1058 1059 struct sun_setrlimit_args { 1060 int which; 1061 struct orlimit *rlp; 1062 }; 1063 1064 sun_setrlimit(p, uap, retval) 1065 struct proc *p; 1066 struct sun_getrlimit_args *uap; 1067 int *retval; 1068 { 1069 if (uap->which >= SUN_RLIM_NLIMITS) 1070 return EINVAL; 1071 1072 if (uap->which == SUN_RLIMIT_NOFILE) 1073 uap->which = RLIMIT_NOFILE; 1074 1075 return osetrlimit(p, uap, retval); 1076 } 1077