ufs_vfsops.c revision 68003
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.
9 *
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.
25 *
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.
37 *
38 *	@(#)ufs_vfsops.c	8.8 (Berkeley) 5/20/95
39 * $FreeBSD: head/sys/ufs/ufs/ufs_vfsops.c 68003 2000-10-30 20:37:19Z phk $
40 */
41
42#include "opt_quota.h"
43
44#include <sys/param.h>
45#include <sys/kernel.h>
46#include <sys/systm.h>
47#include <sys/proc.h>
48#include <sys/mount.h>
49#include <sys/malloc.h>
50#include <sys/vnode.h>
51
52#include <ufs/ufs/extattr.h>
53#include <ufs/ufs/quota.h>
54#include <ufs/ufs/inode.h>
55#include <ufs/ufs/ufsmount.h>
56#include <ufs/ufs/ufs_extern.h>
57
58MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure");
59/*
60 * Make a filesystem operational.
61 * Nothing to do at the moment.
62 */
63/* ARGSUSED */
64int
65ufs_start(mp, flags, p)
66	struct mount *mp;
67	int flags;
68	struct proc *p;
69{
70
71	return (0);
72}
73
74/*
75 * Return the root of a filesystem.
76 */
77int
78ufs_root(mp, vpp)
79	struct mount *mp;
80	struct vnode **vpp;
81{
82	struct vnode *nvp;
83	int error;
84
85	error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp);
86	if (error)
87		return (error);
88	*vpp = nvp;
89	return (0);
90}
91
92/*
93 * Do operations associated with quotas
94 */
95int
96ufs_quotactl(mp, cmds, uid, arg, p)
97	struct mount *mp;
98	int cmds;
99	uid_t uid;
100	caddr_t arg;
101	struct proc *p;
102{
103#ifndef QUOTA
104	return (EOPNOTSUPP);
105#else
106	int cmd, type, error;
107
108	if (uid == -1)
109		uid = p->p_cred->p_ruid;
110	cmd = cmds >> SUBCMDSHIFT;
111
112	switch (cmd) {
113	case Q_SYNC:
114		break;
115	case Q_GETQUOTA:
116		if (uid == p->p_cred->p_ruid)
117			break;
118		/* fall through */
119	default:
120		if ((error = suser_xxx(0, p, PRISON_ROOT)) != 0)
121			return (error);
122	}
123
124	type = cmds & SUBCMDMASK;
125	if ((u_int)type >= MAXQUOTAS)
126		return (EINVAL);
127	if (vfs_busy(mp, LK_NOWAIT, 0, p))
128		return (0);
129
130	switch (cmd) {
131
132	case Q_QUOTAON:
133		error = quotaon(p, mp, type, arg);
134		break;
135
136	case Q_QUOTAOFF:
137		error = quotaoff(p, mp, type);
138		break;
139
140	case Q_SETQUOTA:
141		error = setquota(mp, uid, type, arg);
142		break;
143
144	case Q_SETUSE:
145		error = setuse(mp, uid, type, arg);
146		break;
147
148	case Q_GETQUOTA:
149		error = getquota(mp, uid, type, arg);
150		break;
151
152	case Q_SYNC:
153		error = qsync(mp);
154		break;
155
156	default:
157		error = EINVAL;
158		break;
159	}
160	vfs_unbusy(mp, p);
161	return (error);
162#endif
163}
164
165/*
166 * Initial UFS filesystems, done only once.
167 */
168int
169ufs_init(vfsp)
170	struct vfsconf *vfsp;
171{
172	static int done;
173
174	if (done)
175		return (0);
176	done = 1;
177	ufs_ihashinit();
178#ifdef QUOTA
179	dqinit();
180#endif
181	return (0);
182}
183
184/*
185 * This is the generic part of fhtovp called after the underlying
186 * filesystem has validated the file handle.
187 *
188 * Call the VFS_CHECKEXP beforehand to verify access.
189 */
190int
191ufs_fhtovp(mp, ufhp, vpp)
192	register struct mount *mp;
193	struct ufid *ufhp;
194	struct vnode **vpp;
195{
196	register struct inode *ip;
197	struct vnode *nvp;
198	int error;
199
200	error = VFS_VGET(mp, ufhp->ufid_ino, &nvp);
201	if (error) {
202		*vpp = NULLVP;
203		return (error);
204	}
205	ip = VTOI(nvp);
206	if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
207		vput(nvp);
208		*vpp = NULLVP;
209		return (ESTALE);
210	}
211	*vpp = nvp;
212	return (0);
213}
214
215
216/*
217 * This is the generic part of fhtovp called after the underlying
218 * filesystem has validated the file handle.
219 *
220 * Verify that a host should have access to a filesystem.
221 */
222int
223ufs_check_export(mp, nam, exflagsp, credanonp)
224	register struct mount *mp;
225	struct sockaddr *nam;
226	int *exflagsp;
227	struct ucred **credanonp;
228{
229	register struct netcred *np;
230	register struct ufsmount *ump;;
231
232	ump = VFSTOUFS(mp);
233	/*
234	 * Get the export permission structure for this <mp, client> tuple.
235	 */
236	np = vfs_export_lookup(mp, &ump->um_export, nam);
237	if (np == NULL)
238		return (EACCES);
239
240	*exflagsp = np->netc_exflags;
241	*credanonp = &np->netc_anon;
242	return (0);
243}
244