ufs_vfsops.c revision 92462
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 * $FreeBSD: head/sys/ufs/ufs/ufs_vfsops.c 92462 2002-03-17 01:25:47Z mckusick $ 40 */ 41 42#include "opt_quota.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/kernel.h> 47#include <sys/lock.h> 48#include <sys/malloc.h> 49#include <sys/mount.h> 50#include <sys/proc.h> 51#include <sys/socket.h> 52#include <sys/vnode.h> 53 54#include <ufs/ufs/extattr.h> 55#include <ufs/ufs/quota.h> 56#include <ufs/ufs/inode.h> 57#include <ufs/ufs/ufsmount.h> 58#include <ufs/ufs/ufs_extern.h> 59 60MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure"); 61/* 62 * Make a filesystem operational. 63 * Nothing to do at the moment. 64 */ 65/* ARGSUSED */ 66int 67ufs_start(mp, flags, td) 68 struct mount *mp; 69 int flags; 70 struct thread *td; 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 error = VFS_VGET(mp, (ino_t)ROOTINO, LK_EXCLUSIVE, &nvp); 88 if (error) 89 return (error); 90 *vpp = nvp; 91 return (0); 92} 93 94/* 95 * Do operations associated with quotas 96 */ 97int 98ufs_quotactl(mp, cmds, uid, arg, td) 99 struct mount *mp; 100 int cmds; 101 uid_t uid; 102 caddr_t arg; 103 struct thread *td; 104{ 105#ifndef QUOTA 106 return (EOPNOTSUPP); 107#else 108 int cmd, type, error; 109 110 if (uid == -1) 111 uid = td->td_ucred->cr_ruid; 112 cmd = cmds >> SUBCMDSHIFT; 113 114 switch (cmd) { 115 case Q_SYNC: 116 break; 117 case Q_GETQUOTA: 118 if (uid == td->td_ucred->cr_ruid) 119 break; 120 /* fall through */ 121 default: 122 if ((error = suser_xxx(0, td->td_proc, PRISON_ROOT)) != 0) 123 return (error); 124 } 125 126 type = cmds & SUBCMDMASK; 127 if ((u_int)type >= MAXQUOTAS) 128 return (EINVAL); 129 if (vfs_busy(mp, LK_NOWAIT, 0, td)) 130 return (0); 131 132 switch (cmd) { 133 134 case Q_QUOTAON: 135 error = quotaon(td, mp, type, arg); 136 break; 137 138 case Q_QUOTAOFF: 139 error = quotaoff(td, mp, type); 140 break; 141 142 case Q_SETQUOTA: 143 error = setquota(mp, uid, type, arg); 144 break; 145 146 case Q_SETUSE: 147 error = setuse(mp, uid, type, arg); 148 break; 149 150 case Q_GETQUOTA: 151 error = getquota(mp, uid, type, arg); 152 break; 153 154 case Q_SYNC: 155 error = qsync(mp); 156 break; 157 158 default: 159 error = EINVAL; 160 break; 161 } 162 vfs_unbusy(mp, td); 163 return (error); 164#endif 165} 166 167/* 168 * Initial UFS filesystems, done only once. 169 */ 170int 171ufs_init(vfsp) 172 struct vfsconf *vfsp; 173{ 174 static int done; 175 176 if (done) 177 return (0); 178 done = 1; 179 ufs_ihashinit(); 180#ifdef QUOTA 181 dqinit(); 182#endif 183 return (0); 184} 185 186/* 187 * This is the generic part of fhtovp called after the underlying 188 * filesystem has validated the file handle. 189 * 190 * Call the VFS_CHECKEXP beforehand to verify access. 191 */ 192int 193ufs_fhtovp(mp, ufhp, vpp) 194 register struct mount *mp; 195 struct ufid *ufhp; 196 struct vnode **vpp; 197{ 198 register struct inode *ip; 199 struct vnode *nvp; 200 int error; 201 202 error = VFS_VGET(mp, ufhp->ufid_ino, LK_EXCLUSIVE, &nvp); 203 if (error) { 204 *vpp = NULLVP; 205 return (error); 206 } 207 ip = VTOI(nvp); 208 if (ip->i_mode == 0 || 209 ip->i_gen != ufhp->ufid_gen || 210 (VFSTOUFS(mp)->um_i_effnlink_valid ? ip->i_effnlink : 211 ip->i_nlink) <= 0) { 212 vput(nvp); 213 *vpp = NULLVP; 214 return (ESTALE); 215 } 216 *vpp = nvp; 217 return (0); 218} 219 220