a5a0b8b642c1bbf6c7cd5e91228627fa0ac0bc86
[dragonfly.git] / sys / vfs / ufs / ufs_vfsops.c
bloba5a0b8b642c1bbf6c7cd5e91228627fa0ac0bc86
1 /*
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
38 * @(#)ufs_vfsops.c 8.8 (Berkeley) 5/20/95
39 * $FreeBSD: src/sys/ufs/ufs/ufs_vfsops.c,v 1.17.2.3 2001/10/14 19:08:16 iedowse Exp $
40 * $DragonFly: src/sys/vfs/ufs/ufs_vfsops.c,v 1.16 2006/08/03 16:40:48 swildner Exp $
43 #include "opt_quota.h"
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/mount.h>
48 #include <sys/proc.h>
49 #include <sys/malloc.h>
50 #include <sys/vnode.h>
52 #include "quota.h"
53 #include "inode.h"
54 #include "ufsmount.h"
55 #include "ufs_extern.h"
57 MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure");
59 * Return the root of a filesystem.
61 int
62 ufs_root(struct mount *mp, struct vnode **vpp)
64 struct vnode *nvp;
65 int error;
67 error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp);
68 if (error)
69 return (error);
70 *vpp = nvp;
71 return (0);
75 * Do operations associated with quotas
77 int
78 ufs_quotactl(struct mount *mp, int cmds, uid_t uid, caddr_t arg,
79 struct ucred *cred)
81 #ifndef QUOTA
82 return (EOPNOTSUPP);
83 #else
84 int cmd, type, error;
86 type = cmds & SUBCMDMASK;
87 cmd = cmds >> SUBCMDSHIFT;
89 if (uid == -1) {
90 switch(type) {
91 case USRQUOTA:
92 uid = cred->cr_ruid;
93 break;
94 case GRPQUOTA:
95 uid = cred->cr_rgid;
96 break;
97 default:
98 return (EINVAL);
102 switch (cmd) {
103 case Q_SYNC:
104 break;
105 case Q_GETQUOTA:
106 if (uid == cred->cr_ruid)
107 break;
108 /* fall through */
109 default:
110 if ((error = suser_cred(cred, PRISON_ROOT)) != 0)
111 return (error);
114 type = cmds & SUBCMDMASK;
115 if ((uint)type >= MAXQUOTAS)
116 return (EINVAL);
117 if (vfs_busy(mp, LK_NOWAIT))
118 return (0);
120 switch (cmd) {
122 case Q_QUOTAON:
123 error = ufs_quotaon(cred, mp, type, arg);
124 break;
126 case Q_QUOTAOFF:
127 error = ufs_quotaoff(mp, type);
128 break;
130 case Q_SETQUOTA:
131 error = ufs_setquota(mp, uid, type, arg);
132 break;
134 case Q_SETUSE:
135 error = ufs_setuse(mp, uid, type, arg);
136 break;
138 case Q_GETQUOTA:
139 error = ufs_getquota(mp, uid, type, arg);
140 break;
142 case Q_SYNC:
143 error = ufs_qsync(mp);
144 break;
146 default:
147 error = EINVAL;
148 break;
150 vfs_unbusy(mp);
151 return (error);
152 #endif
156 * Initial UFS filesystems, done only once.
159 ufs_init(struct vfsconf *vfsp)
161 static int done;
163 if (done)
164 return (0);
165 done = 1;
166 ufs_ihashinit();
167 #ifdef QUOTA
168 ufs_dqinit();
169 #endif
170 return (0);
174 * This is the generic part of fhtovp called after the underlying
175 * filesystem has validated the file handle.
177 * Call the VFS_CHECKEXP beforehand to verify access.
180 ufs_fhtovp(struct mount *mp, struct ufid *ufhp, struct vnode **vpp)
182 struct inode *ip;
183 struct vnode *nvp;
184 int error;
186 error = VFS_VGET(mp, ufhp->ufid_ino, &nvp);
187 if (error) {
188 *vpp = NULLVP;
189 return (error);
191 ip = VTOI(nvp);
192 if (ip->i_mode == 0 ||
193 ip->i_gen != ufhp->ufid_gen ||
194 (VFSTOUFS(mp)->um_i_effnlink_valid ? ip->i_effnlink :
195 ip->i_nlink) <= 0) {
196 vput(nvp);
197 *vpp = NULLVP;
198 return (ESTALE);
200 *vpp = nvp;
201 return (0);
206 * This is the generic part of fhtovp called after the underlying
207 * filesystem has validated the file handle.
209 * Verify that a host should have access to a filesystem.
212 ufs_check_export(struct mount *mp, struct sockaddr *nam, int *exflagsp,
213 struct ucred **credanonp)
215 struct netcred *np;
216 struct ufsmount *ump;
218 ump = VFSTOUFS(mp);
220 * Get the export permission structure for this <mp, client> tuple.
222 np = vfs_export_lookup(mp, &ump->um_export, nam);
223 if (np == NULL)
224 return (EACCES);
226 *exflagsp = np->netc_exflags;
227 *credanonp = &np->netc_anon;
228 return (0);