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