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