Home | History | Annotate | Line # | Download | only in common
vfs_syscalls_20.c revision 1.40.12.3
      1  1.40.12.2    martin /*	$NetBSD: vfs_syscalls_20.c,v 1.40.12.3 2020/04/13 08:04:14 martin Exp $	*/
      2        1.1  christos 
      3        1.1  christos /*
      4        1.1  christos  * Copyright (c) 1989, 1993
      5        1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6        1.1  christos  * (c) UNIX System Laboratories, Inc.
      7        1.1  christos  * All or some portions of this file are derived from material licensed
      8        1.1  christos  * to the University of California by American Telephone and Telegraph
      9        1.1  christos  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     10        1.1  christos  * the permission of UNIX System Laboratories, Inc.
     11        1.1  christos  *
     12        1.1  christos  * Redistribution and use in source and binary forms, with or without
     13        1.1  christos  * modification, are permitted provided that the following conditions
     14        1.1  christos  * are met:
     15        1.1  christos  * 1. Redistributions of source code must retain the above copyright
     16        1.1  christos  *    notice, this list of conditions and the following disclaimer.
     17        1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     18        1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     19        1.1  christos  *    documentation and/or other materials provided with the distribution.
     20        1.1  christos  * 3. Neither the name of the University nor the names of its contributors
     21        1.1  christos  *    may be used to endorse or promote products derived from this software
     22        1.1  christos  *    without specific prior written permission.
     23        1.1  christos  *
     24        1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25        1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26        1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27        1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28        1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29        1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30        1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31        1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32        1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33        1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34        1.1  christos  * SUCH DAMAGE.
     35        1.1  christos  *
     36        1.1  christos  *	@(#)vfs_syscalls.c	8.42 (Berkeley) 7/31/95
     37        1.1  christos  */
     38        1.1  christos 
     39        1.1  christos #include <sys/cdefs.h>
     40  1.40.12.2    martin __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.40.12.3 2020/04/13 08:04:14 martin Exp $");
     41        1.1  christos 
     42       1.32        ad #ifdef _KERNEL_OPT
     43        1.1  christos #include "opt_compat_netbsd.h"
     44       1.32        ad #endif
     45        1.1  christos 
     46        1.1  christos #include <sys/param.h>
     47        1.1  christos #include <sys/systm.h>
     48        1.1  christos #include <sys/namei.h>
     49        1.1  christos #include <sys/filedesc.h>
     50        1.1  christos #include <sys/kernel.h>
     51        1.1  christos #include <sys/file.h>
     52        1.1  christos #include <sys/stat.h>
     53        1.1  christos #include <sys/vnode.h>
     54        1.1  christos #include <sys/mount.h>
     55        1.1  christos #include <sys/proc.h>
     56        1.1  christos #include <sys/uio.h>
     57        1.1  christos #include <sys/dirent.h>
     58        1.1  christos #include <sys/sysctl.h>
     59  1.40.12.1  christos #include <sys/syscall.h>
     60  1.40.12.1  christos #include <sys/syscallvar.h>
     61        1.1  christos #include <sys/syscallargs.h>
     62        1.8      elad #include <sys/kauth.h>
     63  1.40.12.3    martin #include <sys/vfs_syscalls.h>
     64        1.1  christos 
     65  1.40.12.1  christos #include <compat/common/compat_mod.h>
     66  1.40.12.1  christos 
     67        1.5  christos #include <compat/sys/mount.h>
     68  1.40.12.3    martin #include <compat/sys/statvfs.h>
     69        1.1  christos 
     70  1.40.12.1  christos static const struct syscall_package vfs_syscalls_20_syscalls[] = {
     71  1.40.12.1  christos 	{ SYS_compat_20_fhstatfs, 0, (sy_call_t *)compat_20_sys_fhstatfs },
     72  1.40.12.1  christos 	{ SYS_compat_20_fstatfs, 0, (sy_call_t *)compat_20_sys_fstatfs },
     73  1.40.12.1  christos 	{ SYS_compat_20_getfsstat, 0, (sy_call_t *)compat_20_sys_getfsstat },
     74  1.40.12.1  christos 	{ SYS_compat_20_statfs, 0, (sy_call_t *)compat_20_sys_statfs },
     75  1.40.12.1  christos 	{ 0, 0, NULL }
     76  1.40.12.1  christos };
     77  1.40.12.1  christos 
     78        1.1  christos /*
     79        1.1  christos  * Get filesystem statistics.
     80        1.1  christos  */
     81        1.1  christos /* ARGSUSED */
     82        1.1  christos int
     83       1.23       dsl compat_20_sys_statfs(struct lwp *l, const struct compat_20_sys_statfs_args *uap, register_t *retval)
     84        1.1  christos {
     85       1.23       dsl 	/* {
     86        1.1  christos 		syscallarg(const char *) path;
     87        1.1  christos 		syscallarg(struct statfs12 *) buf;
     88       1.23       dsl 	} */
     89        1.1  christos 	struct mount *mp;
     90        1.2  christos 	struct statvfs *sbuf;
     91       1.39      maxv 	int error;
     92       1.34  dholland 	struct vnode *vp;
     93        1.1  christos 
     94       1.34  dholland 	error = namei_simple_user(SCARG(uap, path),
     95       1.34  dholland 			NSM_FOLLOW_TRYEMULROOT, &vp);
     96       1.34  dholland 	if (error != 0)
     97        1.1  christos 		return error;
     98        1.2  christos 
     99       1.34  dholland 	mp = vp->v_mount;
    100        1.2  christos 
    101  1.40.12.3    martin 	sbuf = STATVFSBUF_GET();
    102        1.6  christos 	if ((error = dostatvfs(mp, sbuf, l, 0, 1)) != 0)
    103        1.2  christos 		goto done;
    104        1.2  christos 
    105  1.40.12.3    martin 	error = statvfs_to_statfs12_copy(sbuf, SCARG(uap, buf), 0);
    106        1.2  christos done:
    107       1.34  dholland 	vrele(vp);
    108  1.40.12.3    martin 	STATVFSBUF_PUT(sbuf);
    109        1.2  christos 	return error;
    110        1.1  christos }
    111        1.1  christos 
    112        1.1  christos /*
    113        1.1  christos  * Get filesystem statistics.
    114        1.1  christos  */
    115        1.1  christos /* ARGSUSED */
    116        1.1  christos int
    117       1.23       dsl compat_20_sys_fstatfs(struct lwp *l, const struct compat_20_sys_fstatfs_args *uap, register_t *retval)
    118        1.1  christos {
    119       1.23       dsl 	/* {
    120        1.1  christos 		syscallarg(int) fd;
    121        1.1  christos 		syscallarg(struct statfs12 *) buf;
    122       1.23       dsl 	} */
    123        1.1  christos 	struct file *fp;
    124        1.1  christos 	struct mount *mp;
    125        1.9  christos 	struct statvfs *sbuf;
    126        1.1  christos 	int error;
    127        1.1  christos 
    128       1.31        ad 	/* fd_getvnode() will use the descriptor for us */
    129       1.31        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    130        1.1  christos 		return (error);
    131       1.38      matt 	mp = fp->f_vnode->v_mount;
    132  1.40.12.3    martin 	sbuf = STATVFSBUF_GET();
    133        1.9  christos 	if ((error = dostatvfs(mp, sbuf, l, 0, 1)) != 0)
    134        1.1  christos 		goto out;
    135  1.40.12.3    martin 	error = statvfs_to_statfs12_copy(sbuf, SCARG(uap, buf), 0);
    136        1.1  christos  out:
    137       1.26        ad 	fd_putfile(SCARG(uap, fd));
    138  1.40.12.3    martin 	STATVFSBUF_PUT(sbuf);
    139        1.1  christos 	return error;
    140        1.1  christos }
    141        1.1  christos 
    142        1.1  christos 
    143        1.1  christos /*
    144        1.1  christos  * Get statistics on all filesystems.
    145        1.1  christos  */
    146        1.1  christos int
    147       1.23       dsl compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args *uap, register_t *retval)
    148        1.1  christos {
    149       1.23       dsl 	/* {
    150        1.1  christos 		syscallarg(struct statfs12 *) buf;
    151        1.1  christos 		syscallarg(long) bufsize;
    152        1.1  christos 		syscallarg(int) flags;
    153       1.23       dsl 	} */
    154  1.40.12.3    martin 	return do_sys_getvfsstat(l, SCARG(uap, buf), SCARG(uap, bufsize),
    155  1.40.12.3    martin 	    SCARG(uap, flags), statvfs_to_statfs12_copy,
    156  1.40.12.3    martin 	    sizeof(struct statvfs90), retval);
    157        1.1  christos }
    158        1.1  christos 
    159        1.1  christos int
    160       1.23       dsl compat_20_sys_fhstatfs(struct lwp *l, const struct compat_20_sys_fhstatfs_args *uap, register_t *retval)
    161        1.1  christos {
    162       1.23       dsl 	/* {
    163       1.11    martin 		syscallarg(const struct compat_30_fhandle *) fhp;
    164        1.1  christos 		syscallarg(struct statfs12 *) buf;
    165       1.23       dsl 	} */
    166        1.9  christos 	struct statvfs *sbuf;
    167       1.11    martin 	struct compat_30_fhandle fh;
    168        1.1  christos 	struct mount *mp;
    169        1.1  christos 	struct vnode *vp;
    170        1.1  christos 	int error;
    171        1.1  christos 
    172        1.1  christos 	/*
    173        1.1  christos 	 * Must be super user
    174        1.1  christos 	 */
    175       1.14      elad 	if ((error = kauth_authorize_system(l->l_cred,
    176       1.14      elad 	    KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)))
    177        1.1  christos 		return (error);
    178        1.1  christos 
    179       1.11    martin 	if ((error = copyin(SCARG(uap, fhp), &fh, sizeof(fh))) != 0)
    180        1.1  christos 		return (error);
    181        1.1  christos 
    182        1.1  christos 	if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
    183        1.1  christos 		return (ESTALE);
    184  1.40.12.2    martin 	error = VFS_FHTOVP(mp, (struct fid*)&fh.fh_fid, LK_EXCLUSIVE, &vp);
    185  1.40.12.2    martin 	if (error != 0)
    186        1.1  christos 		return (error);
    187        1.1  christos 	mp = vp->v_mount;
    188       1.35   hannken 	VOP_UNLOCK(vp);
    189  1.40.12.3    martin 	sbuf = STATVFSBUF_GET();
    190       1.20     pooka 	if ((error = VFS_STATVFS(mp, sbuf)) != 0)
    191        1.9  christos 		goto out;
    192  1.40.12.3    martin 	error = statvfs_to_statfs12_copy(sbuf, SCARG(uap, buf), 0);
    193        1.9  christos out:
    194       1.24        ad 	vrele(vp);
    195  1.40.12.3    martin 	STATVFSBUF_PUT(sbuf);
    196        1.9  christos 	return error;
    197        1.1  christos }
    198  1.40.12.1  christos 
    199  1.40.12.1  christos int
    200  1.40.12.1  christos vfs_syscalls_20_init(void)
    201  1.40.12.1  christos {
    202  1.40.12.1  christos 
    203  1.40.12.1  christos 	return syscall_establish(NULL, vfs_syscalls_20_syscalls);
    204  1.40.12.1  christos }
    205  1.40.12.1  christos 
    206  1.40.12.1  christos int
    207  1.40.12.1  christos vfs_syscalls_20_fini(void)
    208  1.40.12.1  christos {
    209  1.40.12.1  christos 
    210  1.40.12.1  christos 	return syscall_disestablish(NULL, vfs_syscalls_20_syscalls);
    211  1.40.12.1  christos }
    212