xref: /original-bsd/sys/ufs/ufs/ufs_vfsops.c (revision 333da485)
1 /*
2  * Copyright (c) 1991, 1993
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.3 (Berkeley) 01/21/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  * Do operations associated with quotas
52  */
53 int
54 ufs_quotactl(mp, cmds, uid, arg, p)
55 	struct mount *mp;
56 	int cmds;
57 	uid_t uid;
58 	caddr_t arg;
59 	struct proc *p;
60 {
61 	int cmd, type, error;
62 
63 #ifndef QUOTA
64 	return (EOPNOTSUPP);
65 #else
66 	if (uid == -1)
67 		uid = p->p_cred->p_ruid;
68 	cmd = cmds >> SUBCMDSHIFT;
69 
70 	switch (cmd) {
71 	case Q_GETQUOTA:
72 	case Q_SYNC:
73 		if (uid == p->p_cred->p_ruid)
74 			break;
75 		/* fall through */
76 	default:
77 		if (error = suser(p->p_ucred, &p->p_acflag))
78 			return (error);
79 	}
80 
81 	type = cmd & SUBCMDMASK;
82 	if ((u_int)type >= MAXQUOTAS)
83 		return (EINVAL);
84 
85 	switch (cmd) {
86 
87 	case Q_QUOTAON:
88 		return (quotaon(p, mp, type, arg));
89 
90 	case Q_QUOTAOFF:
91 		if (vfs_busy(mp))
92 			return (0);
93 		error = quotaoff(p, mp, type);
94 		vfs_unbusy(mp);
95 		return (error);
96 
97 	case Q_SETQUOTA:
98 		return (setquota(mp, uid, type, arg));
99 
100 	case Q_SETUSE:
101 		return (setuse(mp, uid, type, arg));
102 
103 	case Q_GETQUOTA:
104 		return (getquota(mp, uid, type, arg));
105 
106 	case Q_SYNC:
107 		if (vfs_busy(mp))
108 			return (0);
109 		error = qsync(mp);
110 		vfs_unbusy(mp);
111 		return (error);
112 
113 	default:
114 		return (EINVAL);
115 	}
116 	/* NOTREACHED */
117 #endif
118 }
119 
120 /*
121  * This is the generic part of fhtovp called after the underlying
122  * filesystem has validated the file handle.
123  *
124  * Verify that a host should have access to a filesystem, and if so
125  * return a vnode for the presented file handle.
126  */
127 int
128 ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp)
129 	register struct mount *mp;
130 	struct ufid *ufhp;
131 	struct mbuf *nam;
132 	struct vnode **vpp;
133 	int *exflagsp;
134 	struct ucred **credanonp;
135 {
136 	register struct inode *ip;
137 	register struct netcred *np;
138 	register struct ufsmount *ump = VFSTOUFS(mp);
139 	struct vnode *nvp;
140 	int error;
141 
142 	/*
143 	 * Get the export permission structure for this <mp, client> tuple.
144 	 */
145 	np = vfs_export_lookup(mp, &ump->um_export, nam);
146 	if (np == NULL)
147 		return (EACCES);
148 
149 	if (error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) {
150 		*vpp = NULLVP;
151 		return (error);
152 	}
153 	ip = VTOI(nvp);
154 	if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
155 		vput(nvp);
156 		*vpp = NULLVP;
157 		return (ESTALE);
158 	}
159 	*vpp = nvp;
160 	*exflagsp = np->netc_exflags;
161 	*credanonp = &np->netc_anon;
162 	return (0);
163 }
164