ufs_vfsops.c revision 13260
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.4 (Berkeley) 4/16/94 39 * $Id: ufs_vfsops.c,v 1.4 1995/03/10 22:06:39 davidg Exp $ 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 * Flag to permit forcible unmounting. 61 */ 62int doforce = 1; 63 64/* 65 * Make a filesystem operational. 66 * Nothing to do at the moment. 67 */ 68/* ARGSUSED */ 69int 70ufs_start(mp, flags, p) 71 struct mount *mp; 72 int flags; 73 struct proc *p; 74{ 75 76 return (0); 77} 78 79/* 80 * Return the root of a filesystem. 81 */ 82int 83ufs_root(mp, vpp) 84 struct mount *mp; 85 struct vnode **vpp; 86{ 87 struct vnode *nvp; 88 int error; 89 90 error = VFS_VGET(mp, (ino_t)ROOTINO, &nvp); 91 if (error) 92 return (error); 93 *vpp = nvp; 94 return (0); 95} 96 97/* 98 * Do operations associated with quotas 99 */ 100int 101ufs_quotactl(mp, cmds, uid, arg, p) 102 struct mount *mp; 103 int cmds; 104 uid_t uid; 105 caddr_t arg; 106 struct proc *p; 107{ 108#ifndef QUOTA 109 return (EOPNOTSUPP); 110#else 111 int cmd, type, error; 112 113 if (uid == -1) 114 uid = p->p_cred->p_ruid; 115 cmd = cmds >> SUBCMDSHIFT; 116 117 switch (cmd) { 118 case Q_SYNC: 119 break; 120 case Q_GETQUOTA: 121 if (uid == p->p_cred->p_ruid) 122 break; 123 /* fall through */ 124 default: 125 if (error = suser(p->p_ucred, &p->p_acflag)) 126 return (error); 127 } 128 129 type = cmds & SUBCMDMASK; 130 if ((u_int)type >= MAXQUOTAS) 131 return (EINVAL); 132 133 switch (cmd) { 134 135 case Q_QUOTAON: 136 return (quotaon(p, mp, type, arg)); 137 138 case Q_QUOTAOFF: 139 if (vfs_busy(mp)) 140 return (0); 141 error = quotaoff(p, mp, type); 142 vfs_unbusy(mp); 143 return (error); 144 145 case Q_SETQUOTA: 146 return (setquota(mp, uid, type, arg)); 147 148 case Q_SETUSE: 149 return (setuse(mp, uid, type, arg)); 150 151 case Q_GETQUOTA: 152 return (getquota(mp, uid, type, arg)); 153 154 case Q_SYNC: 155 if (vfs_busy(mp)) 156 return (0); 157 error = qsync(mp); 158 vfs_unbusy(mp); 159 return (error); 160 161 default: 162 return (EINVAL); 163 } 164 /* NOTREACHED */ 165#endif 166} 167 168/* 169 * This is the generic part of fhtovp called after the underlying 170 * filesystem has validated the file handle. 171 * 172 * Verify that a host should have access to a filesystem, and if so 173 * return a vnode for the presented file handle. 174 */ 175int 176ufs_check_export(mp, ufhp, nam, vpp, exflagsp, credanonp) 177 register struct mount *mp; 178 struct ufid *ufhp; 179 struct mbuf *nam; 180 struct vnode **vpp; 181 int *exflagsp; 182 struct ucred **credanonp; 183{ 184 register struct inode *ip; 185 register struct netcred *np; 186 register struct ufsmount *ump = VFSTOUFS(mp); 187 struct vnode *nvp; 188 int error; 189 190 /* 191 * Get the export permission structure for this <mp, client> tuple. 192 */ 193 np = vfs_export_lookup(mp, &ump->um_export, nam); 194 if (np == NULL) 195 return (EACCES); 196 197 error = VFS_VGET(mp, ufhp->ufid_ino, &nvp); 198 if (error) { 199 *vpp = NULLVP; 200 return (error); 201 } 202 ip = VTOI(nvp); 203 if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) { 204 vput(nvp); 205 *vpp = NULLVP; 206 return (ESTALE); 207 } 208 *vpp = nvp; 209 *exflagsp = np->netc_exflags; 210 *credanonp = &np->netc_anon; 211 return (0); 212} 213