Home | History | Annotate | Line # | Download | only in filecorefs
filecore_vfsops.c revision 1.5.2.4
      1 /*	$NetBSD: filecore_vfsops.c,v 1.5.2.4 2004/08/24 17:57:36 skrll Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1994 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	filecore_vfsops.c	1.1	1998/6/26
     32  */
     33 
     34 /*-
     35  * Copyright (c) 1998 Andrew McMurry
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  * 3. All advertising materials mentioning features or use of this software
     46  *    must display the following acknowledgement:
     47  *	This product includes software developed by the University of
     48  *	California, Berkeley and its contributors.
     49  * 4. Neither the name of the University nor the names of its contributors
     50  *    may be used to endorse or promote products derived from this software
     51  *    without specific prior written permission.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  * SUCH DAMAGE.
     64  *
     65  *	filecore_vfsops.c	1.1	1998/6/26
     66  */
     67 
     68 #include <sys/cdefs.h>
     69 __KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.5.2.4 2004/08/24 17:57:36 skrll Exp $");
     70 
     71 #if defined(_KERNEL_OPT)
     72 #include "opt_compat_netbsd.h"
     73 #endif
     74 
     75 #include <sys/param.h>
     76 #include <sys/systm.h>
     77 #include <sys/namei.h>
     78 #include <sys/proc.h>
     79 #include <sys/vnode.h>
     80 #include <miscfs/specfs/specdev.h>
     81 #include <sys/mount.h>
     82 #include <sys/buf.h>
     83 #include <sys/file.h>
     84 #include <sys/device.h>
     85 #include <sys/errno.h>
     86 #include <sys/malloc.h>
     87 #include <sys/pool.h>
     88 #include <sys/conf.h>
     89 #include <sys/sysctl.h>
     90 
     91 #include <fs/filecorefs/filecore.h>
     92 #include <fs/filecorefs/filecore_extern.h>
     93 #include <fs/filecorefs/filecore_node.h>
     94 #include <fs/filecorefs/filecore_mount.h>
     95 
     96 MALLOC_DEFINE(M_FILECOREMNT, "filecore mount", "Filecore FS mount structures");
     97 
     98 extern const struct vnodeopv_desc filecore_vnodeop_opv_desc;
     99 
    100 const struct vnodeopv_desc * const filecore_vnodeopv_descs[] = {
    101 	&filecore_vnodeop_opv_desc,
    102 	NULL,
    103 };
    104 
    105 struct vfsops filecore_vfsops = {
    106 	MOUNT_FILECORE,
    107 	filecore_mount,
    108 	filecore_start,
    109 	filecore_unmount,
    110 	filecore_root,
    111 	filecore_quotactl,
    112 	filecore_statvfs,
    113 	filecore_sync,
    114 	filecore_vget,
    115 	filecore_fhtovp,
    116 	filecore_vptofh,
    117 	filecore_init,
    118 	filecore_reinit,
    119 	filecore_done,
    120 	NULL,
    121 	NULL,				/* filecore_mountroot */
    122 	filecore_checkexp,
    123 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    124 	filecore_vnodeopv_descs,
    125 };
    126 
    127 struct genfs_ops filecore_genfsops = {
    128 	genfs_size,
    129 };
    130 
    131 /*
    132  * Called by vfs_mountroot when iso is going to be mounted as root.
    133  *
    134  * Name is updated by mount(8) after booting.
    135  */
    136 
    137 static int filecore_mountfs __P((struct vnode *devvp, struct mount *mp,
    138 		struct lwp *l, struct filecore_args *argp));
    139 
    140 #if 0
    141 int
    142 filecore_mountroot()
    143 {
    144 	struct mount *mp;
    145 	extern struct vnode *rootvp;
    146 	struct proc *p = curproc;	/* XXX */
    147 	int error;
    148 	struct filecore_args args;
    149 
    150 	if (root_device->dv_class != DV_DISK)
    151 		return (ENODEV);
    152 
    153 	/*
    154 	 * Get vnodes for swapdev and rootdev.
    155 	 */
    156 	if (bdevvp(rootdev, &rootvp))
    157 		panic("filecore_mountroot: can't setup rootvp");
    158 
    159 	if ((error = vfs_rootmountalloc(MOUNT_FILECORE, "root_device", &mp)) != 0)
    160 		return (error);
    161 
    162 	args.flags = FILECOREMNT_ROOT;
    163 	if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
    164 		mp->mnt_op->vfs_refcount--;
    165 		vfs_unbusy(mp);
    166 		free(mp, M_MOUNT);
    167 		return (error);
    168 	}
    169 	simple_lock(&mountlist_slock);
    170 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    171 	simple_unlock(&mountlist_slock);
    172 	(void)filecore_statvfs(mp, &mp->mnt_stat, p);
    173 	vfs_unbusy(mp);
    174 	return (0);
    175 }
    176 #endif
    177 
    178 /*
    179  * VFS Operations.
    180  *
    181  * mount system call
    182  */
    183 int
    184 filecore_mount(mp, path, data, ndp, l)
    185 	struct mount *mp;
    186 	const char *path;
    187 	void *data;
    188 	struct nameidata *ndp;
    189 	struct lwp *l;
    190 {
    191 	struct vnode *devvp;
    192 	struct filecore_args args;
    193 	struct proc *p;
    194 	int error;
    195 	struct filecore_mnt *fcmp = NULL;
    196 
    197 	p = l->l_proc;
    198 	if (mp->mnt_flag & MNT_GETARGS) {
    199 		fcmp = VFSTOFILECORE(mp);
    200 		if (fcmp == NULL)
    201 			return EIO;
    202 		args.flags = fcmp->fc_mntflags;
    203 		args.uid = fcmp->fc_uid;
    204 		args.gid = fcmp->fc_gid;
    205 		args.fspec = NULL;
    206 		vfs_showexport(mp, &args.export, &fcmp->fc_export);
    207 		return copyout(&args, data, sizeof(args));
    208 	}
    209 	error = copyin(data, &args, sizeof (struct filecore_args));
    210 	if (error)
    211 		return (error);
    212 
    213 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
    214 		return (EROFS);
    215 
    216 	/*
    217 	 * If updating, check whether changing from read-only to
    218 	 * read/write; if there is no device name, that's all we do.
    219 	 */
    220 	if (mp->mnt_flag & MNT_UPDATE) {
    221 		fcmp = VFSTOFILECORE(mp);
    222 		if (args.fspec == 0)
    223 			return (vfs_export(mp, &fcmp->fc_export, &args.export));
    224 	}
    225 	/*
    226 	 * Not an update, or updating the name: look up the name
    227 	 * and verify that it refers to a sensible block device.
    228 	 */
    229 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
    230 	if ((error = namei(ndp)) != 0)
    231 		return (error);
    232 	devvp = ndp->ni_vp;
    233 
    234 	if (devvp->v_type != VBLK) {
    235 		vrele(devvp);
    236 		return ENOTBLK;
    237 	}
    238 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    239 		vrele(devvp);
    240 		return ENXIO;
    241 	}
    242 	/*
    243 	 * If mount by non-root, then verify that user has necessary
    244 	 * permissions on the device.
    245 	 */
    246 	if (p->p_ucred->cr_uid != 0) {
    247 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    248 		error = VOP_ACCESS(devvp, VREAD, p->p_ucred, l);
    249 		VOP_UNLOCK(devvp, 0);
    250 		if (error) {
    251 			vrele(devvp);
    252 			return (error);
    253 		}
    254 	}
    255 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
    256 		error = filecore_mountfs(devvp, mp, l, &args);
    257 	else {
    258 		if (devvp != fcmp->fc_devvp)
    259 			error = EINVAL;	/* needs translation */
    260 		else
    261 			vrele(devvp);
    262 	}
    263 	if (error) {
    264 		vrele(devvp);
    265 		return error;
    266 	}
    267 	fcmp = VFSTOFILECORE(mp);
    268 	return set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
    269 	    mp, l);
    270 }
    271 
    272 /*
    273  * Common code for mount and mountroot
    274  */
    275 static int
    276 filecore_mountfs(devvp, mp, l, argp)
    277 	struct vnode *devvp;
    278 	struct mount *mp;
    279 	struct lwp *l;
    280 	struct filecore_args *argp;
    281 {
    282 	struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
    283 	struct buf *bp = NULL;
    284 	dev_t dev = devvp->v_rdev;
    285 	int error = EINVAL;
    286 	int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
    287 	extern struct vnode *rootvp;
    288 	struct filecore_disc_record *fcdr;
    289 	unsigned map;
    290 	unsigned log2secsize;
    291 
    292 	if (!ronly)
    293 		return EROFS;
    294 
    295 	/*
    296 	 * Disallow multiple mounts of the same device.
    297 	 * Disallow mounting of a device that is currently in use
    298 	 * (except for root, which might share swap device for miniroot).
    299 	 * Flush out any old buffers remaining from a previous use.
    300 	 */
    301 	if ((error = vfs_mountedon(devvp)) != 0)
    302 		return error;
    303 	if (vcount(devvp) > 1 && devvp != rootvp)
    304 		return EBUSY;
    305 	if ((error = vinvalbuf(devvp, V_SAVE, l->l_proc->p_ucred, l, 0, 0))
    306 	    != 0)
    307 		return (error);
    308 
    309 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, l);
    310 	if (error)
    311 		return error;
    312 
    313 	/* Read the filecore boot block to check FS validity and to find the map */
    314 	error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
    315 			   FILECORE_BOOTBLOCK_SIZE, NOCRED, &bp);
    316 #ifdef FILECORE_DEBUG_BR
    317 		printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
    318 		       FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
    319 		       bp, error);
    320 #endif
    321 	if (error != 0)
    322 		goto out;
    323 	if (filecore_bbchecksum(bp->b_data) != 0) {
    324 		error = EINVAL;
    325 		goto out;
    326 	}
    327 	fcdr = (struct filecore_disc_record *)(bp->b_data+FILECORE_BB_DISCREC);
    328 	map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
    329 	    * (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
    330 	    << fcdr->log2bpmb) >> fcdr->log2secsize;
    331 	log2secsize = fcdr->log2secsize;
    332 	bp->b_flags |= B_AGE;
    333 #ifdef FILECORE_DEBUG_BR
    334 	printf("brelse(%p) vf1\n", bp);
    335 #endif
    336 	brelse(bp);
    337 	bp = NULL;
    338 
    339 	/* Read the bootblock in the map */
    340 	error = bread(devvp, map, 1 << log2secsize, NOCRED, &bp);
    341 #ifdef FILECORE_DEBUG_BR
    342 		printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
    343 		       map, 1 << log2secsize, bp, error);
    344 #endif
    345 	if (error != 0)
    346 		goto out;
    347        	fcdr = (struct filecore_disc_record *)(bp->b_data + 4);
    348 	fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK);
    349 	memset(fcmp, 0, sizeof *fcmp);
    350 	if (fcdr->log2bpmb > fcdr->log2secsize)
    351 		fcmp->log2bsize = fcdr->log2bpmb;
    352 	else	fcmp->log2bsize = fcdr->log2secsize;
    353 	fcmp->blksize = 1 << fcmp->log2bsize;
    354 	memcpy(&fcmp->drec, fcdr, sizeof(*fcdr));
    355 	fcmp->map = map;
    356 	fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
    357 	    / (fcdr->idlen + 1);
    358 	fcmp->mask = (1 << fcdr->idlen) - 1;
    359 	if (fcdr->big_flag & 1) {
    360 		fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
    361 		    + fcdr->disc_size) / fcmp->blksize;
    362 	} else {
    363 		fcmp->nblks=fcdr->disc_size / fcmp->blksize;
    364 	}
    365 
    366 	bp->b_flags |= B_AGE;
    367 #ifdef FILECORE_DEBUG_BR
    368 	printf("brelse(%p) vf2\n", bp);
    369 #endif
    370 	brelse(bp);
    371 	bp = NULL;
    372 
    373 	mp->mnt_data = fcmp;
    374 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
    375 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FILECORE);
    376 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    377 	mp->mnt_maxsymlinklen = 0;
    378 	mp->mnt_flag |= MNT_LOCAL;
    379 	mp->mnt_dev_bshift = fcdr->log2secsize;
    380 	mp->mnt_fs_bshift = fcmp->log2bsize;
    381 
    382 	fcmp->fc_mountp = mp;
    383 	fcmp->fc_dev = dev;
    384 	fcmp->fc_devvp = devvp;
    385 	fcmp->fc_mntflags = argp->flags;
    386 	if (argp->flags & FILECOREMNT_USEUID) {
    387 		fcmp->fc_uid = l->l_proc->p_cred->p_ruid;
    388 		fcmp->fc_gid = l->l_proc->p_cred->p_rgid;
    389 	} else {
    390 		fcmp->fc_uid = argp->uid;
    391 		fcmp->fc_gid = argp->gid;
    392 	}
    393 
    394 	return 0;
    395 out:
    396 	if (bp) {
    397 #ifdef FILECORE_DEBUG_BR
    398 		printf("brelse(%p) vf3\n", bp);
    399 #endif
    400 		brelse(bp);
    401 	}
    402 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    403 	(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, l);
    404 	VOP_UNLOCK(devvp, 0);
    405 	if (fcmp) {
    406 		free(fcmp, M_FILECOREMNT);
    407 		mp->mnt_data = NULL;
    408 	}
    409 	return error;
    410 }
    411 
    412 /*
    413  * Make a filesystem operational.
    414  * Nothing to do at the moment.
    415  */
    416 /* ARGSUSED */
    417 int
    418 filecore_start(mp, flags, l)
    419 	struct mount *mp;
    420 	int flags;
    421 	struct lwp *l;
    422 {
    423 	return 0;
    424 }
    425 
    426 /*
    427  * unmount system call
    428  */
    429 int
    430 filecore_unmount(mp, mntflags, l)
    431 	struct mount *mp;
    432 	int mntflags;
    433 	struct lwp *l;
    434 {
    435 	struct filecore_mnt *fcmp;
    436 	int error, flags = 0;
    437 
    438 	if (mntflags & MNT_FORCE)
    439 		flags |= FORCECLOSE;
    440 #if 0
    441 	mntflushbuf(mp, 0);
    442 	if (mntinvalbuf(mp))
    443 		return EBUSY;
    444 #endif
    445 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    446 		return (error);
    447 
    448 	fcmp = VFSTOFILECORE(mp);
    449 
    450 	if (fcmp->fc_devvp->v_type != VBAD)
    451 		fcmp->fc_devvp->v_specmountpoint = NULL;
    452 	vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
    453 	error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED, l);
    454 	vput(fcmp->fc_devvp);
    455 	free(fcmp, M_FILECOREMNT);
    456 	mp->mnt_data = NULL;
    457 	mp->mnt_flag &= ~MNT_LOCAL;
    458 	return (error);
    459 }
    460 
    461 /*
    462  * Return root of a filesystem
    463  */
    464 int
    465 filecore_root(mp, vpp, l)
    466 	struct mount *mp;
    467 	struct vnode **vpp;
    468 	struct lwp *l;
    469 {
    470 	struct vnode *nvp;
    471         int error;
    472 
    473         if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp)) != 0)
    474                 return (error);
    475         *vpp = nvp;
    476         return (0);
    477 }
    478 
    479 /*
    480  * Do operations associated with quotas, not supported
    481  */
    482 /* ARGSUSED */
    483 int
    484 filecore_quotactl(mp, cmd, uid, arg, l)
    485 	struct mount *mp;
    486 	int cmd;
    487 	uid_t uid;
    488 	void *arg;
    489 	struct lwp *l;
    490 {
    491 
    492 	return (EOPNOTSUPP);
    493 }
    494 
    495 /*
    496  * Get file system statistics.
    497  */
    498 int
    499 filecore_statvfs(mp, sbp, l)
    500 	struct mount *mp;
    501 	struct statvfs *sbp;
    502 	struct lwp *l;
    503 {
    504 	struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
    505 
    506 	sbp->f_bsize = fcmp->blksize;
    507 	sbp->f_frsize = sbp->f_bsize; /* XXX */
    508 	sbp->f_iosize = sbp->f_bsize;	/* XXX */
    509 	sbp->f_blocks = fcmp->nblks;
    510 	sbp->f_bfree = 0; /* total free blocks */
    511 	sbp->f_bavail = 0; /* blocks free for non superuser */
    512 	sbp->f_bresvd = 0; /* reserved blocks */
    513 	sbp->f_files =  0; /* total files */
    514 	sbp->f_ffree = 0; /* free file nodes for non superuser */
    515 	sbp->f_favail = 0; /* free file nodes */
    516 	sbp->f_fresvd = 0; /* reserved file nodes */
    517 	copy_statvfs_info(sbp, mp);
    518 	return 0;
    519 }
    520 
    521 /* ARGSUSED */
    522 int
    523 filecore_sync(mp, waitfor, cred, l)
    524 	struct mount *mp;
    525 	int waitfor;
    526 	struct ucred *cred;
    527 	struct lwp *l;
    528 {
    529 	return (0);
    530 }
    531 
    532 /*
    533  * File handle to vnode
    534  *
    535  * Have to be really careful about stale file handles:
    536  * - check that the inode number is in range
    537  * - call iget() to get the locked inode
    538  * - check for an unallocated inode (i_mode == 0)
    539  * - check that the generation number matches
    540  */
    541 
    542 struct ifid {
    543 	ushort		ifid_len;
    544 	ushort		ifid_pad;
    545 	u_int32_t	ifid_ino;
    546 };
    547 
    548 /* ARGSUSED */
    549 int
    550 filecore_fhtovp(mp, fhp, vpp)
    551 	struct mount *mp;
    552 	struct fid *fhp;
    553 	struct vnode **vpp;
    554 {
    555 	struct ifid *ifhp = (struct ifid *)fhp;
    556 	struct vnode *nvp;
    557 	struct filecore_node *ip;
    558 	int error;
    559 
    560 	if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
    561 		*vpp = NULLVP;
    562 		return (error);
    563 	}
    564         ip = VTOI(nvp);
    565         if (filecore_staleinode(ip)) {
    566                 vput(nvp);
    567                 *vpp = NULLVP;
    568                 return (ESTALE);
    569         }
    570 	*vpp = nvp;
    571 	return (0);
    572 }
    573 
    574 /* ARGSUSED */
    575 int
    576 filecore_checkexp(mp, nam, exflagsp, credanonp)
    577 	struct mount *mp;
    578 	struct mbuf *nam;
    579 	int *exflagsp;
    580 	struct ucred **credanonp;
    581 {
    582 	struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
    583 	struct netcred *np;
    584 
    585 	/*
    586 	 * Get the export permission structure for this <mp, client> tuple.
    587 	 */
    588 	np = vfs_export_lookup(mp, &fcmp->fc_export, nam);
    589 	if (np == NULL)
    590 		return (EACCES);
    591 
    592 	*exflagsp = np->netc_exflags;
    593 	*credanonp = &np->netc_anon;
    594 	return (0);
    595 }
    596 
    597 /* This looks complicated. Look at other vgets as well as the iso9660 one.
    598  *
    599  * The filecore inode number is made up of 1 byte directory entry index and
    600  * 3 bytes of the internal disc address of the directory. On a read-only
    601  * filesystem this is unique. For a read-write version we may not be able to
    602  * do vget, see msdosfs.
    603  */
    604 
    605 int
    606 filecore_vget(mp, ino, vpp)
    607 	struct mount *mp;
    608 	ino_t ino;
    609 	struct vnode **vpp;
    610 {
    611 	struct filecore_mnt *fcmp;
    612 	struct filecore_node *ip;
    613 	struct buf *bp;
    614 	struct vnode *vp;
    615 	dev_t dev;
    616 	int error;
    617 
    618 	fcmp = VFSTOFILECORE(mp);
    619 	dev = fcmp->fc_dev;
    620 	if ((*vpp = filecore_ihashget(dev, ino)) != NULLVP)
    621 		return (0);
    622 
    623 	/* Allocate a new vnode/filecore_node. */
    624 	if ((error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, &vp))
    625 	    != 0) {
    626 		*vpp = NULLVP;
    627 		return (error);
    628 	}
    629 	ip = pool_get(&filecore_node_pool, PR_WAITOK);
    630 	memset(ip, 0, sizeof(struct filecore_node));
    631 	vp->v_data = ip;
    632 	ip->i_vnode = vp;
    633 	ip->i_dev = dev;
    634 	ip->i_number = ino;
    635 	ip->i_block = -1;
    636 	ip->i_parent = -2;
    637 
    638 	/*
    639 	 * Put it onto its hash chain and lock it so that other requests for
    640 	 * this inode will block if they arrive while we are sleeping waiting
    641 	 * for old data structures to be purged or for the contents of the
    642 	 * disk portion of this inode to be read.
    643 	 */
    644 	filecore_ihashins(ip);
    645 
    646 	if (ino == FILECORE_ROOTINO) {
    647 		/* Here we need to construct a root directory inode */
    648 		memcpy(ip->i_dirent.name, "root", 4);
    649 		ip->i_dirent.load = 0;
    650 		ip->i_dirent.exec = 0;
    651 		ip->i_dirent.len = FILECORE_DIR_SIZE;
    652 		ip->i_dirent.addr = fcmp->drec.root;
    653 		ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
    654 
    655 	} else {
    656 		/* Read in Data from Directory Entry */
    657 		if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
    658 		    FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
    659 			vput(vp);
    660 #ifdef FILECORE_DEBUG_BR
    661 			printf("brelse(%p) vf4\n", bp);
    662 #endif
    663 			brelse(bp);
    664 			*vpp = NULL;
    665 			return (error);
    666 		}
    667 
    668 		memcpy(&ip->i_dirent,
    669 		    fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
    670 		    sizeof(struct filecore_direntry));
    671 #ifdef FILECORE_DEBUG_BR
    672 		printf("brelse(%p) vf5\n", bp);
    673 #endif
    674 		brelse(bp);
    675 	}
    676 
    677 	ip->i_mnt = fcmp;
    678 	ip->i_devvp = fcmp->fc_devvp;
    679 	ip->i_diroff = 0;
    680 	VREF(ip->i_devvp);
    681 
    682 	/*
    683 	 * Setup type
    684 	 */
    685 	vp->v_type = VREG;
    686 	if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
    687 		vp->v_type = VDIR;
    688 
    689 	/*
    690 	 * Initialize the associated vnode
    691 	 */
    692 	switch (vp->v_type) {
    693 	case VFIFO:
    694 	case VCHR:
    695 	case VBLK:
    696 		/*
    697 		 * Devices not supported.
    698 		 */
    699 		vput(vp);
    700 		return (EOPNOTSUPP);
    701 	case VLNK:
    702 	case VNON:
    703 	case VSOCK:
    704 	case VDIR:
    705 	case VBAD:
    706 	case VREG:
    707 		break;
    708 	}
    709 
    710 	if (ino == FILECORE_ROOTINO)
    711 		vp->v_flag |= VROOT;
    712 
    713 	/*
    714 	 * XXX need generation number?
    715 	 */
    716 
    717 	genfs_node_init(vp, &filecore_genfsops);
    718 	vp->v_size = ip->i_size;
    719 	*vpp = vp;
    720 	return (0);
    721 }
    722 
    723 /*
    724  * Vnode pointer to File handle
    725  */
    726 /* ARGSUSED */
    727 int
    728 filecore_vptofh(vp, fhp)
    729 	struct vnode *vp;
    730 	struct fid *fhp;
    731 {
    732 	struct filecore_node *ip = VTOI(vp);
    733 	struct ifid *ifhp;
    734 
    735 	ifhp = (struct ifid *)fhp;
    736 	ifhp->ifid_len = sizeof(struct ifid);
    737 	ifhp->ifid_ino = ip->i_number;
    738        	return 0;
    739 }
    740 
    741 SYSCTL_SETUP(sysctl_vfs_filecore_setup, "sysctl vfs.filecore subtree setup")
    742 {
    743 
    744 	sysctl_createv(clog, 0, NULL, NULL,
    745 		       CTLFLAG_PERMANENT,
    746 		       CTLTYPE_NODE, "vfs", NULL,
    747 		       NULL, 0, NULL, 0,
    748 		       CTL_VFS, CTL_EOL);
    749 	sysctl_createv(clog, 0, NULL, NULL,
    750 		       CTLFLAG_PERMANENT,
    751 		       CTLTYPE_NODE, "filecore",
    752 		       SYSCTL_DESCR("Acorn FILECORE file system"),
    753 		       NULL, 0, NULL, 0,
    754 		       CTL_VFS, 19, CTL_EOL);
    755 	/*
    756 	 * XXX the "19" above could be dynamic, thereby eliminating
    757 	 * one more instance of the "number to vfs" mapping problem,
    758 	 * but "19" is the order as taken from sys/mount.h
    759 	 */
    760 }
    761