ufs_vfsops.c revision 144056
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 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)ufs_vfsops.c 8.8 (Berkeley) 5/20/95 35 */ 36 37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD: head/sys/ufs/ufs/ufs_vfsops.c 144056 2005-03-24 07:32:50Z jeff $"); 39 40#include "opt_quota.h" 41#include "opt_ufs.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/kernel.h> 46#include <sys/lock.h> 47#include <sys/malloc.h> 48#include <sys/mount.h> 49#include <sys/proc.h> 50#include <sys/socket.h> 51#include <sys/vnode.h> 52 53#include <ufs/ufs/extattr.h> 54#include <ufs/ufs/quota.h> 55#include <ufs/ufs/inode.h> 56#include <ufs/ufs/ufsmount.h> 57#include <ufs/ufs/ufs_extern.h> 58#ifdef UFS_DIRHASH 59#include <ufs/ufs/dir.h> 60#include <ufs/ufs/dirhash.h> 61#endif 62 63MALLOC_DEFINE(M_UFSMNT, "UFS mount", "UFS mount structure"); 64 65/* 66 * Return the root of a filesystem. 67 */ 68int 69ufs_root(mp, flags, vpp, td) 70 struct mount *mp; 71 int flags; 72 struct vnode **vpp; 73 struct thread *td; 74{ 75 struct vnode *nvp; 76 int error; 77 78 error = VFS_VGET(mp, (ino_t)ROOTINO, flags, &nvp); 79 if (error) 80 return (error); 81 *vpp = nvp; 82 return (0); 83} 84 85/* 86 * Do operations associated with quotas 87 */ 88int 89ufs_quotactl(mp, cmds, uid, arg, td) 90 struct mount *mp; 91 int cmds; 92 uid_t uid; 93 caddr_t arg; 94 struct thread *td; 95{ 96#ifndef QUOTA 97 return (EOPNOTSUPP); 98#else 99 int cmd, type, error; 100 101 if (uid == -1) 102 uid = td->td_ucred->cr_ruid; 103 cmd = cmds >> SUBCMDSHIFT; 104 type = cmds & SUBCMDMASK; 105 if ((u_int)type >= MAXQUOTAS) 106 return (EINVAL); 107 108 if (vfs_busy(mp, LK_NOWAIT, 0, td)) 109 return (0); 110 111 switch (cmd) { 112 case Q_QUOTAON: 113 error = quotaon(td, mp, type, arg); 114 break; 115 116 case Q_QUOTAOFF: 117 error = quotaoff(td, mp, type); 118 break; 119 120 case Q_SETQUOTA: 121 error = setquota(td, mp, uid, type, arg); 122 break; 123 124 case Q_SETUSE: 125 error = setuse(td, mp, uid, type, arg); 126 break; 127 128 case Q_GETQUOTA: 129 error = getquota(td, mp, uid, type, arg); 130 break; 131 132 case Q_SYNC: 133 error = qsync(mp); 134 break; 135 136 default: 137 error = EINVAL; 138 break; 139 } 140 vfs_unbusy(mp, td); 141 return (error); 142#endif 143} 144 145/* 146 * Initial UFS filesystems, done only once. 147 */ 148int 149ufs_init(vfsp) 150 struct vfsconf *vfsp; 151{ 152 153#ifdef QUOTA 154 dqinit(); 155#endif 156#ifdef UFS_DIRHASH 157 ufsdirhash_init(); 158#endif 159 return (0); 160} 161 162/* 163 * Uninitialise UFS filesystems, done before module unload. 164 */ 165int 166ufs_uninit(vfsp) 167 struct vfsconf *vfsp; 168{ 169 170#ifdef QUOTA 171 dquninit(); 172#endif 173#ifdef UFS_DIRHASH 174 ufsdirhash_uninit(); 175#endif 176 return (0); 177} 178 179/* 180 * This is the generic part of fhtovp called after the underlying 181 * filesystem has validated the file handle. 182 * 183 * Call the VFS_CHECKEXP beforehand to verify access. 184 */ 185int 186ufs_fhtovp(mp, ufhp, vpp) 187 struct mount *mp; 188 struct ufid *ufhp; 189 struct vnode **vpp; 190{ 191 struct inode *ip; 192 struct vnode *nvp; 193 int error; 194 195 error = VFS_VGET(mp, ufhp->ufid_ino, LK_EXCLUSIVE, &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 ip->i_effnlink <= 0) { 203 vput(nvp); 204 *vpp = NULLVP; 205 return (ESTALE); 206 } 207 *vpp = nvp; 208 vnode_create_vobject(*vpp, DIP(ip, i_size), curthread); 209 return (0); 210} 211