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