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