1 /*	$OpenBSD: ufs_vfsops.c,v 1.11 2003/12/28 17:20:16 tedu Exp $	*/
2 /*	$NetBSD: ufs_vfsops.c,v 1.4 1996/02/09 22:36:12 christos Exp $	*/
3 
4 /*
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.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
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.
24  *
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
35  * SUCH DAMAGE.
36  *
37  *	@(#)ufs_vfsops.c	8.4 (Berkeley) 4/16/94
38  */
39 
40 #include <sys/param.h>
41 #include <sys/mbuf.h>
42 #include <sys/mount.h>
43 #include <sys/proc.h>
44 #include <sys/buf.h>
45 #include <sys/vnode.h>
46 #include <sys/malloc.h>
47 
48 #include <miscfs/specfs/specdev.h>
49 
50 #include <ufs/ufs/extattr.h>
51 #include <ufs/ufs/quota.h>
52 #include <ufs/ufs/inode.h>
53 #include <ufs/ufs/ufsmount.h>
54 #include <ufs/ufs/ufs_extern.h>
55 #ifdef UFS_DIRHASH
56 #include <ufs/ufs/dir.h>
57 #include <ufs/ufs/dirhash.h>
58 #endif
59 
60 /*
61  * Make a filesystem operational.
62  * Nothing to do at the moment.
63  */
64 /* ARGSUSED */
65 int
ufs_start(mp,flags,p)66 ufs_start(mp, flags, p)
67 	struct mount *mp;
68 	int flags;
69 	struct proc *p;
70 {
71 
72 	return (0);
73 }
74 
75 /*
76  * Return the root of a filesystem.
77  */
78 int
ufs_root(mp,vpp)79 ufs_root(mp, vpp)
80 	struct mount *mp;
81 	struct vnode **vpp;
82 {
83 	struct vnode *nvp;
84 	int error;
85 
86 	if ((error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp)) != 0)
87 		return (error);
88 	*vpp = nvp;
89 	return (0);
90 }
91 
92 /*
93  * Verify a remote client has export rights and return these rights via.
94  * exflagsp and credanonp.
95  */
96 int
ufs_check_export(mp,nam,exflagsp,credanonp)97 ufs_check_export(mp, nam, exflagsp, credanonp)
98 	register struct mount *mp;
99 	struct mbuf *nam;
100 	int *exflagsp;
101 	struct ucred **credanonp;
102 {
103 	register struct netcred *np;
104 	register struct ufsmount *ump = VFSTOUFS(mp);
105 
106 	/*
107 	 * Get the export permission structure for this <mp, client> tuple.
108 	 */
109 	np = vfs_export_lookup(mp, &ump->um_export, nam);
110 	if (np == NULL)
111 		return (EACCES);
112 
113 	*exflagsp = np->netc_exflags;
114 	*credanonp = &np->netc_anon;
115 	return (0);
116 }
117 
118 /*
119  * Initial UFS filesystems, done only once.
120  */
121 int
ufs_init(vfsp)122 ufs_init(vfsp)
123 	struct vfsconf *vfsp;
124 {
125 	static int done;
126 
127 	if (done)
128 		return (0);
129 	done = 1;
130 	ufs_ihashinit();
131 	ufs_quota_init();
132 #ifdef UFS_DIRHASH
133 	ufsdirhash_init();
134 #endif
135 
136 	return (0);
137 }
138 
139 /*
140  * This is the generic part of fhtovp called after the underlying
141  * filesystem has validated the file handle.
142  */
143 int
ufs_fhtovp(mp,ufhp,vpp)144 ufs_fhtovp(mp, ufhp, vpp)
145 	register struct mount *mp;
146 	struct ufid *ufhp;
147 	struct vnode **vpp;
148 {
149 	register struct inode *ip;
150 	struct vnode *nvp;
151 	int error;
152 
153 	if ((error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) != 0) {
154 		*vpp = NULLVP;
155 		return (error);
156 	}
157 	ip = VTOI(nvp);
158 	if (ip->i_ffs_mode == 0 || ip->i_ffs_gen != ufhp->ufid_gen) {
159 		vput(nvp);
160 		*vpp = NULLVP;
161 		return (ESTALE);
162 	}
163 	*vpp = nvp;
164 	return (0);
165 }
166