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