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.7 (Berkeley) 05/10/95 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 * 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 * Return the root of a filesystem. 47 */ 48 int 49 ufs_root(mp, vpp) 50 struct mount *mp; 51 struct vnode **vpp; 52 { 53 struct vnode *nvp; 54 int error; 55 56 if (error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp)) 57 return (error); 58 *vpp = nvp; 59 return (0); 60 } 61 62 /* 63 * Do operations associated with quotas 64 */ 65 int 66 ufs_quotactl(mp, cmds, uid, arg, p) 67 struct mount *mp; 68 int cmds; 69 uid_t uid; 70 caddr_t arg; 71 struct proc *p; 72 { 73 int cmd, type, error; 74 75 #ifndef QUOTA 76 return (EOPNOTSUPP); 77 #else 78 if (uid == -1) 79 uid = p->p_cred->p_ruid; 80 cmd = cmds >> SUBCMDSHIFT; 81 82 switch (cmd) { 83 case Q_SYNC: 84 break; 85 case Q_GETQUOTA: 86 if (uid == p->p_cred->p_ruid) 87 break; 88 /* fall through */ 89 default: 90 if (error = suser(p->p_ucred, &p->p_acflag)) 91 return (error); 92 } 93 94 type = cmds & SUBCMDMASK; 95 if ((u_int)type >= MAXQUOTAS) 96 return (EINVAL); 97 98 switch (cmd) { 99 100 case Q_QUOTAON: 101 return (quotaon(p, mp, type, arg)); 102 103 case Q_QUOTAOFF: 104 if (vfs_busy(mp)) 105 return (0); 106 error = quotaoff(p, mp, type); 107 vfs_unbusy(mp); 108 return (error); 109 110 case Q_SETQUOTA: 111 return (setquota(mp, uid, type, arg)); 112 113 case Q_SETUSE: 114 return (setuse(mp, uid, type, arg)); 115 116 case Q_GETQUOTA: 117 return (getquota(mp, uid, type, arg)); 118 119 case Q_SYNC: 120 if (vfs_busy(mp)) 121 return (0); 122 error = qsync(mp); 123 vfs_unbusy(mp); 124 return (error); 125 126 default: 127 return (EINVAL); 128 } 129 /* NOTREACHED */ 130 #endif 131 } 132 133 /* 134 * Initial UFS filesystems, done only once. 135 */ 136 int 137 ufs_init(vfsp) 138 struct vfsconf *vfsp; 139 { 140 static int done; 141 142 if (done) 143 return (0); 144 done = 1; 145 ufs_ihashinit(); 146 #ifdef QUOTA 147 dqinit(); 148 #endif 149 return (0); 150 } 151 152 /* 153 * This is the generic part of fhtovp called after the underlying 154 * filesystem has validated the file handle. 155 * 156 * Verify that a host should have access to a filesystem, and if so 157 * return a vnode for the presented file handle. 158 */ 159 int 160 ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp) 161 register struct mount *mp; 162 struct ufid *ufhp; 163 struct mbuf *nam; 164 struct vnode **vpp; 165 int *exflagsp; 166 struct ucred **credanonp; 167 { 168 register struct inode *ip; 169 register struct netcred *np; 170 register struct ufsmount *ump = VFSTOUFS(mp); 171 struct vnode *nvp; 172 int error; 173 174 /* 175 * Get the export permission structure for this <mp, client> tuple. 176 */ 177 np = vfs_export_lookup(mp, &ump->um_export, nam); 178 if (np == NULL) 179 return (EACCES); 180 181 if (error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) { 182 *vpp = NULLVP; 183 return (error); 184 } 185 ip = VTOI(nvp); 186 if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) { 187 vput(nvp); 188 *vpp = NULLVP; 189 return (ESTALE); 190 } 191 *vpp = nvp; 192 *exflagsp = np->netc_exflags; 193 *credanonp = &np->netc_anon; 194 return (0); 195 } 196