Home | History | Annotate | Line # | Download | only in lfs
ulfs_vfsops.c revision 1.8.2.3
      1  1.8.2.2       tls /*	$NetBSD: ulfs_vfsops.c,v 1.8.2.3 2017/12/03 11:39:22 jdolecek Exp $	*/
      2  1.8.2.3  jdolecek /*  from NetBSD: ufs_vfsops.c,v 1.54 2015/03/17 09:39:29 hannken Exp  */
      3  1.8.2.2       tls 
      4  1.8.2.2       tls /*
      5  1.8.2.2       tls  * Copyright (c) 1991, 1993, 1994
      6  1.8.2.2       tls  *	The Regents of the University of California.  All rights reserved.
      7  1.8.2.2       tls  * (c) UNIX System Laboratories, Inc.
      8  1.8.2.2       tls  * All or some portions of this file are derived from material licensed
      9  1.8.2.2       tls  * to the University of California by American Telephone and Telegraph
     10  1.8.2.2       tls  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     11  1.8.2.2       tls  * the permission of UNIX System Laboratories, Inc.
     12  1.8.2.2       tls  *
     13  1.8.2.2       tls  * Redistribution and use in source and binary forms, with or without
     14  1.8.2.2       tls  * modification, are permitted provided that the following conditions
     15  1.8.2.2       tls  * are met:
     16  1.8.2.2       tls  * 1. Redistributions of source code must retain the above copyright
     17  1.8.2.2       tls  *    notice, this list of conditions and the following disclaimer.
     18  1.8.2.2       tls  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.8.2.2       tls  *    notice, this list of conditions and the following disclaimer in the
     20  1.8.2.2       tls  *    documentation and/or other materials provided with the distribution.
     21  1.8.2.2       tls  * 3. Neither the name of the University nor the names of its contributors
     22  1.8.2.2       tls  *    may be used to endorse or promote products derived from this software
     23  1.8.2.2       tls  *    without specific prior written permission.
     24  1.8.2.2       tls  *
     25  1.8.2.2       tls  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.8.2.2       tls  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.8.2.2       tls  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.8.2.2       tls  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.8.2.2       tls  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.8.2.2       tls  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.8.2.2       tls  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.8.2.2       tls  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.8.2.2       tls  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.8.2.2       tls  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.8.2.2       tls  * SUCH DAMAGE.
     36  1.8.2.2       tls  *
     37  1.8.2.2       tls  *	@(#)ufs_vfsops.c	8.8 (Berkeley) 5/20/95
     38  1.8.2.2       tls  */
     39  1.8.2.2       tls 
     40  1.8.2.2       tls #include <sys/cdefs.h>
     41  1.8.2.2       tls __KERNEL_RCSID(0, "$NetBSD: ulfs_vfsops.c,v 1.8.2.3 2017/12/03 11:39:22 jdolecek Exp $");
     42  1.8.2.2       tls 
     43  1.8.2.2       tls #if defined(_KERNEL_OPT)
     44  1.8.2.2       tls #include "opt_lfs.h"
     45  1.8.2.2       tls #include "opt_quota.h"
     46  1.8.2.2       tls #endif
     47  1.8.2.2       tls 
     48  1.8.2.2       tls #include <sys/param.h>
     49  1.8.2.2       tls #include <sys/mbuf.h>
     50  1.8.2.2       tls #include <sys/mount.h>
     51  1.8.2.2       tls #include <sys/proc.h>
     52  1.8.2.2       tls #include <sys/buf.h>
     53  1.8.2.2       tls #include <sys/vnode.h>
     54  1.8.2.2       tls #include <sys/kmem.h>
     55  1.8.2.2       tls #include <sys/kauth.h>
     56  1.8.2.2       tls #include <sys/quotactl.h>
     57  1.8.2.2       tls 
     58  1.8.2.2       tls #include <miscfs/specfs/specdev.h>
     59  1.8.2.2       tls 
     60  1.8.2.2       tls #include <ufs/lfs/lfs.h>
     61  1.8.2.3  jdolecek #include <ufs/lfs/lfs_accessors.h>
     62  1.8.2.2       tls #include <ufs/lfs/ulfs_quotacommon.h>
     63  1.8.2.2       tls #include <ufs/lfs/ulfs_inode.h>
     64  1.8.2.2       tls #include <ufs/lfs/ulfsmount.h>
     65  1.8.2.2       tls #include <ufs/lfs/ulfs_extern.h>
     66  1.8.2.2       tls #ifdef LFS_DIRHASH
     67  1.8.2.2       tls #include <ufs/lfs/ulfs_dirhash.h>
     68  1.8.2.2       tls #endif
     69  1.8.2.2       tls 
     70  1.8.2.2       tls /* how many times ulfs_init() was called */
     71  1.8.2.2       tls static int ulfs_initcount = 0;
     72  1.8.2.2       tls 
     73  1.8.2.2       tls /*
     74  1.8.2.2       tls  * Make a filesystem operational.
     75  1.8.2.2       tls  * Nothing to do at the moment.
     76  1.8.2.2       tls  */
     77  1.8.2.2       tls /* ARGSUSED */
     78  1.8.2.2       tls int
     79  1.8.2.2       tls ulfs_start(struct mount *mp, int flags)
     80  1.8.2.2       tls {
     81  1.8.2.2       tls 
     82  1.8.2.2       tls 	return (0);
     83  1.8.2.2       tls }
     84  1.8.2.2       tls 
     85  1.8.2.2       tls /*
     86  1.8.2.2       tls  * Return the root of a filesystem.
     87  1.8.2.2       tls  */
     88  1.8.2.2       tls int
     89  1.8.2.2       tls ulfs_root(struct mount *mp, struct vnode **vpp)
     90  1.8.2.2       tls {
     91  1.8.2.2       tls 	struct vnode *nvp;
     92  1.8.2.2       tls 	int error;
     93  1.8.2.2       tls 
     94  1.8.2.2       tls 	if ((error = VFS_VGET(mp, (ino_t)ULFS_ROOTINO, &nvp)) != 0)
     95  1.8.2.2       tls 		return (error);
     96  1.8.2.2       tls 	*vpp = nvp;
     97  1.8.2.2       tls 	return (0);
     98  1.8.2.2       tls }
     99  1.8.2.2       tls 
    100  1.8.2.2       tls /*
    101  1.8.2.2       tls  * Do operations associated with quotas
    102  1.8.2.2       tls  */
    103  1.8.2.2       tls int
    104  1.8.2.2       tls ulfs_quotactl(struct mount *mp, struct quotactl_args *args)
    105  1.8.2.2       tls {
    106  1.8.2.2       tls 
    107  1.8.2.2       tls #if !defined(LFS_QUOTA) && !defined(LFS_QUOTA2)
    108  1.8.2.2       tls 	(void) mp;
    109  1.8.2.2       tls 	(void) args;
    110  1.8.2.2       tls 	return (EOPNOTSUPP);
    111  1.8.2.2       tls #else
    112  1.8.2.2       tls 	struct lwp *l = curlwp;
    113  1.8.2.2       tls 	int error;
    114  1.8.2.2       tls 
    115  1.8.2.2       tls 	/* Mark the mount busy, as we're passing it to kauth(9). */
    116  1.8.2.3  jdolecek 	error = vfs_busy(mp);
    117  1.8.2.2       tls 	if (error) {
    118  1.8.2.2       tls 		return (error);
    119  1.8.2.2       tls 	}
    120  1.8.2.2       tls 	mutex_enter(&mp->mnt_updating);
    121  1.8.2.2       tls 
    122  1.8.2.2       tls 	error = lfsquota_handle_cmd(mp, l, args);
    123  1.8.2.2       tls 
    124  1.8.2.2       tls 	mutex_exit(&mp->mnt_updating);
    125  1.8.2.3  jdolecek 	vfs_unbusy(mp);
    126  1.8.2.2       tls 	return (error);
    127  1.8.2.2       tls #endif
    128  1.8.2.2       tls }
    129  1.8.2.2       tls 
    130  1.8.2.2       tls #if 0
    131  1.8.2.2       tls 	switch (cmd) {
    132  1.8.2.2       tls 	case Q_SYNC:
    133  1.8.2.2       tls 		break;
    134  1.8.2.2       tls 
    135  1.8.2.2       tls 	case Q_GETQUOTA:
    136  1.8.2.2       tls 		/* The user can always query about his own quota. */
    137  1.8.2.2       tls 		if (uid == kauth_cred_getuid(l->l_cred))
    138  1.8.2.2       tls 			break;
    139  1.8.2.2       tls 
    140  1.8.2.2       tls 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
    141  1.8.2.2       tls 		    KAUTH_REQ_SYSTEM_FS_QUOTA_GET, mp, KAUTH_ARG(uid), NULL);
    142  1.8.2.2       tls 
    143  1.8.2.2       tls 		break;
    144  1.8.2.2       tls 
    145  1.8.2.2       tls 	case Q_QUOTAON:
    146  1.8.2.2       tls 	case Q_QUOTAOFF:
    147  1.8.2.2       tls 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
    148  1.8.2.2       tls 		    KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF, mp, NULL, NULL);
    149  1.8.2.2       tls 
    150  1.8.2.2       tls 		break;
    151  1.8.2.2       tls 
    152  1.8.2.2       tls 	case Q_SETQUOTA:
    153  1.8.2.2       tls 	case Q_SETUSE:
    154  1.8.2.2       tls 		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
    155  1.8.2.2       tls 		    KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(uid), NULL);
    156  1.8.2.2       tls 
    157  1.8.2.2       tls 		break;
    158  1.8.2.2       tls 
    159  1.8.2.2       tls 	default:
    160  1.8.2.2       tls 		error = EINVAL;
    161  1.8.2.2       tls 		break;
    162  1.8.2.2       tls 	}
    163  1.8.2.2       tls 
    164  1.8.2.2       tls 	type = cmds & SUBCMDMASK;
    165  1.8.2.2       tls 	if (!error) {
    166  1.8.2.2       tls 		/* Only check if there was no error above. */
    167  1.8.2.2       tls 		if ((u_int)type >= MAXQUOTAS)
    168  1.8.2.2       tls 			error = EINVAL;
    169  1.8.2.2       tls 	}
    170  1.8.2.2       tls 
    171  1.8.2.2       tls 	if (error) {
    172  1.8.2.3  jdolecek 		vfs_unbusy(mp);
    173  1.8.2.2       tls 		return (error);
    174  1.8.2.2       tls 	}
    175  1.8.2.2       tls 
    176  1.8.2.2       tls 	mutex_enter(&mp->mnt_updating);
    177  1.8.2.2       tls 	switch (cmd) {
    178  1.8.2.2       tls 
    179  1.8.2.2       tls 	case Q_QUOTAON:
    180  1.8.2.2       tls 		error = quotaon(l, mp, type, arg);
    181  1.8.2.2       tls 		break;
    182  1.8.2.2       tls 
    183  1.8.2.2       tls 	case Q_QUOTAOFF:
    184  1.8.2.2       tls 		error = quotaoff(l, mp, type);
    185  1.8.2.2       tls 		break;
    186  1.8.2.2       tls 
    187  1.8.2.2       tls 	case Q_SETQUOTA:
    188  1.8.2.2       tls 		error = setquota(mp, uid, type, arg);
    189  1.8.2.2       tls 		break;
    190  1.8.2.2       tls 
    191  1.8.2.2       tls 	case Q_SETUSE:
    192  1.8.2.2       tls 		error = setuse(mp, uid, type, arg);
    193  1.8.2.2       tls 		break;
    194  1.8.2.2       tls 
    195  1.8.2.2       tls 	case Q_GETQUOTA:
    196  1.8.2.2       tls 		error = getquota(mp, uid, type, arg);
    197  1.8.2.2       tls 		break;
    198  1.8.2.2       tls 
    199  1.8.2.2       tls 	case Q_SYNC:
    200  1.8.2.2       tls 		error = lfs_qsync(mp);
    201  1.8.2.2       tls 		break;
    202  1.8.2.2       tls 
    203  1.8.2.2       tls 	default:
    204  1.8.2.2       tls 		error = EINVAL;
    205  1.8.2.2       tls 	}
    206  1.8.2.2       tls 	mutex_exit(&mp->mnt_updating);
    207  1.8.2.3  jdolecek 	vfs_unbusy(mp);
    208  1.8.2.2       tls 	return (error);
    209  1.8.2.2       tls #endif
    210  1.8.2.2       tls 
    211  1.8.2.2       tls /*
    212  1.8.2.2       tls  * This is the generic part of fhtovp called after the underlying
    213  1.8.2.2       tls  * filesystem has validated the file handle.
    214  1.8.2.2       tls  */
    215  1.8.2.2       tls int
    216  1.8.2.2       tls ulfs_fhtovp(struct mount *mp, struct ulfs_ufid *ufhp, struct vnode **vpp)
    217  1.8.2.2       tls {
    218  1.8.2.2       tls 	struct vnode *nvp;
    219  1.8.2.2       tls 	struct inode *ip;
    220  1.8.2.2       tls 	int error;
    221  1.8.2.2       tls 
    222  1.8.2.2       tls 	if ((error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) != 0) {
    223  1.8.2.3  jdolecek 		if (error == ENOENT)
    224  1.8.2.3  jdolecek 			error = ESTALE;
    225  1.8.2.2       tls 		*vpp = NULLVP;
    226  1.8.2.2       tls 		return (error);
    227  1.8.2.2       tls 	}
    228  1.8.2.2       tls 	ip = VTOI(nvp);
    229  1.8.2.2       tls 	KASSERT(ip != NULL);
    230  1.8.2.2       tls 	if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
    231  1.8.2.2       tls 		vput(nvp);
    232  1.8.2.2       tls 		*vpp = NULLVP;
    233  1.8.2.2       tls 		return (ESTALE);
    234  1.8.2.2       tls 	}
    235  1.8.2.2       tls 	*vpp = nvp;
    236  1.8.2.2       tls 	return (0);
    237  1.8.2.2       tls }
    238  1.8.2.2       tls 
    239  1.8.2.2       tls /*
    240  1.8.2.2       tls  * Initialize ULFS filesystems, done only once.
    241  1.8.2.2       tls  */
    242  1.8.2.2       tls void
    243  1.8.2.2       tls ulfs_init(void)
    244  1.8.2.2       tls {
    245  1.8.2.2       tls 	if (ulfs_initcount++ > 0)
    246  1.8.2.2       tls 		return;
    247  1.8.2.2       tls 
    248  1.8.2.2       tls #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
    249  1.8.2.2       tls 	lfs_dqinit();
    250  1.8.2.2       tls #endif
    251  1.8.2.2       tls #ifdef LFS_DIRHASH
    252  1.8.2.2       tls 	ulfsdirhash_init();
    253  1.8.2.2       tls #endif
    254  1.8.2.2       tls #ifdef LFS_EXTATTR
    255  1.8.2.2       tls 	ulfs_extattr_init();
    256  1.8.2.2       tls #endif
    257  1.8.2.2       tls }
    258  1.8.2.2       tls 
    259  1.8.2.2       tls void
    260  1.8.2.2       tls ulfs_reinit(void)
    261  1.8.2.2       tls {
    262  1.8.2.3  jdolecek 
    263  1.8.2.2       tls #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
    264  1.8.2.2       tls 	lfs_dqreinit();
    265  1.8.2.2       tls #endif
    266  1.8.2.2       tls }
    267  1.8.2.2       tls 
    268  1.8.2.2       tls /*
    269  1.8.2.2       tls  * Free ULFS filesystem resources, done only once.
    270  1.8.2.2       tls  */
    271  1.8.2.2       tls void
    272  1.8.2.2       tls ulfs_done(void)
    273  1.8.2.2       tls {
    274  1.8.2.2       tls 	if (--ulfs_initcount > 0)
    275  1.8.2.2       tls 		return;
    276  1.8.2.2       tls 
    277  1.8.2.2       tls #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
    278  1.8.2.2       tls 	lfs_dqdone();
    279  1.8.2.2       tls #endif
    280  1.8.2.2       tls #ifdef LFS_DIRHASH
    281  1.8.2.2       tls 	ulfsdirhash_done();
    282  1.8.2.2       tls #endif
    283  1.8.2.2       tls #ifdef LFS_EXTATTR
    284  1.8.2.2       tls 	ulfs_extattr_done();
    285  1.8.2.2       tls #endif
    286  1.8.2.2       tls }
    287