The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/ultrix/ultrix_pathname.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ultrix_pathname.c,v 1.35 2008/06/24 11:18:15 ad 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. Neither the name of the University nor the names of its contributors
   25  *    may be used to endorse or promote products derived from this software
   26  *    without specific prior written permission.
   27  *
   28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   38  * SUCH DAMAGE.
   39  *
   40  *
   41  *      @(#)sun_misc.c  8.1 (Berkeley) 6/18/93
   42  *
   43  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
   44  */
   45 
   46 
   47 /*
   48  * Ultrix emulation filesystem-namespace compatibility module.
   49  *
   50  * Ultrix system calls that examine the filesysten namespace
   51  * are implemented here.  Each system call has a wrapper that
   52  * first checks if the given file exists at a special `emulation'
   53  * pathname: the given path, prefixex with '/emul/ultrix', and
   54  * if that pathname exists, it is used instead of the providd pathname.
   55  *
   56  * Used to locate OS-specific files (shared libraries, config files,
   57  * etc) used by emul processes at their `normal' pathnames, without
   58  * polluting, or conflicting with, the native filesysten namespace.
   59  */
   60 
   61 #include <sys/cdefs.h>
   62 __KERNEL_RCSID(0, "$NetBSD: ultrix_pathname.c,v 1.35 2008/06/24 11:18:15 ad Exp $");
   63 
   64 #include <sys/param.h>
   65 #include <sys/systm.h>
   66 #include <sys/namei.h>
   67 #include <sys/file.h>
   68 #include <sys/filedesc.h>
   69 #include <sys/ioctl.h>
   70 #include <sys/mount.h>
   71 #include <sys/stat.h>
   72 #include <sys/vnode.h>
   73 #include <sys/syscallargs.h>
   74 #include <sys/proc.h>
   75 
   76 #include <compat/ultrix/ultrix_syscallargs.h>
   77 #include <compat/common/compat_util.h>
   78 
   79 static int ultrixstatfs(struct statvfs *, void *);
   80 
   81 int
   82 ultrix_sys_creat(struct lwp *l, const struct ultrix_sys_creat_args *uap, register_t *retval)
   83 {
   84         struct sys_open_args ap;
   85 
   86         SCARG(&ap, path) = SCARG(uap, path);
   87         SCARG(&ap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
   88         SCARG(&ap, mode) = SCARG(uap, mode);
   89 
   90         return sys_open(l, &ap, retval);
   91 }
   92 
   93 
   94 int
   95 ultrix_sys_access(struct lwp *l, const struct ultrix_sys_access_args *uap, register_t *retval)
   96 {
   97 
   98         return sys_access(l, (const struct sys_access_args *)uap, retval);
   99 }
  100 
  101 int
  102 ultrix_sys_stat(struct lwp *l, const struct ultrix_sys_stat_args *uap, register_t *retval)
  103 {
  104 
  105         return compat_43_sys_stat(l,
  106             (const struct compat_43_sys_stat_args *)uap, retval);
  107 }
  108 
  109 int
  110 ultrix_sys_lstat(struct lwp *l, const struct ultrix_sys_lstat_args *uap, register_t *retval)
  111 {
  112 
  113         return compat_43_sys_lstat(l,
  114             (const struct compat_43_sys_lstat_args *)uap, retval);
  115 }
  116 
  117 int
  118 ultrix_sys_execv(struct lwp *l, const struct ultrix_sys_execv_args *uap, register_t *retval)
  119 {
  120         /* {
  121                 syscallarg(const char *) path;
  122                 syscallarg(char **) argv;
  123         } */
  124         struct sys_execve_args ap;
  125 
  126         SCARG(&ap, path) = SCARG(uap, path);
  127         SCARG(&ap, argp) = SCARG(uap, argp);
  128         SCARG(&ap, envp) = NULL;
  129 
  130         return sys_execve(l, &ap, retval);
  131 }
  132 
  133 int
  134 ultrix_sys_execve(struct lwp *l, const struct ultrix_sys_execve_args *uap, register_t *retval)
  135 {
  136         /* {
  137                 syscallarg(const char *) path;
  138                 syscallarg(char **) argv;
  139                 syscallarg(char **) envp;
  140         } */
  141         struct sys_execve_args ap;
  142 
  143         SCARG(&ap, path) = SCARG(uap, path);
  144         SCARG(&ap, argp) = SCARG(uap, argp);
  145         SCARG(&ap, envp) = SCARG(uap, envp);
  146 
  147         return sys_execve(l, &ap, retval);
  148 }
  149 
  150 int
  151 ultrix_sys_open(struct lwp *l, const struct ultrix_sys_open_args *uap, register_t *retval)
  152 {
  153         struct proc *p = l->l_proc;
  154         int q, r;
  155         int noctty;
  156         int ret;
  157         struct sys_open_args ap;
  158 
  159         /* convert open flags into NetBSD flags */
  160 
  161         q = SCARG(uap, flags);
  162         noctty = q & 0x8000;
  163         r =     (q & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
  164         r |=    ((q & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
  165         r |=    ((q & 0x0080) ? O_SHLOCK : 0);
  166         r |=    ((q & 0x0100) ? O_EXLOCK : 0);
  167         r |=    ((q & 0x2000) ? O_FSYNC : 0);
  168 
  169         SCARG(&ap, path) = SCARG(uap, path);
  170         SCARG(&ap, flags) = r;
  171         SCARG(&ap, mode) = SCARG(uap, mode);
  172         ret = sys_open(l, &ap, retval);
  173 
  174         /* XXXSMP */
  175         if (!ret && !noctty && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
  176                 file_t *fp;
  177                 int fd;
  178 
  179                 fd = (int)*retval;
  180                 fp = fd_getfile(fd);
  181 
  182                 /* ignore any error, just give it a try */
  183                 if (fp != NULL) {
  184                         if (fp->f_type == DTYPE_VNODE)
  185                                 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, NULL);
  186                         fd_putfile(fd);
  187                 }
  188         }
  189         return ret;
  190 }
  191 
  192 
  193 struct ultrix_statfs {
  194         long    f_type;         /* type of info, zero for now */
  195         long    f_bsize;        /* fundamental file system block size */
  196         long    f_blocks;       /* total blocks in file system */
  197         long    f_bfree;        /* free blocks */
  198         long    f_bavail;       /* free blocks available to non-super-user */
  199         long    f_files;        /* total file nodes in file system */
  200         long    f_ffree;        /* free file nodes in fs */
  201         fsid_t  f_fsid;         /* file system id */
  202         long    f_spare[7];     /* spare for later */
  203 };
  204 
  205 /*
  206  * Custruct ultrix statfs result from native.
  207  * XXX should this be the same as returned by Ultrix getmnt(2)?
  208  * XXX Ultrix predates DEV_BSIZE.  Is  conversion of disk space from 1k
  209  *  block units to DEV_BSIZE necessary?
  210  */
  211 static int
  212 ultrixstatfs(struct statvfs *sp, void *buf)
  213 {
  214         struct ultrix_statfs ssfs;
  215 
  216         memset(&ssfs, 0, sizeof ssfs);
  217         ssfs.f_type = 0;
  218         ssfs.f_bsize = sp->f_bsize;
  219         ssfs.f_blocks = sp->f_blocks;
  220         ssfs.f_bfree = sp->f_bfree;
  221         ssfs.f_bavail = sp->f_bavail;
  222         ssfs.f_files = sp->f_files;
  223         ssfs.f_ffree = sp->f_ffree;
  224         ssfs.f_fsid = sp->f_fsidx;
  225         return copyout((void *)&ssfs, buf, sizeof ssfs);
  226 }
  227 
  228 
  229 int
  230 ultrix_sys_statfs(struct lwp *l, const struct ultrix_sys_statfs_args *uap, register_t *retval)
  231 {
  232         struct mount *mp;
  233         struct statvfs *sp;
  234         int error;
  235         struct nameidata nd;
  236 
  237         NDINIT(&nd, LOOKUP, FOLLOW | TRYEMULROOT, UIO_USERSPACE,
  238             SCARG(uap, path));
  239         if ((error = namei(&nd)) != 0)
  240                 return error;
  241 
  242         mp = nd.ni_vp->v_mount;
  243         sp = &mp->mnt_stat;
  244         vrele(nd.ni_vp);
  245         if ((error = VFS_STATVFS(mp, sp)) != 0)
  246                 return error;
  247         sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
  248         return ultrixstatfs(sp, (void *)SCARG(uap, buf));
  249 }
  250 
  251 /*
  252  * sys_fstatfs() takes an fd, not a path, and so needs no emul
  253  * pathname processing;  but it's similar enough to sys_statvfs() that
  254  * it goes here anyway.
  255  */
  256 int
  257 ultrix_sys_fstatfs(struct lwp *l, const struct ultrix_sys_fstatfs_args *uap, register_t *retval)
  258 {
  259         file_t *fp;
  260         struct mount *mp;
  261         struct statvfs *sp;
  262         int error;
  263 
  264         /* fd_getvnode() will use the descriptor for us */
  265         if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
  266                 return error;
  267         mp = ((struct vnode *)fp->f_data)->v_mount;
  268         sp = &mp->mnt_stat;
  269         if ((error = VFS_STATVFS(mp, sp)) != 0)
  270                 goto out;
  271         sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
  272         error = ultrixstatfs(sp, (void *)SCARG(uap, buf));
  273  out:
  274         fd_putfile(SCARG(uap, fd));
  275         return error;
  276 }
  277 
  278 int
  279 ultrix_sys_mknod(struct lwp *l, const struct ultrix_sys_mknod_args *uap, register_t *retval)
  280 {
  281 
  282         if (S_ISFIFO(SCARG(uap, mode)))
  283                 return sys_mkfifo(l, (const struct sys_mkfifo_args *)uap,
  284                     retval);
  285 
  286         return sys_mknod(l, (const struct sys_mknod_args *)uap, retval);
  287 }

Cache object: 45c1bebc7026aa4a04038d461e532755


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.