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