1 /* $NetBSD: ultrix_misc.c,v 1.10 1995/03/09 12:06:17 mycroft 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 register_t *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 register_t *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 register_t *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 register_t *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 register_t *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 register_t *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 register_t *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 register_t *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, 320 (size_t *)0)) 321 return (error); 322 323 if (strcmp(fsname, "4.2") == 0) { 324 uap->type = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN); 325 if (error = copyout("ufs", uap->type, sizeof("ufs"))) 326 return (error); 327 } else if (strcmp(fsname, "nfs") == 0) { 328 struct sun_nfs_args sna; 329 struct sockaddr_in sain; 330 struct nfs_args na; 331 struct sockaddr sa; 332 333 if (error = copyin(uap->data, &sna, sizeof sna)) 334 return (error); 335 if (error = copyin(sna.addr, &sain, sizeof sain)) 336 return (error); 337 bcopy(&sain, &sa, sizeof sa); 338 sa.sa_len = sizeof(sain); 339 uap->data = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN); 340 na.addr = (struct sockaddr *)((int)uap->data + sizeof na); 341 na.sotype = SOCK_DGRAM; 342 na.proto = IPPROTO_UDP; 343 na.fh = (nfsv2fh_t *)sna.fh; 344 na.flags = sna.flags; 345 na.wsize = sna.wsize; 346 na.rsize = sna.rsize; 347 na.timeo = sna.timeo; 348 na.retrans = sna.retrans; 349 na.hostname = sna.hostname; 350 351 if (error = copyout(&sa, na.addr, sizeof sa)) 352 return (error); 353 if (error = copyout(&na, uap->data, sizeof na)) 354 return (error); 355 } 356 return (mount(p, uap, retval)); 357 } 358 359 #if defined(NFSCLIENT) 360 async_daemon(p, uap, retval) 361 struct proc *p; 362 void *uap; 363 register_t *retval; 364 { 365 struct nfssvc_args { 366 int flag; 367 caddr_t argp; 368 } args; 369 370 args.flag = NFSSVC_BIOD; 371 return nfssvc(p, &args, retval); 372 } 373 #endif /* NFSCLIENT */ 374 375 struct sun_sigpending_args { 376 int *mask; 377 }; 378 sun_sigpending(p, uap, retval) 379 struct proc *p; 380 struct sun_sigpending_args *uap; 381 register_t *retval; 382 { 383 int mask = p->p_siglist & p->p_sigmask; 384 385 return (copyout((caddr_t)&mask, (caddr_t)uap->mask, sizeof(int))); 386 } 387 388 #if 0 389 /* XXX: Temporary until sys/dir.h, include/dirent.h and sys/dirent.h are fixed */ 390 struct dirent { 391 u_long d_fileno; /* file number of entry */ 392 u_short d_reclen; /* length of this record */ 393 u_short d_namlen; /* length of string in d_name */ 394 char d_name[255 + 1]; /* name must be no longer than this */ 395 }; 396 #endif 397 398 /* 399 * Here is the sun layout. (Compare the BSD layout in <sys/dirent.h>.) 400 * We can assume big-endian, so the BSD d_type field is just the high 401 * byte of the SunOS d_namlen field, after adjusting for the extra "long". 402 */ 403 struct sun_dirent { 404 long d_off; 405 u_long d_fileno; 406 u_short d_reclen; 407 u_short d_namlen; 408 char d_name[256]; 409 }; 410 411 /* 412 * Read Sun-style directory entries. We suck them into kernel space so 413 * that they can be massaged before being copied out to user code. Like 414 * SunOS, we squish out `empty' entries. 415 * 416 * This is quite ugly, but what do you expect from compatibility code? 417 */ 418 struct sun_getdents_args { 419 int fd; 420 char *buf; 421 int nbytes; 422 }; 423 sun_getdents(p, uap, retval) 424 struct proc *p; 425 register struct sun_getdents_args *uap; 426 register_t *retval; 427 { 428 register struct vnode *vp; 429 register caddr_t inp, buf; /* BSD-format */ 430 register int len, reclen; /* BSD-format */ 431 register caddr_t outp; /* Sun-format */ 432 register int resid; /* Sun-format */ 433 struct file *fp; 434 struct uio auio; 435 struct iovec aiov; 436 off_t off; /* true file offset */ 437 long soff; /* Sun file offset */ 438 int buflen, error, eofflag; 439 #define BSD_DIRENT(cp) ((struct dirent *)(cp)) 440 #define SUN_RECLEN(reclen) (reclen + sizeof(long)) 441 442 if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0) 443 return (error); 444 if ((fp->f_flag & FREAD) == 0) 445 return (EBADF); 446 vp = (struct vnode *)fp->f_data; 447 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */ 448 return (EINVAL); 449 buflen = min(MAXBSIZE, uap->nbytes); 450 buf = malloc(buflen, M_TEMP, M_WAITOK); 451 VOP_LOCK(vp); 452 off = fp->f_offset; 453 again: 454 aiov.iov_base = buf; 455 aiov.iov_len = buflen; 456 auio.uio_iov = &aiov; 457 auio.uio_iovcnt = 1; 458 auio.uio_rw = UIO_READ; 459 auio.uio_segflg = UIO_SYSSPACE; 460 auio.uio_procp = p; 461 auio.uio_resid = buflen; 462 auio.uio_offset = off; 463 /* 464 * First we read into the malloc'ed buffer, then 465 * we massage it into user space, one record at a time. 466 */ 467 if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, (u_long *)0, 468 0)) 469 goto out; 470 inp = buf; 471 outp = uap->buf; 472 resid = uap->nbytes; 473 if ((len = buflen - auio.uio_resid) == 0) 474 goto eof; 475 for (; len > 0; len -= reclen) { 476 reclen = ((struct dirent *)inp)->d_reclen; 477 if (reclen & 3) 478 panic("sun_getdents"); 479 off += reclen; /* each entry points to next */ 480 if (BSD_DIRENT(inp)->d_fileno == 0) { 481 inp += reclen; /* it is a hole; squish it out */ 482 continue; 483 } 484 if (reclen > len || resid < SUN_RECLEN(reclen)) { 485 /* entry too big for buffer, so just stop */ 486 outp++; 487 break; 488 } 489 /* 490 * Massage in place to make a Sun-shaped dirent (otherwise 491 * we have to worry about touching user memory outside of 492 * the copyout() call). 493 */ 494 BSD_DIRENT(inp)->d_reclen = SUN_RECLEN(reclen); 495 #if notdef 496 BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */ 497 #endif 498 soff = off; 499 if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 || 500 (error = copyout(inp, outp + sizeof soff, reclen)) != 0) 501 goto out; 502 /* advance past this real entry */ 503 inp += reclen; 504 /* advance output past Sun-shaped entry */ 505 outp += SUN_RECLEN(reclen); 506 resid -= SUN_RECLEN(reclen); 507 } 508 /* if we squished out the whole block, try again */ 509 if (outp == uap->buf) 510 goto again; 511 fp->f_offset = off; /* update the vnode offset */ 512 eof: 513 *retval = uap->nbytes - resid; 514 out: 515 VOP_UNLOCK(vp); 516 free(buf, M_TEMP); 517 return (error); 518 } 519 520 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */ 521 522 struct sun_mmap_args { 523 caddr_t addr; 524 size_t len; 525 int prot; 526 int flags; 527 int fd; 528 long off; /* not off_t! */ 529 off_t qoff; /* created here and fed to mmap() */ 530 }; 531 sun_mmap(p, uap, retval) 532 register struct proc *p; 533 register struct sun_mmap_args *uap; 534 register_t *retval; 535 { 536 register struct filedesc *fdp; 537 register struct file *fp; 538 register struct vnode *vp; 539 540 /* 541 * Verify the arguments. 542 */ 543 if (uap->prot & ~(PROT_READ|PROT_WRITE|PROT_EXEC)) 544 return (EINVAL); /* XXX still needed? */ 545 546 if ((uap->flags & SUN__MAP_NEW) == 0) 547 return (EINVAL); 548 uap->flags &= ~SUN__MAP_NEW; 549 550 if ((uap->flags & MAP_FIXED) == 0 && 551 uap->addr != 0 && 552 uap->addr < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ)) 553 uap->addr = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ); 554 555 /* 556 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX) 557 */ 558 fdp = p->p_fd; 559 if ((unsigned)uap->fd < fdp->fd_nfiles && /*XXX*/ 560 (fp = fdp->fd_ofiles[uap->fd]) != NULL && /*XXX*/ 561 fp->f_type == DTYPE_VNODE && /*XXX*/ 562 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/ 563 iszerodev(vp->v_rdev)) { /*XXX*/ 564 uap->flags |= MAP_ANON; 565 uap->fd = -1; 566 } 567 568 uap->qoff = uap->off; 569 return (mmap(p, uap, retval)); 570 } 571 572 #define MC_SYNC 1 573 #define MC_LOCK 2 574 #define MC_UNLOCK 3 575 #define MC_ADVISE 4 576 #define MC_LOCKAS 5 577 #define MC_UNLOCKAS 6 578 579 struct sun_mctl_args { 580 caddr_t addr; 581 size_t len; 582 int func; 583 void *arg; 584 }; 585 sun_mctl(p, uap, retval) 586 register struct proc *p; 587 register struct sun_mctl_args *uap; 588 register_t *retval; 589 { 590 591 switch (uap->func) { 592 593 case MC_ADVISE: /* ignore for now */ 594 return (0); 595 596 case MC_SYNC: /* translate to msync */ 597 return (msync(p, uap, retval)); 598 599 default: 600 return (EINVAL); 601 } 602 } 603 604 struct sun_setsockopt_args { 605 int s; 606 int level; 607 int name; 608 caddr_t val; 609 int valsize; 610 }; 611 sun_setsockopt(p, uap, retval) 612 struct proc *p; 613 register struct sun_setsockopt_args *uap; 614 register_t *retval; 615 { 616 struct file *fp; 617 struct mbuf *m = NULL; 618 int error; 619 620 if (error = getsock(p->p_fd, uap->s, &fp)) 621 return (error); 622 #define SO_DONTLINGER (~SO_LINGER) 623 if (uap->name == SO_DONTLINGER) { 624 m = m_get(M_WAIT, MT_SOOPTS); 625 if (m == NULL) 626 return (ENOBUFS); 627 mtod(m, struct linger *)->l_onoff = 0; 628 m->m_len = sizeof(struct linger); 629 return (sosetopt((struct socket *)fp->f_data, uap->level, 630 SO_LINGER, m)); 631 } 632 if (uap->valsize > MLEN) 633 return (EINVAL); 634 if (uap->val) { 635 m = m_get(M_WAIT, MT_SOOPTS); 636 if (m == NULL) 637 return (ENOBUFS); 638 if (error = copyin(uap->val, mtod(m, caddr_t), 639 (u_int)uap->valsize)) { 640 (void) m_free(m); 641 return (error); 642 } 643 m->m_len = uap->valsize; 644 } 645 return (sosetopt((struct socket *)fp->f_data, uap->level, 646 uap->name, m)); 647 } 648 649 struct sun_fchroot_args { 650 int fdes; 651 }; 652 sun_fchroot(p, uap, retval) 653 register struct proc *p; 654 register struct sun_fchroot_args *uap; 655 register_t *retval; 656 { 657 register struct filedesc *fdp = p->p_fd; 658 register struct vnode *vp; 659 struct file *fp; 660 int error; 661 662 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) 663 return (error); 664 if ((error = getvnode(fdp, uap->fdes, &fp)) != 0) 665 return (error); 666 vp = (struct vnode *)fp->f_data; 667 VOP_LOCK(vp); 668 if (vp->v_type != VDIR) 669 error = ENOTDIR; 670 else 671 error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p); 672 VOP_UNLOCK(vp); 673 if (error) 674 return (error); 675 VREF(vp); 676 if (fdp->fd_rdir != NULL) 677 vrele(fdp->fd_rdir); 678 fdp->fd_rdir = vp; 679 return (0); 680 } 681 682 /* 683 * XXX: This needs cleaning up. 684 */ 685 sun_auditsys() 686 { 687 return 0; 688 } 689 690 struct sun_utsname { 691 char sysname[9]; 692 char nodename[9]; 693 char nodeext[65-9]; 694 char release[9]; 695 char version[9]; 696 char machine[9]; 697 }; 698 699 struct sun_uname_args { 700 struct sun_utsname *name; 701 }; 702 sun_uname(p, uap, retval) 703 struct proc *p; 704 struct sun_uname_args *uap; 705 register_t *retval; 706 { 707 struct sun_utsname sut; 708 extern char ostype[], machine[], osrelease[]; 709 710 bzero(&sut, sizeof(sut)); 711 712 bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1); 713 bcopy(hostname, sut.nodename, sizeof(sut.nodename)); 714 sut.nodename[sizeof(sut.nodename)-1] = '\0'; 715 bcopy(osrelease, sut.release, sizeof(sut.release) - 1); 716 bcopy("1", sut.version, sizeof(sut.version) - 1); 717 bcopy(machine, sut.machine, sizeof(sut.machine) - 1); 718 719 return copyout((caddr_t)&sut, (caddr_t)uap->name, sizeof(struct sun_utsname)); 720 } 721 722 struct sun_setpgid_args { 723 int pid; /* target process id */ 724 int pgid; /* target pgrp id */ 725 }; 726 int 727 sun_setpgid(p, uap, retval) 728 struct proc *p; 729 struct sun_setpgid_args *uap; 730 register_t *retval; 731 { 732 /* 733 * difference to our setpgid call is to include backwards 734 * compatibility to pre-setsid() binaries. Do setsid() 735 * instead of setpgid() in those cases where the process 736 * tries to create a new session the old way. 737 */ 738 if (!uap->pgid && (!uap->pid || uap->pid == p->p_pid)) 739 return setsid(p, uap, retval); 740 else 741 return setpgid(p, uap, retval); 742 } 743 744 struct sun_open_args { 745 char *fname; 746 int fmode; 747 int crtmode; 748 }; 749 sun_open(p, uap, retval) 750 struct proc *p; 751 struct sun_open_args *uap; 752 register_t *retval; 753 { 754 int l, r; 755 int noctty = uap->fmode & 0x8000; 756 int ret; 757 758 /* convert mode into NetBSD mode */ 759 l = uap->fmode; 760 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800)); 761 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0); 762 r |= ((l & 0x0080) ? O_SHLOCK : 0); 763 r |= ((l & 0x0100) ? O_EXLOCK : 0); 764 r |= ((l & 0x2000) ? O_FSYNC : 0); 765 766 uap->fmode = r; 767 ret = open(p, uap, retval); 768 769 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) { 770 struct filedesc *fdp = p->p_fd; 771 struct file *fp = fdp->fd_ofiles[*retval]; 772 773 /* ignore any error, just give it a try */ 774 if (fp->f_type == DTYPE_VNODE) 775 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p); 776 } 777 return ret; 778 } 779 780 #if defined (NFSSERVER) 781 struct nfssvc_args { 782 int fd; 783 caddr_t mskval; 784 int msklen; 785 caddr_t mtchval; 786 int mtchlen; 787 }; 788 struct sun_nfssvc_args { 789 int fd; 790 }; 791 sun_nfssvc(p, uap, retval) 792 struct proc *p; 793 struct sun_nfssvc_args *uap; 794 register_t *retval; 795 { 796 struct nfssvc_args outuap; 797 struct sockaddr sa; 798 int error; 799 extern char sigcode[], esigcode[]; 800 801 bzero(&outuap, sizeof outuap); 802 outuap.fd = uap->fd; 803 outuap.mskval = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN); 804 outuap.msklen = sizeof sa; 805 outuap.mtchval = outuap.mskval + sizeof sa; 806 outuap.mtchlen = sizeof sa; 807 808 bzero(&sa, sizeof sa); 809 if (error = copyout(&sa, outuap.mskval, outuap.msklen)) 810 return (error); 811 if (error = copyout(&sa, outuap.mtchval, outuap.mtchlen)) 812 return (error); 813 814 return nfssvc(p, &outuap, retval); 815 } 816 #endif /* NFSSERVER */ 817 818 struct sun_ustat { 819 daddr_t f_tfree; /* total free */ 820 ino_t f_tinode; /* total inodes free */ 821 char f_fname[6]; /* filsys name */ 822 char f_fpack[6]; /* filsys pack name */ 823 }; 824 struct sun_ustat_args { 825 int dev; 826 struct sun_ustat *buf; 827 }; 828 sun_ustat(p, uap, retval) 829 struct proc *p; 830 struct sun_ustat_args *uap; 831 register_t *retval; 832 { 833 struct sun_ustat us; 834 int error; 835 836 bzero(&us, sizeof us); 837 838 /* 839 * XXX: should set f_tfree and f_tinode at least 840 * How do we translate dev -> fstat? (and then to sun_ustat) 841 */ 842 843 if (error = copyout(&us, uap->buf, sizeof us)) 844 return (error); 845 return 0; 846 } 847 848 struct sun_quotactl_args { 849 int cmd; 850 char *special; 851 int uid; 852 caddr_t addr; 853 }; 854 sun_quotactl(p, uap, retval) 855 struct proc *p; 856 struct sun_quotactl_args *uap; 857 register_t *retval; 858 { 859 return EINVAL; 860 } 861 862 sun_vhangup(p, uap, retval) 863 struct proc *p; 864 void *uap; 865 register_t *retval; 866 { 867 return 0; 868 } 869 870 struct sun_statfs { 871 long f_type; /* type of info, zero for now */ 872 long f_bsize; /* fundamental file system block size */ 873 long f_blocks; /* total blocks in file system */ 874 long f_bfree; /* free blocks */ 875 long f_bavail; /* free blocks available to non-super-user */ 876 long f_files; /* total file nodes in file system */ 877 long f_ffree; /* free file nodes in fs */ 878 fsid_t f_fsid; /* file system id */ 879 long f_spare[7]; /* spare for later */ 880 }; 881 static 882 sunstatfs(sp, buf) 883 struct statfs *sp; 884 caddr_t buf; 885 { 886 struct sun_statfs ssfs; 887 888 bzero(&ssfs, sizeof ssfs); 889 ssfs.f_type = 0; 890 ssfs.f_bsize = sp->f_bsize; 891 ssfs.f_blocks = sp->f_blocks; 892 ssfs.f_bfree = sp->f_bfree; 893 ssfs.f_bavail = sp->f_bavail; 894 ssfs.f_files = sp->f_files; 895 ssfs.f_ffree = sp->f_ffree; 896 ssfs.f_fsid = sp->f_fsid; 897 return copyout((caddr_t)&ssfs, buf, sizeof ssfs); 898 } 899 900 struct sun_statfs_args { 901 char *path; 902 struct sun_statfs *buf; 903 }; 904 sun_statfs(p, uap, retval) 905 struct proc *p; 906 struct sun_statfs_args *uap; 907 register_t *retval; 908 { 909 register struct mount *mp; 910 register struct statfs *sp; 911 int error; 912 struct nameidata nd; 913 914 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p); 915 if (error = namei(&nd)) 916 return (error); 917 mp = nd.ni_vp->v_mount; 918 sp = &mp->mnt_stat; 919 vrele(nd.ni_vp); 920 if (error = VFS_STATFS(mp, sp, p)) 921 return (error); 922 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; 923 return sunstatfs(sp, (caddr_t)uap->buf); 924 } 925 926 struct sun_fstatfs_args { 927 int fd; 928 struct sun_statfs *buf; 929 }; 930 sun_fstatfs(p, uap, retval) 931 struct proc *p; 932 struct sun_fstatfs_args *uap; 933 register_t *retval; 934 { 935 struct file *fp; 936 struct mount *mp; 937 register struct statfs *sp; 938 int error; 939 940 if (error = getvnode(p->p_fd, uap->fd, &fp)) 941 return (error); 942 mp = ((struct vnode *)fp->f_data)->v_mount; 943 sp = &mp->mnt_stat; 944 if (error = VFS_STATFS(mp, sp, p)) 945 return (error); 946 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK; 947 return sunstatfs(sp, (caddr_t)uap->buf); 948 } 949 950 struct sun_exportfs_args { 951 char *path; 952 char *ex; /* struct sun_export * */ 953 }; 954 sun_exportfs(p, uap, retval) 955 struct proc *p; 956 struct sun_exportfs_args *uap; 957 register_t *retval; 958 { 959 /* 960 * XXX: should perhaps translate into a mount(2) 961 * with MOUNT_EXPORT? 962 */ 963 return 0; 964 } 965 966 struct sun_mknod_args { 967 char *fname; 968 int fmode; 969 int dev; 970 }; 971 972 sun_mknod(p, uap, retval) 973 struct proc *p; 974 struct sun_mknod_args *uap; 975 register_t *retval; 976 { 977 if (S_ISFIFO(uap->fmode)) 978 return mkfifo(p, uap, retval); 979 980 return mknod(p, uap, retval); 981 } 982 983 #define SUN_SC_ARG_MAX 1 984 #define SUN_SC_CHILD_MAX 2 985 #define SUN_SC_CLK_TCK 3 986 #define SUN_SC_NGROUPS_MAX 4 987 #define SUN_SC_OPEN_MAX 5 988 #define SUN_SC_JOB_CONTROL 6 989 #define SUN_SC_SAVED_IDS 7 990 #define SUN_SC_VERSION 8 991 992 struct sun_sysconf_args { 993 int name; 994 }; 995 996 sun_sysconf(p, uap, retval) 997 struct proc *p; 998 struct sun_sysconf_args *uap; 999 register_t *retval; 1000 { 1001 extern int maxfiles; 1002 1003 switch(uap->name) { 1004 case SUN_SC_ARG_MAX: 1005 *retval = ARG_MAX; 1006 break; 1007 case SUN_SC_CHILD_MAX: 1008 *retval = maxproc; 1009 break; 1010 case SUN_SC_CLK_TCK: 1011 *retval = 60; /* should this be `hz', ie. 100? */ 1012 break; 1013 case SUN_SC_NGROUPS_MAX: 1014 *retval = NGROUPS_MAX; 1015 break; 1016 case SUN_SC_OPEN_MAX: 1017 *retval = maxfiles; 1018 break; 1019 case SUN_SC_JOB_CONTROL: 1020 *retval = 1; 1021 break; 1022 case SUN_SC_SAVED_IDS: 1023 #ifdef _POSIX_SAVED_IDS 1024 *retval = 1; 1025 #else 1026 *retval = 0; 1027 #endif 1028 break; 1029 case SUN_SC_VERSION: 1030 *retval = 198808; 1031 break; 1032 default: 1033 return EINVAL; 1034 } 1035 return 0; 1036 } 1037