1 /* $NetBSD: ulfs_vfsops.c,v 1.11 2015/09/15 15:01:03 dholland Exp $ */
2 /* from NetBSD: ufs_vfsops.c,v 1.52 2013/01/22 09:39:18 dholland Exp */
5 * Copyright (c) 1991, 1993, 1994
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * @(#)ufs_vfsops.c 8.8 (Berkeley) 5/20/95
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: ulfs_vfsops.c,v 1.11 2015/09/15 15:01:03 dholland Exp $");
43 #if defined(_KERNEL_OPT)
45 #include "opt_quota.h"
48 #include <sys/param.h>
50 #include <sys/mount.h>
53 #include <sys/vnode.h>
55 #include <sys/kauth.h>
56 #include <sys/quotactl.h>
58 #include <miscfs/specfs/specdev.h>
60 #include <ufs/lfs/lfs.h>
61 #include <ufs/lfs/lfs_accessors.h>
62 #include <ufs/lfs/ulfs_quotacommon.h>
63 #include <ufs/lfs/ulfs_inode.h>
64 #include <ufs/lfs/ulfsmount.h>
65 #include <ufs/lfs/ulfs_extern.h>
67 #include <ufs/lfs/ulfs_dirhash.h>
70 /* how many times ulfs_init() was called */
71 static int ulfs_initcount
= 0;
74 * Make a filesystem operational.
75 * Nothing to do at the moment.
79 ulfs_start(struct mount
*mp
, int flags
)
86 * Return the root of a filesystem.
89 ulfs_root(struct mount
*mp
, struct vnode
**vpp
)
94 if ((error
= VFS_VGET(mp
, (ino_t
)ULFS_ROOTINO
, &nvp
)) != 0)
101 * Do operations associated with quotas
104 ulfs_quotactl(struct mount
*mp
, struct quotactl_args
*args
)
107 #if !defined(LFS_QUOTA) && !defined(LFS_QUOTA2)
112 struct lwp
*l
= curlwp
;
115 /* Mark the mount busy, as we're passing it to kauth(9). */
116 error
= vfs_busy(mp
, NULL
);
120 mutex_enter(&mp
->mnt_updating
);
122 error
= lfsquota_handle_cmd(mp
, l
, args
);
124 mutex_exit(&mp
->mnt_updating
);
125 vfs_unbusy(mp
, false, NULL
);
136 /* The user can always query about his own quota. */
137 if (uid
== kauth_cred_getuid(l
->l_cred
))
140 error
= kauth_authorize_system(l
->l_cred
, KAUTH_SYSTEM_FS_QUOTA
,
141 KAUTH_REQ_SYSTEM_FS_QUOTA_GET
, mp
, KAUTH_ARG(uid
), NULL
);
147 error
= kauth_authorize_system(l
->l_cred
, KAUTH_SYSTEM_FS_QUOTA
,
148 KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF
, mp
, NULL
, NULL
);
154 error
= kauth_authorize_system(l
->l_cred
, KAUTH_SYSTEM_FS_QUOTA
,
155 KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE
, mp
, KAUTH_ARG(uid
), NULL
);
164 type
= cmds
& SUBCMDMASK
;
166 /* Only check if there was no error above. */
167 if ((u_int
)type
>= MAXQUOTAS
)
172 vfs_unbusy(mp
, false, NULL
);
176 mutex_enter(&mp
->mnt_updating
);
180 error
= quotaon(l
, mp
, type
, arg
);
184 error
= quotaoff(l
, mp
, type
);
188 error
= setquota(mp
, uid
, type
, arg
);
192 error
= setuse(mp
, uid
, type
, arg
);
196 error
= getquota(mp
, uid
, type
, arg
);
200 error
= lfs_qsync(mp
);
206 mutex_exit(&mp
->mnt_updating
);
207 vfs_unbusy(mp
, false, NULL
);
212 * This is the generic part of fhtovp called after the underlying
213 * filesystem has validated the file handle.
216 ulfs_fhtovp(struct mount
*mp
, struct ulfs_ufid
*ufhp
, struct vnode
**vpp
)
222 if ((error
= VFS_VGET(mp
, ufhp
->ufid_ino
, &nvp
)) != 0) {
230 if (ip
->i_mode
== 0 || ip
->i_gen
!= ufhp
->ufid_gen
) {
240 * Initialize ULFS filesystems, done only once.
245 if (ulfs_initcount
++ > 0)
248 #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
263 #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
269 * Free ULFS filesystem resources, done only once.
274 if (--ulfs_initcount
> 0)
277 #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)