xref: /original-bsd/sys/ufs/ffs/ufs_vfsops.c (revision 7e5c8007)
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  * %sccs.include.redist.c%
11  *
12  *	@(#)ufs_vfsops.c	8.4 (Berkeley) 04/16/94
13  */
14 
15 #include <sys/param.h>
16 #include <sys/mbuf.h>
17 #include <sys/mount.h>
18 #include <sys/proc.h>
19 #include <sys/buf.h>
20 #include <sys/vnode.h>
21 #include <sys/malloc.h>
22 
23 #include <miscfs/specfs/specdev.h>
24 
25 #include <ufs/ufs/quota.h>
26 #include <ufs/ufs/inode.h>
27 #include <ufs/ufs/ufsmount.h>
28 #include <ufs/ufs/ufs_extern.h>
29 
30 /*
31  * Flag to permit forcible unmounting.
32  */
33 int doforce = 1;
34 
35 /*
36  * Make a filesystem operational.
37  * Nothing to do at the moment.
38  */
39 /* ARGSUSED */
40 int
41 ufs_start(mp, flags, p)
42 	struct mount *mp;
43 	int flags;
44 	struct proc *p;
45 {
46 
47 	return (0);
48 }
49 
50 /*
51  * Return the root of a filesystem.
52  */
53 int
54 ufs_root(mp, vpp)
55 	struct mount *mp;
56 	struct vnode **vpp;
57 {
58 	struct vnode *nvp;
59 	int error;
60 
61 	if (error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp))
62 		return (error);
63 	*vpp = nvp;
64 	return (0);
65 }
66 
67 /*
68  * Do operations associated with quotas
69  */
70 int
71 ufs_quotactl(mp, cmds, uid, arg, p)
72 	struct mount *mp;
73 	int cmds;
74 	uid_t uid;
75 	caddr_t arg;
76 	struct proc *p;
77 {
78 	int cmd, type, error;
79 
80 #ifndef QUOTA
81 	return (EOPNOTSUPP);
82 #else
83 	if (uid == -1)
84 		uid = p->p_cred->p_ruid;
85 	cmd = cmds >> SUBCMDSHIFT;
86 
87 	switch (cmd) {
88 	case Q_GETQUOTA:
89 	case Q_SYNC:
90 		if (uid == p->p_cred->p_ruid)
91 			break;
92 		/* fall through */
93 	default:
94 		if (error = suser(p->p_ucred, &p->p_acflag))
95 			return (error);
96 	}
97 
98 	type = cmd & SUBCMDMASK;
99 	if ((u_int)type >= MAXQUOTAS)
100 		return (EINVAL);
101 
102 	switch (cmd) {
103 
104 	case Q_QUOTAON:
105 		return (quotaon(p, mp, type, arg));
106 
107 	case Q_QUOTAOFF:
108 		if (vfs_busy(mp))
109 			return (0);
110 		error = quotaoff(p, mp, type);
111 		vfs_unbusy(mp);
112 		return (error);
113 
114 	case Q_SETQUOTA:
115 		return (setquota(mp, uid, type, arg));
116 
117 	case Q_SETUSE:
118 		return (setuse(mp, uid, type, arg));
119 
120 	case Q_GETQUOTA:
121 		return (getquota(mp, uid, type, arg));
122 
123 	case Q_SYNC:
124 		if (vfs_busy(mp))
125 			return (0);
126 		error = qsync(mp);
127 		vfs_unbusy(mp);
128 		return (error);
129 
130 	default:
131 		return (EINVAL);
132 	}
133 	/* NOTREACHED */
134 #endif
135 }
136 
137 /*
138  * This is the generic part of fhtovp called after the underlying
139  * filesystem has validated the file handle.
140  *
141  * Verify that a host should have access to a filesystem, and if so
142  * return a vnode for the presented file handle.
143  */
144 int
145 ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp)
146 	register struct mount *mp;
147 	struct ufid *ufhp;
148 	struct mbuf *nam;
149 	struct vnode **vpp;
150 	int *exflagsp;
151 	struct ucred **credanonp;
152 {
153 	register struct inode *ip;
154 	register struct netcred *np;
155 	register struct ufsmount *ump = VFSTOUFS(mp);
156 	struct vnode *nvp;
157 	int error;
158 
159 	/*
160 	 * Get the export permission structure for this <mp, client> tuple.
161 	 */
162 	np = vfs_export_lookup(mp, &ump->um_export, nam);
163 	if (np == NULL)
164 		return (EACCES);
165 
166 	if (error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) {
167 		*vpp = NULLVP;
168 		return (error);
169 	}
170 	ip = VTOI(nvp);
171 	if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
172 		vput(nvp);
173 		*vpp = NULLVP;
174 		return (ESTALE);
175 	}
176 	*vpp = nvp;
177 	*exflagsp = np->netc_exflags;
178 	*credanonp = &np->netc_anon;
179 	return (0);
180 }
181