ulfs_vfsops.c revision 1.3 1 1.3 dholland /* $NetBSD: ulfs_vfsops.c,v 1.3 2013/06/06 00:46:40 dholland Exp $ */
2 1.1 dholland /* from NetBSD: ufs_vfsops.c,v 1.52 2013/01/22 09:39:18 dholland 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.3 dholland __KERNEL_RCSID(0, "$NetBSD: ulfs_vfsops.c,v 1.3 2013/06/06 00:46:40 dholland 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.1 dholland
57 1.1 dholland #include <miscfs/specfs/specdev.h>
58 1.1 dholland
59 1.1 dholland #include <sys/quotactl.h>
60 1.2 dholland #include <ufs/lfs/ulfs_quotacommon.h>
61 1.2 dholland #include <ufs/lfs/ulfs_inode.h>
62 1.2 dholland #include <ufs/lfs/ulfsmount.h>
63 1.2 dholland #include <ufs/lfs/ulfs_extern.h>
64 1.3 dholland #ifdef LFS_DIRHASH
65 1.2 dholland #include <ufs/lfs/ulfs_dirhash.h>
66 1.1 dholland #endif
67 1.1 dholland
68 1.1 dholland /* how many times ufs_init() was called */
69 1.1 dholland static int ufs_initcount = 0;
70 1.1 dholland
71 1.1 dholland pool_cache_t ufs_direct_cache;
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.1 dholland ufs_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.1 dholland ufs_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.1 dholland if ((error = VFS_VGET(mp, (ino_t)UFS_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.1 dholland ufs_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.1 dholland error = vfs_busy(mp, NULL);
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.1 dholland error = quota_handle_cmd(mp, l, args);
123 1.1 dholland
124 1.1 dholland mutex_exit(&mp->mnt_updating);
125 1.1 dholland vfs_unbusy(mp, false, NULL);
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.1 dholland vfs_unbusy(mp, false, NULL);
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.1 dholland error = 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.1 dholland vfs_unbusy(mp, false, NULL);
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.1 dholland ufs_fhtovp(struct mount *mp, struct 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.1 dholland *vpp = NULLVP;
224 1.1 dholland return (error);
225 1.1 dholland }
226 1.1 dholland ip = VTOI(nvp);
227 1.1 dholland KASSERT(ip != NULL);
228 1.1 dholland if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
229 1.1 dholland vput(nvp);
230 1.1 dholland *vpp = NULLVP;
231 1.1 dholland return (ESTALE);
232 1.1 dholland }
233 1.1 dholland *vpp = nvp;
234 1.1 dholland return (0);
235 1.1 dholland }
236 1.1 dholland
237 1.1 dholland /*
238 1.1 dholland * Initialize UFS filesystems, done only once.
239 1.1 dholland */
240 1.1 dholland void
241 1.1 dholland ufs_init(void)
242 1.1 dholland {
243 1.1 dholland if (ufs_initcount++ > 0)
244 1.1 dholland return;
245 1.1 dholland
246 1.1 dholland ufs_direct_cache = pool_cache_init(sizeof(struct direct), 0, 0, 0,
247 1.1 dholland "ufsdir", NULL, IPL_NONE, NULL, NULL, NULL);
248 1.1 dholland
249 1.1 dholland ufs_ihashinit();
250 1.3 dholland #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
251 1.1 dholland dqinit();
252 1.1 dholland #endif
253 1.3 dholland #ifdef LFS_DIRHASH
254 1.1 dholland ufsdirhash_init();
255 1.1 dholland #endif
256 1.3 dholland #ifdef LFS_EXTATTR
257 1.1 dholland ufs_extattr_init();
258 1.1 dholland #endif
259 1.1 dholland }
260 1.1 dholland
261 1.1 dholland void
262 1.1 dholland ufs_reinit(void)
263 1.1 dholland {
264 1.1 dholland ufs_ihashreinit();
265 1.3 dholland #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
266 1.1 dholland dqreinit();
267 1.1 dholland #endif
268 1.1 dholland }
269 1.1 dholland
270 1.1 dholland /*
271 1.1 dholland * Free UFS filesystem resources, done only once.
272 1.1 dholland */
273 1.1 dholland void
274 1.1 dholland ufs_done(void)
275 1.1 dholland {
276 1.1 dholland if (--ufs_initcount > 0)
277 1.1 dholland return;
278 1.1 dholland
279 1.1 dholland ufs_ihashdone();
280 1.3 dholland #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
281 1.1 dholland dqdone();
282 1.1 dholland #endif
283 1.1 dholland pool_cache_destroy(ufs_direct_cache);
284 1.3 dholland #ifdef LFS_DIRHASH
285 1.1 dholland ufsdirhash_done();
286 1.1 dholland #endif
287 1.3 dholland #ifdef LFS_EXTATTR
288 1.1 dholland ufs_extattr_done();
289 1.1 dholland #endif
290 1.1 dholland }
291