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