ufs_vfsops.c revision 1541
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 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)ufs_vfsops.c 8.4 (Berkeley) 4/16/94 39 */ 40 41#include <sys/param.h> 42#include <sys/mbuf.h> 43#include <sys/mount.h> 44#include <sys/proc.h> 45#include <sys/buf.h> 46#include <sys/vnode.h> 47#include <sys/malloc.h> 48 49#include <miscfs/specfs/specdev.h> 50 51#include <ufs/ufs/quota.h> 52#include <ufs/ufs/inode.h> 53#include <ufs/ufs/ufsmount.h> 54#include <ufs/ufs/ufs_extern.h> 55 56/* 57 * Flag to permit forcible unmounting. 58 */ 59int doforce = 1; 60 61/* 62 * Make a filesystem operational. 63 * Nothing to do at the moment. 64 */ 65/* ARGSUSED */ 66int 67ufs_start(mp, flags, p) 68 struct mount *mp; 69 int flags; 70 struct proc *p; 71{ 72 73 return (0); 74} 75 76/* 77 * Return the root of a filesystem. 78 */ 79int 80ufs_root(mp, vpp) 81 struct mount *mp; 82 struct vnode **vpp; 83{ 84 struct vnode *nvp; 85 int error; 86 87 if (error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp)) 88 return (error); 89 *vpp = nvp; 90 return (0); 91} 92 93/* 94 * Do operations associated with quotas 95 */ 96int 97ufs_quotactl(mp, cmds, uid, arg, p) 98 struct mount *mp; 99 int cmds; 100 uid_t uid; 101 caddr_t arg; 102 struct proc *p; 103{ 104 int cmd, type, error; 105 106#ifndef QUOTA 107 return (EOPNOTSUPP); 108#else 109 if (uid == -1) 110 uid = p->p_cred->p_ruid; 111 cmd = cmds >> SUBCMDSHIFT; 112 113 switch (cmd) { 114 case Q_GETQUOTA: 115 case Q_SYNC: 116 if (uid == p->p_cred->p_ruid) 117 break; 118 /* fall through */ 119 default: 120 if (error = suser(p->p_ucred, &p->p_acflag)) 121 return (error); 122 } 123 124 type = cmd & SUBCMDMASK; 125 if ((u_int)type >= MAXQUOTAS) 126 return (EINVAL); 127 128 switch (cmd) { 129 130 case Q_QUOTAON: 131 return (quotaon(p, mp, type, arg)); 132 133 case Q_QUOTAOFF: 134 if (vfs_busy(mp)) 135 return (0); 136 error = quotaoff(p, mp, type); 137 vfs_unbusy(mp); 138 return (error); 139 140 case Q_SETQUOTA: 141 return (setquota(mp, uid, type, arg)); 142 143 case Q_SETUSE: 144 return (setuse(mp, uid, type, arg)); 145 146 case Q_GETQUOTA: 147 return (getquota(mp, uid, type, arg)); 148 149 case Q_SYNC: 150 if (vfs_busy(mp)) 151 return (0); 152 error = qsync(mp); 153 vfs_unbusy(mp); 154 return (error); 155 156 default: 157 return (EINVAL); 158 } 159 /* NOTREACHED */ 160#endif 161} 162 163/* 164 * This is the generic part of fhtovp called after the underlying 165 * filesystem has validated the file handle. 166 * 167 * Verify that a host should have access to a filesystem, and if so 168 * return a vnode for the presented file handle. 169 */ 170int 171ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp) 172 register struct mount *mp; 173 struct ufid *ufhp; 174 struct mbuf *nam; 175 struct vnode **vpp; 176 int *exflagsp; 177 struct ucred **credanonp; 178{ 179 register struct inode *ip; 180 register struct netcred *np; 181 register struct ufsmount *ump = VFSTOUFS(mp); 182 struct vnode *nvp; 183 int error; 184 185 /* 186 * Get the export permission structure for this <mp, client> tuple. 187 */ 188 np = vfs_export_lookup(mp, &ump->um_export, nam); 189 if (np == NULL) 190 return (EACCES); 191 192 if (error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) { 193 *vpp = NULLVP; 194 return (error); 195 } 196 ip = VTOI(nvp); 197 if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) { 198 vput(nvp); 199 *vpp = NULLVP; 200 return (ESTALE); 201 } 202 *vpp = nvp; 203 *exflagsp = np->netc_exflags; 204 *credanonp = &np->netc_anon; 205 return (0); 206} 207