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