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