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