[BACK]Return to ultrix_pathname.c CVS log [TXT][DIR] Up to [local] / sys / compat / ultrix

Annotation of sys/compat/ultrix/ultrix_pathname.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: ultrix_pathname.c,v 1.9 2003/06/02 23:28:01 millert Exp $     */
        !             2: /*     $NetBSD: ultrix_pathname.c,v 1.2 1996/04/07 17:23:07 jonathan Exp $     */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1992, 1993
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             7:  *
        !             8:  * This software was developed by the Computer Systems Engineering group
        !             9:  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
        !            10:  * contributed to Berkeley.
        !            11:  *
        !            12:  * All advertising materials mentioning features or use of this software
        !            13:  * must display the following acknowledgement:
        !            14:  *     This product includes software developed by the University of
        !            15:  *     California, Lawrence Berkeley Laboratory.
        !            16:  *
        !            17:  * Redistribution and use in source and binary forms, with or without
        !            18:  * modification, are permitted provided that the following conditions
        !            19:  * are met:
        !            20:  * 1. Redistributions of source code must retain the above copyright
        !            21:  *    notice, this list of conditions and the following disclaimer.
        !            22:  * 2. Redistributions in binary form must reproduce the above copyright
        !            23:  *    notice, this list of conditions and the following disclaimer in the
        !            24:  *    documentation and/or other materials provided with the distribution.
        !            25:  * 3. Neither the name of the University nor the names of its contributors
        !            26:  *    may be used to endorse or promote products derived from this software
        !            27:  *    without specific prior written permission.
        !            28:  *
        !            29:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            30:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            31:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            32:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            33:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            34:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            35:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            36:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            37:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            38:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            39:  * SUCH DAMAGE.
        !            40:  *
        !            41:  *
        !            42:  *     @(#)sun_misc.c  8.1 (Berkeley) 6/18/93
        !            43:  *
        !            44:  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
        !            45:  */
        !            46:
        !            47:
        !            48: /*
        !            49:  * Ultrix emulation filesystem-namespace compatibility module.
        !            50:  *
        !            51:  * Ultrix system calls that examine the filesysten namespace
        !            52:  * are implemented here.  Each system call has a wrapper that
        !            53:  * first checks if the given file exists at a special `emulation'
        !            54:  * pathname: the given path, prefixex with '/emul/ultrix', and
        !            55:  * if that pathname exists, it is used instead of the providd pathname.
        !            56:  *
        !            57:  * Used to locate OS-specific files (shared libraries, config files,
        !            58:  * etc) used by emul processes at their `normal' pathnames, without
        !            59:  * polluting, or conflicting with, the native filesysten namespace.
        !            60:  */
        !            61:
        !            62: #include <sys/param.h>
        !            63: #include <sys/systm.h>
        !            64: #include <sys/namei.h>
        !            65: #include <sys/file.h>
        !            66: #include <sys/filedesc.h>
        !            67: #include <sys/ioctl.h>
        !            68: #include <sys/mount.h>
        !            69: #include <sys/stat.h>
        !            70: #include <sys/vnode.h>
        !            71: #include <sys/syscallargs.h>
        !            72:
        !            73: #include <compat/ultrix/ultrix_syscallargs.h>
        !            74: #include <compat/ultrix/ultrix_util.h>
        !            75:
        !            76: const char ultrix_emul_path[] = "/emul/ultrix";
        !            77:
        !            78: int
        !            79: ultrix_sys_creat(p, v, retval)
        !            80:        struct proc *p;
        !            81:        void *v;
        !            82:        register_t *retval;
        !            83: {
        !            84:        struct ultrix_sys_creat_args *uap = v;
        !            85:        struct sys_open_args ouap;
        !            86:
        !            87:        caddr_t sg = stackgap_init(p->p_emul);
        !            88:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !            89:
        !            90:        SCARG(&ouap, path) = SCARG(uap, path);
        !            91:        SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
        !            92:        SCARG(&ouap, mode) = SCARG(uap, mode);
        !            93:
        !            94:        return (sys_open(p, &ouap, retval));
        !            95: }
        !            96:
        !            97:
        !            98: int
        !            99: ultrix_sys_access(p, v, retval)
        !           100:        struct proc *p;
        !           101:        void *v;
        !           102:        register_t *retval;
        !           103: {
        !           104:        struct ultrix_sys_access_args *uap = v;
        !           105:        caddr_t sg = stackgap_init(p->p_emul);
        !           106:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           107:
        !           108:        return (sys_access(p, uap, retval));
        !           109: }
        !           110:
        !           111: int
        !           112: ultrix_sys_stat(p, v, retval)
        !           113:        struct proc *p;
        !           114:        void *v;
        !           115:        register_t *retval;
        !           116: {
        !           117:        struct ultrix_sys_stat_args *uap = v;
        !           118:        caddr_t sg = stackgap_init(p->p_emul);
        !           119:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           120:
        !           121:        return (compat_43_sys_stat(p, uap, retval));
        !           122: }
        !           123:
        !           124: int
        !           125: ultrix_sys_lstat(p, v, retval)
        !           126:        struct proc *p;
        !           127:        void *v;
        !           128:        register_t *retval;
        !           129: {
        !           130:        struct ultrix_sys_lstat_args *uap = v;
        !           131:        caddr_t sg = stackgap_init(p->p_emul);
        !           132:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           133:
        !           134:        return (compat_43_sys_lstat(p, uap, retval));
        !           135: }
        !           136:
        !           137: int
        !           138: ultrix_sys_execv(p, v, retval)
        !           139:        struct proc *p;
        !           140:        void *v;
        !           141:        register_t *retval;
        !           142: {
        !           143:        struct ultrix_sys_execv_args *uap = v;
        !           144:        struct sys_execve_args ouap;
        !           145:
        !           146:        caddr_t sg = stackgap_init(p->p_emul);
        !           147:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           148:
        !           149:        SCARG(&ouap, path) = SCARG(uap, path);
        !           150:        SCARG(&ouap, argp) = SCARG(uap, argp);
        !           151:        SCARG(&ouap, envp) = NULL;
        !           152:
        !           153:        return (sys_execve(p, &ouap, retval));
        !           154: }
        !           155:
        !           156: int
        !           157: ultrix_sys_open(p, v, retval)
        !           158:        struct proc *p;
        !           159:        void *v;
        !           160:        register_t *retval;
        !           161: {
        !           162:        struct ultrix_sys_open_args *uap = v;
        !           163:        int l, r;
        !           164:        int noctty;
        !           165:        int ret;
        !           166:
        !           167:        caddr_t sg = stackgap_init(p->p_emul);
        !           168:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           169:
        !           170:        /* convert open flags into NetBSD flags */
        !           171:        l = SCARG(uap, flags);
        !           172:        noctty = l & 0x8000;
        !           173:        r =     (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
        !           174:        r |=    ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
        !           175:        r |=    ((l & 0x0080) ? O_SHLOCK : 0);
        !           176:        r |=    ((l & 0x0100) ? O_EXLOCK : 0);
        !           177:        r |=    ((l & 0x2000) ? O_SYNC : 0);
        !           178:
        !           179:        SCARG(uap, flags) = r;
        !           180:        ret = sys_open(p, (struct sys_open_args *)uap, retval);
        !           181:
        !           182:        if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
        !           183:                struct filedesc *fdp = p->p_fd;
        !           184:                struct file *fp;
        !           185:
        !           186:                if ((fd = fd_getfile(fdp, *retval)) == NULL)
        !           187:                        return (EBADF);
        !           188:                FREF(fp);
        !           189:                /* ignore any error, just give it a try */
        !           190:                if (fp->f_type == DTYPE_VNODE)
        !           191:                        (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
        !           192:                FRELE(fp);
        !           193:        }
        !           194:        return ret;
        !           195: }
        !           196:
        !           197:
        !           198: struct ultrix_statfs {
        !           199:        long    f_type;         /* type of info, zero for now */
        !           200:        long    f_bsize;        /* fundamental file system block size */
        !           201:        long    f_blocks;       /* total blocks in file system */
        !           202:        long    f_bfree;        /* free blocks */
        !           203:        long    f_bavail;       /* free blocks available to non-super-user */
        !           204:        long    f_files;        /* total file nodes in file system */
        !           205:        long    f_ffree;        /* free file nodes in fs */
        !           206:        fsid_t  f_fsid;         /* file system id */
        !           207:        long    f_spare[7];     /* spare for later */
        !           208: };
        !           209:
        !           210: /*
        !           211:  * Custruct ultrix statfs result from native.
        !           212:  * XXX should this be the same as returned by Ultrix getmnt(2)?
        !           213:  * XXX Ultrix predates DEV_BSIZE.  Is  conversion of disk space from 1k
        !           214:  *  block units to DEV_BSIZE necessary?
        !           215:  */
        !           216: static int
        !           217: ultrixstatfs(sp, buf)
        !           218:        struct statfs *sp;
        !           219:        caddr_t buf;
        !           220: {
        !           221:        struct ultrix_statfs ssfs;
        !           222:
        !           223:        bzero(&ssfs, sizeof ssfs);
        !           224:        ssfs.f_type = 0;
        !           225:        ssfs.f_bsize = sp->f_bsize;
        !           226:        ssfs.f_blocks = sp->f_blocks;
        !           227:        ssfs.f_bfree = sp->f_bfree;
        !           228:        ssfs.f_bavail = sp->f_bavail;
        !           229:        ssfs.f_files = sp->f_files;
        !           230:        ssfs.f_ffree = sp->f_ffree;
        !           231:        ssfs.f_fsid = sp->f_fsid;
        !           232:        return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
        !           233: }
        !           234:
        !           235:
        !           236: int
        !           237: ultrix_sys_statfs(p, v, retval)
        !           238:        struct proc *p;
        !           239:        void *v;
        !           240:        register_t *retval;
        !           241: {
        !           242:        struct ultrix_sys_statfs_args *uap = v;
        !           243:        register struct mount *mp;
        !           244:        register struct statfs *sp;
        !           245:        int error;
        !           246:        struct nameidata nd;
        !           247:
        !           248:        caddr_t sg = stackgap_init(p->p_emul);
        !           249:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           250:
        !           251:        NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
        !           252:        if ((error = namei(&nd)) != 0)
        !           253:                return (error);
        !           254:
        !           255:        mp = nd.ni_vp->v_mount;
        !           256:        sp = &mp->mnt_stat;
        !           257:        vrele(nd.ni_vp);
        !           258:        if ((error = VFS_STATFS(mp, sp, p)) != 0)
        !           259:                return (error);
        !           260:        sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
        !           261:        return ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
        !           262: }
        !           263:
        !           264: /*
        !           265:  * sys_fstatfs() takes an fd, not a path, and so needs no emul
        !           266:  * pathname processing;  but it's similar enough to sys_statfs() that
        !           267:  * it goes here anyway.
        !           268:  */
        !           269: int
        !           270: ultrix_sys_fstatfs(p, v, retval)
        !           271:        struct proc *p;
        !           272:        void *v;
        !           273:        register_t *retval;
        !           274: {
        !           275:        struct ultrix_sys_fstatfs_args *uap = v;
        !           276:        struct file *fp;
        !           277:        struct mount *mp;
        !           278:        register struct statfs *sp;
        !           279:        int error;
        !           280:
        !           281:        if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
        !           282:                return (error);
        !           283:
        !           284:        mp = ((struct vnode *)fp->f_data)->v_mount;
        !           285:        sp = &mp->mnt_stat;
        !           286:        error = VFS_STATFS(mp, sp, p);
        !           287:        FRELE(fp);
        !           288:        if (error)
        !           289:                return (error);
        !           290:        sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
        !           291:        return ultrixstatfs(sp, (caddr_t)SCARG(uap, buf));
        !           292: }
        !           293:
        !           294: int
        !           295: ultrix_sys_mknod(p, v, retval)
        !           296:        struct proc *p;
        !           297:        void *v;
        !           298:        register_t *retval;
        !           299: {
        !           300:        struct ultrix_sys_mknod_args *uap = v;
        !           301:
        !           302:        caddr_t sg = stackgap_init(p->p_emul);
        !           303:        ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
        !           304:
        !           305:        if (S_ISFIFO(SCARG(uap, mode)))
        !           306:                return sys_mkfifo(p, uap, retval);
        !           307:
        !           308:        return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
        !           309: }

CVSweb