Home | History | Annotate | Line # | Download | only in filecorefs
filecore_vfsops.c revision 1.32.4.1
      1 /*	$NetBSD: filecore_vfsops.c,v 1.32.4.1 2007/07/11 20:09:21 mjf 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.32.4.1 2007/07/11 20:09:21 mjf 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 #include <sys/kauth.h>
     91 
     92 #include <fs/filecorefs/filecore.h>
     93 #include <fs/filecorefs/filecore_extern.h>
     94 #include <fs/filecorefs/filecore_node.h>
     95 #include <fs/filecorefs/filecore_mount.h>
     96 
     97 MALLOC_JUSTDEFINE(M_FILECOREMNT,
     98     "filecore mount", "Filecore FS mount structures");
     99 
    100 extern const struct vnodeopv_desc filecore_vnodeop_opv_desc;
    101 
    102 const struct vnodeopv_desc * const filecore_vnodeopv_descs[] = {
    103 	&filecore_vnodeop_opv_desc,
    104 	NULL,
    105 };
    106 
    107 struct vfsops filecore_vfsops = {
    108 	MOUNT_FILECORE,
    109 	filecore_mount,
    110 	filecore_start,
    111 	filecore_unmount,
    112 	filecore_root,
    113 	filecore_quotactl,
    114 	filecore_statvfs,
    115 	filecore_sync,
    116 	filecore_vget,
    117 	filecore_fhtovp,
    118 	filecore_vptofh,
    119 	filecore_init,
    120 	filecore_reinit,
    121 	filecore_done,
    122 	NULL,				/* filecore_mountroot */
    123 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    124 	vfs_stdextattrctl,
    125 	vfs_stdsuspendctl,
    126 	filecore_vnodeopv_descs,
    127 	0,
    128 	{ NULL, NULL }
    129 };
    130 VFS_ATTACH(filecore_vfsops);
    131 
    132 static const struct genfs_ops filecore_genfsops = {
    133 	.gop_size = genfs_size,
    134 };
    135 
    136 /*
    137  * Called by vfs_mountroot when iso is going to be mounted as root.
    138  *
    139  * Name is updated by mount(8) after booting.
    140  */
    141 
    142 static int filecore_mountfs __P((struct vnode *devvp, struct mount *mp,
    143 		struct lwp *l, struct filecore_args *argp));
    144 
    145 #if 0
    146 int
    147 filecore_mountroot()
    148 {
    149 	struct mount *mp;
    150 	extern struct vnode *rootvp;
    151 	struct proc *p = curproc;	/* XXX */
    152 	int error;
    153 	struct filecore_args args;
    154 
    155 	if (device_class(root_device) != DV_DISK)
    156 		return (ENODEV);
    157 
    158 	/*
    159 	 * Get vnodes for swapdev and rootdev.
    160 	 */
    161 	if (bdevvp(rootdev, &rootvp))
    162 		panic("filecore_mountroot: can't setup rootvp");
    163 
    164 	if ((error = vfs_rootmountalloc(MOUNT_FILECORE, "root_device", &mp)) != 0)
    165 		return (error);
    166 
    167 	args.flags = FILECOREMNT_ROOT;
    168 	if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
    169 		mp->mnt_op->vfs_refcount--;
    170 		vfs_unbusy(mp);
    171 		free(mp, M_MOUNT);
    172 		return (error);
    173 	}
    174 	simple_lock(&mountlist_slock);
    175 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    176 	simple_unlock(&mountlist_slock);
    177 	(void)filecore_statvfs(mp, &mp->mnt_stat, p);
    178 	vfs_unbusy(mp);
    179 	return (0);
    180 }
    181 #endif
    182 
    183 /*
    184  * VFS Operations.
    185  *
    186  * mount system call
    187  */
    188 int
    189 filecore_mount(mp, path, data, ndp, l)
    190 	struct mount *mp;
    191 	const char *path;
    192 	void *data;
    193 	struct nameidata *ndp;
    194 	struct lwp *l;
    195 {
    196 	struct vnode *devvp;
    197 	struct filecore_args args;
    198 	int error;
    199 	struct filecore_mnt *fcmp = NULL;
    200 
    201 	if (mp->mnt_flag & MNT_GETARGS) {
    202 		fcmp = VFSTOFILECORE(mp);
    203 		if (fcmp == NULL)
    204 			return EIO;
    205 		args.flags = fcmp->fc_mntflags;
    206 		args.uid = fcmp->fc_uid;
    207 		args.gid = fcmp->fc_gid;
    208 		args.fspec = NULL;
    209 		return copyout(&args, data, sizeof(args));
    210 	}
    211 	error = copyin(data, &args, sizeof (struct filecore_args));
    212 	if (error)
    213 		return (error);
    214 
    215 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
    216 		return (EROFS);
    217 
    218 	if ((mp->mnt_flag & MNT_UPDATE) && args.fspec == NULL)
    219 		return EINVAL;
    220 
    221 	/*
    222 	 * Not an update, or updating the name: look up the name
    223 	 * and verify that it refers to a sensible block device.
    224 	 */
    225 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
    226 	if ((error = namei(ndp)) != 0)
    227 		return (error);
    228 	devvp = ndp->ni_vp;
    229 
    230 	if (devvp->v_type != VBLK) {
    231 		vrele(devvp);
    232 		return ENOTBLK;
    233 	}
    234 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    235 		vrele(devvp);
    236 		return ENXIO;
    237 	}
    238 	/*
    239 	 * If mount by non-root, then verify that user has necessary
    240 	 * permissions on the device.
    241 	 */
    242 	if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER, NULL)) {
    243 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    244 		error = VOP_ACCESS(devvp, VREAD, l->l_cred, l);
    245 		VOP_UNLOCK(devvp, 0);
    246 		if (error) {
    247 			vrele(devvp);
    248 			return (error);
    249 		}
    250 	}
    251 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
    252 		error = filecore_mountfs(devvp, mp, l, &args);
    253 	else {
    254 		if (devvp != fcmp->fc_devvp)
    255 			error = EINVAL;	/* needs translation */
    256 		else
    257 			vrele(devvp);
    258 	}
    259 	if (error) {
    260 		vrele(devvp);
    261 		return error;
    262 	}
    263 	fcmp = VFSTOFILECORE(mp);
    264 	return set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
    265 	    mp, l);
    266 }
    267 
    268 /*
    269  * Common code for mount and mountroot
    270  */
    271 static int
    272 filecore_mountfs(devvp, mp, l, argp)
    273 	struct vnode *devvp;
    274 	struct mount *mp;
    275 	struct lwp *l;
    276 	struct filecore_args *argp;
    277 {
    278 	struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
    279 	struct buf *bp = NULL;
    280 	dev_t dev = devvp->v_rdev;
    281 	int error = EINVAL;
    282 	int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
    283 	extern struct vnode *rootvp;
    284 	struct filecore_disc_record *fcdr;
    285 	unsigned map;
    286 	unsigned log2secsize;
    287 
    288 	if (!ronly)
    289 		return EROFS;
    290 
    291 	/*
    292 	 * Disallow multiple mounts of the same device.
    293 	 * Disallow mounting of a device that is currently in use
    294 	 * (except for root, which might share swap device for miniroot).
    295 	 * Flush out any old buffers remaining from a previous use.
    296 	 */
    297 	if ((error = vfs_mountedon(devvp)) != 0)
    298 		return error;
    299 	if (vcount(devvp) > 1 && devvp != rootvp)
    300 		return EBUSY;
    301 	if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0))
    302 	    != 0)
    303 		return (error);
    304 
    305 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, l);
    306 	if (error)
    307 		return error;
    308 
    309 	/* Read the filecore boot block to check FS validity and to find the map */
    310 	error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
    311 			   FILECORE_BOOTBLOCK_SIZE, NOCRED, &bp);
    312 #ifdef FILECORE_DEBUG_BR
    313 		printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
    314 		       FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
    315 		       bp, error);
    316 #endif
    317 	if (error != 0)
    318 		goto out;
    319 
    320 	KASSERT(bp != NULL);
    321 	if (filecore_bbchecksum(bp->b_data) != 0) {
    322 		error = EINVAL;
    323 		goto out;
    324 	}
    325 	fcdr = (struct filecore_disc_record *)((char *)(bp->b_data) +
    326 	    FILECORE_BB_DISCREC);
    327 	map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
    328 	    * (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
    329 	    << fcdr->log2bpmb) >> fcdr->log2secsize;
    330 	log2secsize = fcdr->log2secsize;
    331 	bp->b_flags |= B_AGE;
    332 #ifdef FILECORE_DEBUG_BR
    333 	printf("brelse(%p) vf1\n", bp);
    334 #endif
    335 	brelse(bp);
    336 	bp = NULL;
    337 
    338 	/* Read the bootblock in the map */
    339 	error = bread(devvp, map, 1 << log2secsize, NOCRED, &bp);
    340 #ifdef FILECORE_DEBUG_BR
    341 		printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
    342 		       map, 1 << log2secsize, bp, error);
    343 #endif
    344 	if (error != 0)
    345 		goto out;
    346        	fcdr = (struct filecore_disc_record *)((char *)(bp->b_data) + 4);
    347 	fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK);
    348 	memset(fcmp, 0, sizeof *fcmp);
    349 	if (fcdr->log2bpmb > fcdr->log2secsize)
    350 		fcmp->log2bsize = fcdr->log2bpmb;
    351 	else	fcmp->log2bsize = fcdr->log2secsize;
    352 	fcmp->blksize = 1 << fcmp->log2bsize;
    353 	memcpy(&fcmp->drec, fcdr, sizeof(*fcdr));
    354 	fcmp->map = map;
    355 	fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
    356 	    / (fcdr->idlen + 1);
    357 	fcmp->mask = (1 << fcdr->idlen) - 1;
    358 	if (fcdr->big_flag & 1) {
    359 		fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
    360 		    + fcdr->disc_size) / fcmp->blksize;
    361 	} else {
    362 		fcmp->nblks=fcdr->disc_size / fcmp->blksize;
    363 	}
    364 
    365 	bp->b_flags |= B_AGE;
    366 #ifdef FILECORE_DEBUG_BR
    367 	printf("brelse(%p) vf2\n", bp);
    368 #endif
    369 	brelse(bp);
    370 	bp = NULL;
    371 
    372 	mp->mnt_data = fcmp;
    373 	mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
    374 	mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FILECORE);
    375 	mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
    376 	mp->mnt_stat.f_namemax = 10;
    377 	mp->mnt_flag |= MNT_LOCAL;
    378 	mp->mnt_dev_bshift = fcdr->log2secsize;
    379 	mp->mnt_fs_bshift = fcmp->log2bsize;
    380 
    381 	fcmp->fc_mountp = mp;
    382 	fcmp->fc_dev = dev;
    383 	fcmp->fc_devvp = devvp;
    384 	fcmp->fc_mntflags = argp->flags;
    385 	if (argp->flags & FILECOREMNT_USEUID) {
    386 		fcmp->fc_uid = kauth_cred_getuid(l->l_cred);
    387 		fcmp->fc_gid = kauth_cred_getgid(l->l_cred);
    388 	} else {
    389 		fcmp->fc_uid = argp->uid;
    390 		fcmp->fc_gid = argp->gid;
    391 	}
    392 
    393 	return 0;
    394 out:
    395 	if (bp) {
    396 #ifdef FILECORE_DEBUG_BR
    397 		printf("brelse(%p) vf3\n", bp);
    398 #endif
    399 		brelse(bp);
    400 	}
    401 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    402 	(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, l);
    403 	VOP_UNLOCK(devvp, 0);
    404 	return error;
    405 }
    406 
    407 /*
    408  * Make a filesystem operational.
    409  * Nothing to do at the moment.
    410  */
    411 /* ARGSUSED */
    412 int
    413 filecore_start(mp, flags, l)
    414 	struct mount *mp;
    415 	int flags;
    416 	struct lwp *l;
    417 {
    418 	return 0;
    419 }
    420 
    421 /*
    422  * unmount system call
    423  */
    424 int
    425 filecore_unmount(mp, mntflags, l)
    426 	struct mount *mp;
    427 	int mntflags;
    428 	struct lwp *l;
    429 {
    430 	struct filecore_mnt *fcmp;
    431 	int error, flags = 0;
    432 
    433 	if (mntflags & MNT_FORCE)
    434 		flags |= FORCECLOSE;
    435 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    436 		return (error);
    437 
    438 	fcmp = VFSTOFILECORE(mp);
    439 
    440 	if (fcmp->fc_devvp->v_type != VBAD)
    441 		fcmp->fc_devvp->v_specmountpoint = NULL;
    442 	vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
    443 	error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED, l);
    444 	vput(fcmp->fc_devvp);
    445 	free(fcmp, M_FILECOREMNT);
    446 	mp->mnt_data = NULL;
    447 	mp->mnt_flag &= ~MNT_LOCAL;
    448 	return (error);
    449 }
    450 
    451 /*
    452  * Return root of a filesystem
    453  */
    454 int
    455 filecore_root(mp, vpp)
    456 	struct mount *mp;
    457 	struct vnode **vpp;
    458 {
    459 	struct vnode *nvp;
    460         int error;
    461 
    462         if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp)) != 0)
    463                 return (error);
    464         *vpp = nvp;
    465         return (0);
    466 }
    467 
    468 /*
    469  * Do operations associated with quotas, not supported
    470  */
    471 /* ARGSUSED */
    472 int
    473 filecore_quotactl(mp, cmd, uid, arg, l)
    474 	struct mount *mp;
    475 	int cmd;
    476 	uid_t uid;
    477 	void *arg;
    478 	struct lwp *l;
    479 {
    480 
    481 	return (EOPNOTSUPP);
    482 }
    483 
    484 /*
    485  * Get file system statistics.
    486  */
    487 int
    488 filecore_statvfs(mp, sbp, l)
    489 	struct mount *mp;
    490 	struct statvfs *sbp;
    491 	struct lwp *l;
    492 {
    493 	struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
    494 
    495 	sbp->f_bsize = fcmp->blksize;
    496 	sbp->f_frsize = sbp->f_bsize; /* XXX */
    497 	sbp->f_iosize = sbp->f_bsize;	/* XXX */
    498 	sbp->f_blocks = fcmp->nblks;
    499 	sbp->f_bfree = 0; /* total free blocks */
    500 	sbp->f_bavail = 0; /* blocks free for non superuser */
    501 	sbp->f_bresvd = 0; /* reserved blocks */
    502 	sbp->f_files =  0; /* total files */
    503 	sbp->f_ffree = 0; /* free file nodes for non superuser */
    504 	sbp->f_favail = 0; /* free file nodes */
    505 	sbp->f_fresvd = 0; /* reserved file nodes */
    506 	copy_statvfs_info(sbp, mp);
    507 	return 0;
    508 }
    509 
    510 /* ARGSUSED */
    511 int
    512 filecore_sync(mp, waitfor, cred, l)
    513 	struct mount *mp;
    514 	int waitfor;
    515 	kauth_cred_t cred;
    516 	struct lwp *l;
    517 {
    518 	return (0);
    519 }
    520 
    521 /*
    522  * File handle to vnode
    523  *
    524  * Have to be really careful about stale file handles:
    525  * - check that the inode number is in range
    526  * - call iget() to get the locked inode
    527  * - check for an unallocated inode (i_mode == 0)
    528  * - check that the generation number matches
    529  */
    530 
    531 struct ifid {
    532 	ushort		ifid_len;
    533 	ushort		ifid_pad;
    534 	u_int32_t	ifid_ino;
    535 };
    536 
    537 /* ARGSUSED */
    538 int
    539 filecore_fhtovp(mp, fhp, vpp)
    540 	struct mount *mp;
    541 	struct fid *fhp;
    542 	struct vnode **vpp;
    543 {
    544 	struct ifid ifh;
    545 	struct vnode *nvp;
    546 	struct filecore_node *ip;
    547 	int error;
    548 
    549 	if (fhp->fid_len != sizeof(struct ifid))
    550 		return EINVAL;
    551 
    552 	memcpy(&ifh, fhp, sizeof(ifh));
    553 	if ((error = VFS_VGET(mp, ifh.ifid_ino, &nvp)) != 0) {
    554 		*vpp = NULLVP;
    555 		return (error);
    556 	}
    557         ip = VTOI(nvp);
    558         if (filecore_staleinode(ip)) {
    559                 vput(nvp);
    560                 *vpp = NULLVP;
    561                 return (ESTALE);
    562         }
    563 	*vpp = nvp;
    564 	return (0);
    565 }
    566 
    567 /* This looks complicated. Look at other vgets as well as the iso9660 one.
    568  *
    569  * The filecore inode number is made up of 1 byte directory entry index and
    570  * 3 bytes of the internal disc address of the directory. On a read-only
    571  * filesystem this is unique. For a read-write version we may not be able to
    572  * do vget, see msdosfs.
    573  */
    574 
    575 int
    576 filecore_vget(mp, ino, vpp)
    577 	struct mount *mp;
    578 	ino_t ino;
    579 	struct vnode **vpp;
    580 {
    581 	struct filecore_mnt *fcmp;
    582 	struct filecore_node *ip;
    583 	struct buf *bp;
    584 	struct vnode *vp;
    585 	dev_t dev;
    586 	int error;
    587 
    588 	fcmp = VFSTOFILECORE(mp);
    589 	dev = fcmp->fc_dev;
    590 	if ((*vpp = filecore_ihashget(dev, ino)) != NULLVP)
    591 		return (0);
    592 
    593 	/* Allocate a new vnode/filecore_node. */
    594 	if ((error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, &vp))
    595 	    != 0) {
    596 		*vpp = NULLVP;
    597 		return (error);
    598 	}
    599 	ip = pool_get(&filecore_node_pool, PR_WAITOK);
    600 	memset(ip, 0, sizeof(struct filecore_node));
    601 	vp->v_data = ip;
    602 	ip->i_vnode = vp;
    603 	ip->i_dev = dev;
    604 	ip->i_number = ino;
    605 	ip->i_block = -1;
    606 	ip->i_parent = -2;
    607 
    608 	/*
    609 	 * Put it onto its hash chain and lock it so that other requests for
    610 	 * this inode will block if they arrive while we are sleeping waiting
    611 	 * for old data structures to be purged or for the contents of the
    612 	 * disk portion of this inode to be read.
    613 	 */
    614 	filecore_ihashins(ip);
    615 
    616 	if (ino == FILECORE_ROOTINO) {
    617 		/* Here we need to construct a root directory inode */
    618 		memcpy(ip->i_dirent.name, "root", 4);
    619 		ip->i_dirent.load = 0;
    620 		ip->i_dirent.exec = 0;
    621 		ip->i_dirent.len = FILECORE_DIR_SIZE;
    622 		ip->i_dirent.addr = fcmp->drec.root;
    623 		ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
    624 
    625 	} else {
    626 		/* Read in Data from Directory Entry */
    627 		if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
    628 		    FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
    629 			vput(vp);
    630 #ifdef FILECORE_DEBUG_BR
    631 			printf("brelse(%p) vf4\n", bp);
    632 #endif
    633 			brelse(bp);
    634 			*vpp = NULL;
    635 			return (error);
    636 		}
    637 
    638 		memcpy(&ip->i_dirent,
    639 		    fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
    640 		    sizeof(struct filecore_direntry));
    641 #ifdef FILECORE_DEBUG_BR
    642 		printf("brelse(%p) vf5\n", bp);
    643 #endif
    644 		brelse(bp);
    645 	}
    646 
    647 	ip->i_mnt = fcmp;
    648 	ip->i_devvp = fcmp->fc_devvp;
    649 	ip->i_diroff = 0;
    650 	VREF(ip->i_devvp);
    651 
    652 	/*
    653 	 * Setup type
    654 	 */
    655 	vp->v_type = VREG;
    656 	if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
    657 		vp->v_type = VDIR;
    658 
    659 	/*
    660 	 * Initialize the associated vnode
    661 	 */
    662 	switch (vp->v_type) {
    663 	case VFIFO:
    664 	case VCHR:
    665 	case VBLK:
    666 		/*
    667 		 * Devices not supported.
    668 		 */
    669 		vput(vp);
    670 		return (EOPNOTSUPP);
    671 	case VLNK:
    672 	case VNON:
    673 	case VSOCK:
    674 	case VDIR:
    675 	case VBAD:
    676 	case VREG:
    677 		break;
    678 	}
    679 
    680 	if (ino == FILECORE_ROOTINO)
    681 		vp->v_flag |= VROOT;
    682 
    683 	/*
    684 	 * XXX need generation number?
    685 	 */
    686 
    687 	genfs_node_init(vp, &filecore_genfsops);
    688 	vp->v_size = ip->i_size;
    689 	*vpp = vp;
    690 	return (0);
    691 }
    692 
    693 /*
    694  * Vnode pointer to File handle
    695  */
    696 /* ARGSUSED */
    697 int
    698 filecore_vptofh(vp, fhp, fh_size)
    699 	struct vnode *vp;
    700 	struct fid *fhp;
    701 	size_t *fh_size;
    702 {
    703 	struct filecore_node *ip = VTOI(vp);
    704 	struct ifid ifh;
    705 
    706 	if (*fh_size < sizeof(struct ifid)) {
    707 		*fh_size = sizeof(struct ifid);
    708 		return E2BIG;
    709 	}
    710 	memset(&ifh, 0, sizeof(ifh));
    711 	ifh.ifid_len = sizeof(struct ifid);
    712 	ifh.ifid_ino = ip->i_number;
    713 	memcpy(fhp, &ifh, sizeof(ifh));
    714        	return 0;
    715 }
    716 
    717 SYSCTL_SETUP(sysctl_vfs_filecore_setup, "sysctl vfs.filecore subtree setup")
    718 {
    719 
    720 	sysctl_createv(clog, 0, NULL, NULL,
    721 		       CTLFLAG_PERMANENT,
    722 		       CTLTYPE_NODE, "vfs", NULL,
    723 		       NULL, 0, NULL, 0,
    724 		       CTL_VFS, CTL_EOL);
    725 	sysctl_createv(clog, 0, NULL, NULL,
    726 		       CTLFLAG_PERMANENT,
    727 		       CTLTYPE_NODE, "filecore",
    728 		       SYSCTL_DESCR("Acorn FILECORE file system"),
    729 		       NULL, 0, NULL, 0,
    730 		       CTL_VFS, 19, CTL_EOL);
    731 	/*
    732 	 * XXX the "19" above could be dynamic, thereby eliminating
    733 	 * one more instance of the "number to vfs" mapping problem,
    734 	 * but "19" is the order as taken from sys/mount.h
    735 	 */
    736 }
    737