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