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