xref: /openbsd-src/sys/ufs/ufs/ufs_vfsops.c (revision 5b133f3f277e80f096764111e64f3a1284acb179)
1 /*	$OpenBSD: ufs_vfsops.c,v 1.20 2023/03/08 04:43:09 guenther 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/vnode.h>
44 #include <sys/malloc.h>
45 #include <sys/specdev.h>
46 
47 #include <ufs/ufs/quota.h>
48 #include <ufs/ufs/inode.h>
49 #include <ufs/ufs/ufsmount.h>
50 #include <ufs/ufs/ufs_extern.h>
51 #ifdef UFS_DIRHASH
52 #include <ufs/ufs/dir.h>
53 #include <ufs/ufs/dirhash.h>
54 #endif
55 
56 /*
57  * Make a filesystem operational.
58  * Nothing to do at the moment.
59  */
60 int
ufs_start(struct mount * mp,int flags,struct proc * p)61 ufs_start(struct mount *mp, int flags, struct proc *p)
62 {
63 	return (0);
64 }
65 
66 /*
67  * Return the root of a filesystem.
68  */
69 int
ufs_root(struct mount * mp,struct vnode ** vpp)70 ufs_root(struct mount *mp, struct vnode **vpp)
71 {
72 	struct vnode *nvp;
73 	int error;
74 
75 	if ((error = VFS_VGET(mp, ROOTINO, &nvp)) != 0)
76 		return (error);
77 	*vpp = nvp;
78 	return (0);
79 }
80 
81 /*
82  * Verify a remote client has export rights and return these rights via.
83  * exflagsp and credanonp.
84  */
85 int
ufs_check_export(struct mount * mp,struct mbuf * nam,int * exflagsp,struct ucred ** credanonp)86 ufs_check_export(struct mount *mp, struct mbuf *nam, int *exflagsp,
87     struct ucred **credanonp)
88 {
89 	struct netcred *np;
90 	struct ufsmount *ump = VFSTOUFS(mp);
91 
92 	/*
93 	 * Get the export permission structure for this <mp, client> tuple.
94 	 */
95 	np = vfs_export_lookup(mp, &ump->um_export, nam);
96 	if (np == NULL)
97 		return (EACCES);
98 
99 	*exflagsp = np->netc_exflags;
100 	*credanonp = &np->netc_anon;
101 	return (0);
102 }
103 
104 /*
105  * Initialize UFS file systems, done only once.
106  */
107 int
ufs_init(struct vfsconf * vfsp)108 ufs_init(struct vfsconf *vfsp)
109 {
110 	static int done;
111 
112 	if (done)
113 		return (0);
114 	done = 1;
115 	ufs_ihashinit();
116 	ufs_quota_init();
117 #ifdef UFS_DIRHASH
118 	ufsdirhash_init();
119 #endif
120 
121 	return (0);
122 }
123 
124 /*
125  * This is the generic part of fhtovp called after the underlying
126  * filesystem has validated the file handle.
127  */
128 int
ufs_fhtovp(struct mount * mp,struct ufid * ufhp,struct vnode ** vpp)129 ufs_fhtovp(struct mount *mp, struct ufid *ufhp, struct vnode **vpp)
130 {
131 	struct inode *ip;
132 	struct vnode *nvp;
133 	int error;
134 
135 	if ((error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) != 0) {
136 		*vpp = NULLVP;
137 		return (error);
138 	}
139 	ip = VTOI(nvp);
140 	if (DIP(ip, mode) == 0 || DIP(ip, gen) != ufhp->ufid_gen) {
141 		vput(nvp);
142 		*vpp = NULLVP;
143 		return (ESTALE);
144 	}
145 	*vpp = nvp;
146 	return (0);
147 }
148