Home | History | Annotate | Line # | Download | only in genfs
layer_vfsops.c revision 1.10
      1 /*	$NetBSD: layer_vfsops.c,v 1.10 2003/08/07 16:32:36 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 National Aeronautics & Space Administration
      5  * All rights reserved.
      6  *
      7  * This software was written by William Studenmund of the
      8  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
      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. Neither the name of the National Aeronautics & Space Administration
     19  *    nor the names of its contributors may be used to endorse or promote
     20  *    products derived from this software without specific prior written
     21  *    permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
     24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
     27  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     28  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  * POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 /*
     36  * Copyright (c) 1992, 1993, 1995
     37  *	The Regents of the University of California.  All rights reserved.
     38  *
     39  * This code is derived from software donated to Berkeley by
     40  * Jan-Simon Pendry.
     41  *
     42  * Redistribution and use in source and binary forms, with or without
     43  * modification, are permitted provided that the following conditions
     44  * are met:
     45  * 1. Redistributions of source code must retain the above copyright
     46  *    notice, this list of conditions and the following disclaimer.
     47  * 2. Redistributions in binary form must reproduce the above copyright
     48  *    notice, this list of conditions and the following disclaimer in the
     49  *    documentation and/or other materials provided with the distribution.
     50  * 3. Neither the name of the University nor the names of its contributors
     51  *    may be used to endorse or promote products derived from this software
     52  *    without specific prior written permission.
     53  *
     54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64  * SUCH DAMAGE.
     65  *
     66  *	from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
     67  *	from: @(#)lofs_vfsops.c	1.2 (Berkeley) 6/18/92
     68  *	@(#)null_vfsops.c	8.7 (Berkeley) 5/14/95
     69  */
     70 
     71 /*
     72  * generic layer vfs ops.
     73  */
     74 
     75 #include <sys/cdefs.h>
     76 __KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.10 2003/08/07 16:32:36 agc Exp $");
     77 
     78 #include <sys/param.h>
     79 #include <sys/systm.h>
     80 #include <sys/time.h>
     81 #include <sys/proc.h>
     82 #include <sys/vnode.h>
     83 #include <sys/mount.h>
     84 #include <sys/namei.h>
     85 #include <sys/malloc.h>
     86 #include <miscfs/genfs/layer.h>
     87 #include <miscfs/genfs/layer_extern.h>
     88 
     89 /*
     90  * VFS start.  Nothing needed here - the start routine
     91  * on the underlying filesystem will have been called
     92  * when that filesystem was mounted.
     93  */
     94 int
     95 layerfs_start(mp, flags, p)
     96 	struct mount *mp;
     97 	int flags;
     98 	struct proc *p;
     99 {
    100 
    101 	return (0);
    102 	/* return VFS_START(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, flags, p); */
    103 }
    104 
    105 int
    106 layerfs_root(mp, vpp)
    107 	struct mount *mp;
    108 	struct vnode **vpp;
    109 {
    110 	struct vnode *vp;
    111 
    112 #ifdef LAYERFS_DIAGNOSTIC
    113 	printf("layerfs_root(mp = %p, vp = %p->%p)\n", mp,
    114 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
    115 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
    116 #endif
    117 
    118 	/*
    119 	 * Return locked reference to root.
    120 	 */
    121 	vp = MOUNTTOLAYERMOUNT(mp)->layerm_rootvp;
    122 	if (vp == NULL) {
    123 		*vpp = NULL;
    124 		return (EINVAL);
    125 	}
    126 	VREF(vp);
    127 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    128 	*vpp = vp;
    129 	return 0;
    130 }
    131 
    132 int
    133 layerfs_quotactl(mp, cmd, uid, arg, p)
    134 	struct mount *mp;
    135 	int cmd;
    136 	uid_t uid;
    137 	caddr_t arg;
    138 	struct proc *p;
    139 {
    140 
    141 	return VFS_QUOTACTL(MOUNTTOLAYERMOUNT(mp)->layerm_vfs,
    142 				cmd, uid, arg, p);
    143 }
    144 
    145 int
    146 layerfs_statfs(mp, sbp, p)
    147 	struct mount *mp;
    148 	struct statfs *sbp;
    149 	struct proc *p;
    150 {
    151 	int error;
    152 	struct statfs mstat;
    153 
    154 #ifdef LAYERFS_DIAGNOSTIC
    155 	printf("layerfs_statfs(mp = %p, vp = %p->%p)\n", mp,
    156 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
    157 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
    158 #endif
    159 
    160 	memset(&mstat, 0, sizeof(mstat));
    161 
    162 	error = VFS_STATFS(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, &mstat, p);
    163 	if (error)
    164 		return (error);
    165 
    166 	/* now copy across the "interesting" information and fake the rest */
    167 	sbp->f_type = mstat.f_type;
    168 	sbp->f_flags = mstat.f_flags;
    169 	sbp->f_bsize = mstat.f_bsize;
    170 	sbp->f_iosize = mstat.f_iosize;
    171 	sbp->f_blocks = mstat.f_blocks;
    172 	sbp->f_bfree = mstat.f_bfree;
    173 	sbp->f_bavail = mstat.f_bavail;
    174 	sbp->f_files = mstat.f_files;
    175 	sbp->f_ffree = mstat.f_ffree;
    176 	copy_statfs_info(sbp, mp);
    177 	return (0);
    178 }
    179 
    180 int
    181 layerfs_sync(mp, waitfor, cred, p)
    182 	struct mount *mp;
    183 	int waitfor;
    184 	struct ucred *cred;
    185 	struct proc *p;
    186 {
    187 
    188 	/*
    189 	 * XXX - Assumes no data cached at layer.
    190 	 */
    191 	return (0);
    192 }
    193 
    194 int
    195 layerfs_vget(mp, ino, vpp)
    196 	struct mount *mp;
    197 	ino_t ino;
    198 	struct vnode **vpp;
    199 {
    200 	int error;
    201 	struct vnode *vp;
    202 
    203 	if ((error = VFS_VGET(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, ino, &vp))) {
    204 		*vpp = NULL;
    205 		return (error);
    206 	}
    207 	if ((error = layer_node_create(mp, vp, vpp))) {
    208 		vput(vp);
    209 		*vpp = NULL;
    210 		return (error);
    211 	}
    212 
    213 	return (0);
    214 }
    215 
    216 int
    217 layerfs_fhtovp(mp, fidp, vpp)
    218 	struct mount *mp;
    219 	struct fid *fidp;
    220 	struct vnode **vpp;
    221 {
    222 	int error;
    223 	struct vnode *vp;
    224 
    225 	if ((error = VFS_FHTOVP(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, fidp, &vp)))
    226 		return (error);
    227 
    228 	if ((error = layer_node_create(mp, vp, vpp))) {
    229 		vput(vp);
    230 		*vpp = NULL;
    231 		return (error);
    232 	}
    233 
    234 	return (0);
    235 }
    236 
    237 int
    238 layerfs_checkexp(mp, nam, exflagsp, credanonp)
    239 	struct mount *mp;
    240 	struct mbuf *nam;
    241 	int *exflagsp;
    242 	struct ucred**credanonp;
    243 {
    244 	struct	netcred *np;
    245 	struct	layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
    246 
    247 	/*
    248 	 * get the export permission structure for this <mp, client> tuple.
    249 	 */
    250 	if ((np = vfs_export_lookup(mp, &lmp->layerm_export, nam)) == NULL)
    251 		return (EACCES);
    252 
    253 	*exflagsp = np->netc_exflags;
    254 	*credanonp = &np->netc_anon;
    255 	return (0);
    256 }
    257 
    258 int
    259 layerfs_vptofh(vp, fhp)
    260 	struct vnode *vp;
    261 	struct fid *fhp;
    262 {
    263 
    264 	return (VFS_VPTOFH(LAYERVPTOLOWERVP(vp), fhp));
    265 }
    266 
    267 int
    268 layerfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    269 	int *name;
    270 	u_int namelen;
    271 	void *oldp;
    272 	size_t *oldlenp;
    273 	void *newp;
    274 	size_t newlen;
    275 	struct proc *p;
    276 {
    277 	return (EOPNOTSUPP);
    278 }
    279