Home | History | Annotate | Line # | Download | only in common
vfs_syscalls_12.c revision 1.2
      1  1.2  christos /*	$NetBSD: vfs_syscalls_12.c,v 1.2 1997/10/16 23:50:36 christos Exp $	*/
      2  1.1      fvdl 
      3  1.1      fvdl /*
      4  1.1      fvdl  * Copyright (c) 1989, 1993
      5  1.1      fvdl  *	The Regents of the University of California.  All rights reserved.
      6  1.1      fvdl  * (c) UNIX System Laboratories, Inc.
      7  1.1      fvdl  * All or some portions of this file are derived from material licensed
      8  1.1      fvdl  * to the University of California by American Telephone and Telegraph
      9  1.1      fvdl  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     10  1.1      fvdl  * the permission of UNIX System Laboratories, Inc.
     11  1.1      fvdl  *
     12  1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     13  1.1      fvdl  * modification, are permitted provided that the following conditions
     14  1.1      fvdl  * are met:
     15  1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     16  1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     17  1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     19  1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     20  1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     21  1.1      fvdl  *    must display the following acknowledgement:
     22  1.1      fvdl  *	This product includes software developed by the University of
     23  1.1      fvdl  *	California, Berkeley and its contributors.
     24  1.1      fvdl  * 4. Neither the name of the University nor the names of its contributors
     25  1.1      fvdl  *    may be used to endorse or promote products derived from this software
     26  1.1      fvdl  *    without specific prior written permission.
     27  1.1      fvdl  *
     28  1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  1.1      fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  1.1      fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  1.1      fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  1.1      fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  1.1      fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  1.1      fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  1.1      fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  1.1      fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  1.1      fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  1.1      fvdl  * SUCH DAMAGE.
     39  1.1      fvdl  *
     40  1.1      fvdl  *	From: @(#)vfs_syscalls.c	8.28 (Berkeley) 12/10/94
     41  1.1      fvdl  */
     42  1.1      fvdl 
     43  1.1      fvdl #include <sys/param.h>
     44  1.1      fvdl #include <sys/systm.h>
     45  1.1      fvdl #include <sys/namei.h>
     46  1.1      fvdl #include <sys/filedesc.h>
     47  1.1      fvdl #include <sys/kernel.h>
     48  1.1      fvdl #include <sys/file.h>
     49  1.1      fvdl #include <sys/stat.h>
     50  1.2  christos #include <sys/socketvar.h>
     51  1.1      fvdl #include <sys/vnode.h>
     52  1.1      fvdl #include <sys/mount.h>
     53  1.1      fvdl #include <sys/proc.h>
     54  1.1      fvdl #include <sys/uio.h>
     55  1.1      fvdl #include <sys/malloc.h>
     56  1.1      fvdl #include <sys/dirent.h>
     57  1.1      fvdl 
     58  1.1      fvdl #include <sys/syscallargs.h>
     59  1.1      fvdl 
     60  1.2  christos static void cvtstat __P((struct stat *, struct stat12 *));
     61  1.2  christos 
     62  1.2  christos /*
     63  1.2  christos  * Convert from an old to a new stat structure.
     64  1.2  christos  */
     65  1.2  christos static void
     66  1.2  christos cvtstat(st, ost)
     67  1.2  christos 	struct stat *st;
     68  1.2  christos 	struct stat12 *ost;
     69  1.2  christos {
     70  1.2  christos 
     71  1.2  christos 	ost->st_dev = st->st_dev;
     72  1.2  christos 	ost->st_ino = st->st_ino;
     73  1.2  christos 	ost->st_mode = st->st_mode;
     74  1.2  christos 	ost->st_nlink = st->st_nlink;
     75  1.2  christos 	if (st->st_nlink >= (1 << 15))
     76  1.2  christos 		ost->st_nlink = (1 << 15) - 1;
     77  1.2  christos 	else
     78  1.2  christos 		ost->st_nlink = st->st_nlink;
     79  1.2  christos 	ost->st_uid = st->st_uid;
     80  1.2  christos 	ost->st_gid = st->st_gid;
     81  1.2  christos 	ost->st_rdev = st->st_rdev;
     82  1.2  christos 	ost->st_size = st->st_size;
     83  1.2  christos 	ost->st_atime = st->st_atime;
     84  1.2  christos 	ost->st_mtime = st->st_mtime;
     85  1.2  christos 	ost->st_ctime = st->st_ctime;
     86  1.2  christos 	ost->st_blksize = st->st_blksize;
     87  1.2  christos 	ost->st_blocks = st->st_blocks;
     88  1.2  christos 	ost->st_flags = st->st_flags;
     89  1.2  christos 	ost->st_gen = st->st_gen;
     90  1.2  christos }
     91  1.1      fvdl /*
     92  1.1      fvdl  * Read a block of directory entries in a file system independent format.
     93  1.1      fvdl  */
     94  1.1      fvdl int
     95  1.1      fvdl compat_12_sys_getdirentries(p, v, retval)
     96  1.1      fvdl 	struct proc *p;
     97  1.1      fvdl 	void *v;
     98  1.1      fvdl 	register_t *retval;
     99  1.1      fvdl {
    100  1.1      fvdl 	register struct compat_12_sys_getdirentries_args /* {
    101  1.1      fvdl 		syscallarg(int) fd;
    102  1.1      fvdl 		syscallarg(char *) buf;
    103  1.1      fvdl 		syscallarg(u_int) count;
    104  1.1      fvdl 		syscallarg(long *) basep;
    105  1.1      fvdl 	} */ *uap = v;
    106  1.1      fvdl 	struct file *fp;
    107  1.1      fvdl 	int error, done;
    108  1.1      fvdl 	long loff;
    109  1.1      fvdl 
    110  1.1      fvdl 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
    111  1.1      fvdl 		return error;
    112  1.1      fvdl 	if ((fp->f_flag & FREAD) == 0)
    113  1.1      fvdl 		return (EBADF);
    114  1.1      fvdl 
    115  1.1      fvdl 	loff = fp->f_offset;
    116  1.1      fvdl 
    117  1.1      fvdl 	error = vn_readdir(fp, SCARG(uap, buf), UIO_USERSPACE,
    118  1.1      fvdl 			SCARG(uap, count), &done, p, 0, 0);
    119  1.1      fvdl 
    120  1.1      fvdl 	error = copyout(&loff, SCARG(uap, basep), sizeof(long));
    121  1.1      fvdl 	*retval = done;
    122  1.1      fvdl 	return error;
    123  1.2  christos }
    124  1.2  christos 
    125  1.2  christos /*
    126  1.2  christos  * Get file status; this version follows links.
    127  1.2  christos  */
    128  1.2  christos /* ARGSUSED */
    129  1.2  christos int
    130  1.2  christos compat_12_sys_stat(p, v, retval)
    131  1.2  christos 	struct proc *p;
    132  1.2  christos 	void *v;
    133  1.2  christos 	register_t *retval;
    134  1.2  christos {
    135  1.2  christos 	register struct compat_12_sys_stat_args /* {
    136  1.2  christos 		syscallarg(char *) path;
    137  1.2  christos 		syscallarg(struct stat12 *) ub;
    138  1.2  christos 	} */ *uap = v;
    139  1.2  christos 	struct stat sb;
    140  1.2  christos 	struct stat12 osb;
    141  1.2  christos 	int error;
    142  1.2  christos 	struct nameidata nd;
    143  1.2  christos 
    144  1.2  christos 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
    145  1.2  christos 	    SCARG(uap, path), p);
    146  1.2  christos 	if ((error = namei(&nd)) != 0)
    147  1.2  christos 		return (error);
    148  1.2  christos 	error = vn_stat(nd.ni_vp, &sb, p);
    149  1.2  christos 	vput(nd.ni_vp);
    150  1.2  christos 	if (error)
    151  1.2  christos 		return (error);
    152  1.2  christos 	cvtstat(&sb, &osb);
    153  1.2  christos 	error = copyout((caddr_t)&osb, (caddr_t)SCARG(uap, ub), sizeof (osb));
    154  1.2  christos 	return (error);
    155  1.2  christos }
    156  1.2  christos 
    157  1.2  christos 
    158  1.2  christos /*
    159  1.2  christos  * Get file status; this version does not follow links.
    160  1.2  christos  */
    161  1.2  christos /* ARGSUSED */
    162  1.2  christos int
    163  1.2  christos compat_12_sys_lstat(p, v, retval)
    164  1.2  christos 	struct proc *p;
    165  1.2  christos 	void *v;
    166  1.2  christos 	register_t *retval;
    167  1.2  christos {
    168  1.2  christos 	register struct compat_12_sys_lstat_args /* {
    169  1.2  christos 		syscallarg(char *) path;
    170  1.2  christos 		syscallarg(struct stat12 *) ub;
    171  1.2  christos 	} */ *uap = v;
    172  1.2  christos 	struct stat sb;
    173  1.2  christos 	struct stat12 osb;
    174  1.2  christos 	int error;
    175  1.2  christos 	struct nameidata nd;
    176  1.2  christos 
    177  1.2  christos 	NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE,
    178  1.2  christos 	    SCARG(uap, path), p);
    179  1.2  christos 	if ((error = namei(&nd)) != 0)
    180  1.2  christos 		return (error);
    181  1.2  christos 	error = vn_stat(nd.ni_vp, &sb, p);
    182  1.2  christos 	vput(nd.ni_vp);
    183  1.2  christos 	if (error)
    184  1.2  christos 		return (error);
    185  1.2  christos 	cvtstat(&sb, &osb);
    186  1.2  christos 	error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
    187  1.2  christos 	return (error);
    188  1.2  christos }
    189  1.2  christos 
    190  1.2  christos 
    191  1.2  christos /*
    192  1.2  christos  * Return status information about a file descriptor.
    193  1.2  christos  */
    194  1.2  christos /* ARGSUSED */
    195  1.2  christos int
    196  1.2  christos compat_12_sys_fstat(p, v, retval)
    197  1.2  christos 	struct proc *p;
    198  1.2  christos 	void *v;
    199  1.2  christos 	register_t *retval;
    200  1.2  christos {
    201  1.2  christos 	register struct compat_12_sys_fstat_args /* {
    202  1.2  christos 		syscallarg(int) fd;
    203  1.2  christos 		syscallarg(struct stat12 *) sb;
    204  1.2  christos 	} */ *uap = v;
    205  1.2  christos 	int fd = SCARG(uap, fd);
    206  1.2  christos 	register struct filedesc *fdp = p->p_fd;
    207  1.2  christos 	register struct file *fp;
    208  1.2  christos 	struct stat ub;
    209  1.2  christos 	struct stat12 oub;
    210  1.2  christos 	int error;
    211  1.2  christos 
    212  1.2  christos 	if ((u_int)fd >= fdp->fd_nfiles ||
    213  1.2  christos 	    (fp = fdp->fd_ofiles[fd]) == NULL)
    214  1.2  christos 		return (EBADF);
    215  1.2  christos 	switch (fp->f_type) {
    216  1.2  christos 
    217  1.2  christos 	case DTYPE_VNODE:
    218  1.2  christos 		error = vn_stat((struct vnode *)fp->f_data, &ub, p);
    219  1.2  christos 		break;
    220  1.2  christos 
    221  1.2  christos 	case DTYPE_SOCKET:
    222  1.2  christos 		error = soo_stat((struct socket *)fp->f_data, &ub);
    223  1.2  christos 		break;
    224  1.2  christos 
    225  1.2  christos 	default:
    226  1.2  christos 		panic("compat_12_sys_fstat");
    227  1.2  christos 		/*NOTREACHED*/
    228  1.2  christos 	}
    229  1.2  christos 	cvtstat(&ub, &oub);
    230  1.2  christos 	if (error == 0)
    231  1.2  christos 		error = copyout((caddr_t)&oub, (caddr_t)SCARG(uap, sb),
    232  1.2  christos 		    sizeof (oub));
    233  1.2  christos 	return (error);
    234  1.1      fvdl }
    235