Home | History | Annotate | Line # | Download | only in genfs
layer_vfsops.c revision 1.1
      1 /*	$NetBSD: layer_vfsops.c,v 1.1 1999/07/08 01:19:01 wrstuden 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 Similation 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 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/param.h>
     80 #include <sys/systm.h>
     81 #include <sys/time.h>
     82 #include <sys/proc.h>
     83 #include <sys/types.h>
     84 #include <sys/vnode.h>
     85 #include <sys/mount.h>
     86 #include <sys/namei.h>
     87 #include <sys/malloc.h>
     88 #include <miscfs/genfs/layer.h>
     89 #include <miscfs/genfs/layer_extern.h>
     90 
     91 /*
     92  * VFS start.  Nothing needed here - the start routine
     93  * on the underlying filesystem will have been called
     94  * when that filesystem was mounted.
     95  */
     96 int
     97 layerfs_start(mp, flags, p)
     98 	struct mount *mp;
     99 	int flags;
    100 	struct proc *p;
    101 {
    102 
    103 	return (0);
    104 	/* return VFS_START(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, flags, p); */
    105 }
    106 
    107 int
    108 layerfs_root(mp, vpp)
    109 	struct mount *mp;
    110 	struct vnode **vpp;
    111 {
    112 	struct vnode *vp;
    113 
    114 #ifdef LAYERFS_DIAGNOSTIC
    115 	printf("layerfs_root(mp = %p, vp = %p->%p)\n", mp,
    116 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
    117 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
    118 #endif
    119 
    120 	/*
    121 	 * Return locked reference to root.
    122 	 */
    123 	vp = MOUNTTOLAYERMOUNT(mp)->layerm_rootvp;
    124 	if (vp == NULL) {
    125 		*vpp = NULL;
    126 		return (EINVAL);
    127 	}
    128 	VREF(vp);
    129 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    130 	*vpp = vp;
    131 	return 0;
    132 }
    133 
    134 int
    135 layerfs_quotactl(mp, cmd, uid, arg, p)
    136 	struct mount *mp;
    137 	int cmd;
    138 	uid_t uid;
    139 	caddr_t arg;
    140 	struct proc *p;
    141 {
    142 
    143 	return VFS_QUOTACTL(MOUNTTOLAYERMOUNT(mp)->layerm_vfs,
    144 				cmd, uid, arg, p);
    145 }
    146 
    147 int
    148 layerfs_statfs(mp, sbp, p)
    149 	struct mount *mp;
    150 	struct statfs *sbp;
    151 	struct proc *p;
    152 {
    153 	int error;
    154 	struct statfs mstat;
    155 
    156 #ifdef LAYERFS_DIAGNOSTIC
    157 	printf("layerfs_statfs(mp = %p, vp = %p->%p)\n", mp,
    158 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
    159 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
    160 #endif
    161 
    162 	memset(&mstat, 0, sizeof(mstat));
    163 
    164 	error = VFS_STATFS(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, &mstat, p);
    165 	if (error)
    166 		return (error);
    167 
    168 	/* now copy across the "interesting" information and fake the rest */
    169 	sbp->f_type = mstat.f_type;
    170 	sbp->f_flags = mstat.f_flags;
    171 	sbp->f_bsize = mstat.f_bsize;
    172 	sbp->f_iosize = mstat.f_iosize;
    173 	sbp->f_blocks = mstat.f_blocks;
    174 	sbp->f_bfree = mstat.f_bfree;
    175 	sbp->f_bavail = mstat.f_bavail;
    176 	sbp->f_files = mstat.f_files;
    177 	sbp->f_ffree = mstat.f_ffree;
    178 	if (sbp != &mp->mnt_stat) {
    179 		memcpy(&sbp->f_fsid, &mp->mnt_stat.f_fsid, sizeof(sbp->f_fsid));
    180 		memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
    181 		memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
    182 	}
    183 	strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
    184 	return (0);
    185 }
    186 
    187 int
    188 layerfs_sync(mp, waitfor, cred, p)
    189 	struct mount *mp;
    190 	int waitfor;
    191 	struct ucred *cred;
    192 	struct proc *p;
    193 {
    194 
    195 	/*
    196 	 * XXX - Assumes no data cached at layer.
    197 	 */
    198 	return (0);
    199 }
    200 
    201 int
    202 layerfs_vget(mp, ino, vpp)
    203 	struct mount *mp;
    204 	ino_t ino;
    205 	struct vnode **vpp;
    206 {
    207 	int error;
    208 	struct vnode *vp;
    209 
    210 	if ((error = VFS_VGET(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, ino, &vp))) {
    211 		*vpp = NULL;
    212 		return (error);
    213 	}
    214 	if ((error = layer_node_create(mp, vp, vpp))) {
    215 		vput(vp);
    216 		*vpp = NULL;
    217 		return (error);
    218 	}
    219 
    220 	return (0);
    221 }
    222 
    223 int
    224 layerfs_fhtovp(mp, fidp, vpp)
    225 	struct mount *mp;
    226 	struct fid *fidp;
    227 	struct vnode **vpp;
    228 {
    229 	int error;
    230 	struct vnode *vp;
    231 
    232 	if ((error = VFS_FHTOVP(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, fidp, &vp)))
    233 		return (error);
    234 
    235 	if ((error = layer_node_create(mp, vp, vpp))) {
    236 		vput(vp);
    237 		*vpp = NULL;
    238 		return (error);
    239 	}
    240 
    241 	return (0);
    242 }
    243 
    244 int
    245 layerfs_checkexp(mp, nam, exflagsp, credanonp)
    246 	struct mount *mp;
    247 	struct mbuf *nam;
    248 	int *exflagsp;
    249 	struct ucred**credanonp;
    250 {
    251 	struct	netcred *np;
    252 	struct	layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
    253 
    254 	/*
    255 	 * get the export permission structure for this <mp, client> tuple.
    256 	 */
    257 	if ((np = vfs_export_lookup(mp, &lmp->layerm_export, nam)) == NULL)
    258 		return (EACCES);
    259 
    260 	*exflagsp = np->netc_exflags;
    261 	*credanonp = &np->netc_anon;
    262 	return (0);
    263 }
    264 
    265 int
    266 layerfs_vptofh(vp, fhp)
    267 	struct vnode *vp;
    268 	struct fid *fhp;
    269 {
    270 
    271 	return (VFS_VPTOFH(LAYERVPTOLOWERVP(vp), fhp));
    272 }
    273 
    274 int
    275 layerfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    276 	int *name;
    277 	u_int namelen;
    278 	void *oldp;
    279 	size_t *oldlenp;
    280 	void *newp;
    281 	size_t newlen;
    282 	struct proc *p;
    283 {
    284 	return (EOPNOTSUPP);
    285 }
    286