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