Home | History | Annotate | Line # | Download | only in filecorefs
filecore_vfsops.c revision 1.5
      1 /*	$NetBSD: filecore_vfsops.c,v 1.5 2003/06/29 22:31:09 fvdl 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 2003/06/29 22:31:09 fvdl 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 proc *p, 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, p)
    154 	struct mount *mp;
    155 	const char *path;
    156 	void *data;
    157 	struct nameidata *ndp;
    158 	struct proc *p;
    159 {
    160 	struct vnode *devvp;
    161 	struct filecore_args args;
    162 	int error;
    163 	struct filecore_mnt *fcmp = NULL;
    164 
    165 	if (mp->mnt_flag & MNT_GETARGS) {
    166 		fcmp = VFSTOFILECORE(mp);
    167 		if (fcmp == NULL)
    168 			return EIO;
    169 		args.flags = fcmp->fc_mntflags;
    170 		args.uid = fcmp->fc_uid;
    171 		args.gid = fcmp->fc_gid;
    172 		args.fspec = NULL;
    173 		vfs_showexport(mp, &args.export, &fcmp->fc_export);
    174 		return copyout(&args, data, sizeof(args));
    175 	}
    176 	error = copyin(data, (caddr_t)&args, sizeof (struct filecore_args));
    177 	if (error)
    178 		return (error);
    179 
    180 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
    181 		return (EROFS);
    182 
    183 	/*
    184 	 * If updating, check whether changing from read-only to
    185 	 * read/write; if there is no device name, that's all we do.
    186 	 */
    187 	if (mp->mnt_flag & MNT_UPDATE) {
    188 		fcmp = VFSTOFILECORE(mp);
    189 		if (args.fspec == 0)
    190 			return (vfs_export(mp, &fcmp->fc_export, &args.export));
    191 	}
    192 	/*
    193 	 * Not an update, or updating the name: look up the name
    194 	 * and verify that it refers to a sensible block device.
    195 	 */
    196 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
    197 	if ((error = namei(ndp)) != 0)
    198 		return (error);
    199 	devvp = ndp->ni_vp;
    200 
    201 	if (devvp->v_type != VBLK) {
    202 		vrele(devvp);
    203 		return ENOTBLK;
    204 	}
    205 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    206 		vrele(devvp);
    207 		return ENXIO;
    208 	}
    209 	/*
    210 	 * If mount by non-root, then verify that user has necessary
    211 	 * permissions on the device.
    212 	 */
    213 	if (p->p_ucred->cr_uid != 0) {
    214 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    215 		error = VOP_ACCESS(devvp, VREAD, p->p_ucred, p);
    216 		VOP_UNLOCK(devvp, 0);
    217 		if (error) {
    218 			vrele(devvp);
    219 			return (error);
    220 		}
    221 	}
    222 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
    223 		error = filecore_mountfs(devvp, mp, p, &args);
    224 	else {
    225 		if (devvp != fcmp->fc_devvp)
    226 			error = EINVAL;	/* needs translation */
    227 		else
    228 			vrele(devvp);
    229 	}
    230 	if (error) {
    231 		vrele(devvp);
    232 		return error;
    233 	}
    234 	fcmp = VFSTOFILECORE(mp);
    235 	return set_statfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
    236 	    mp, p);
    237 }
    238 
    239 /*
    240  * Common code for mount and mountroot
    241  */
    242 static int
    243 filecore_mountfs(devvp, mp, p, argp)
    244 	struct vnode *devvp;
    245 	struct mount *mp;
    246 	struct proc *p;
    247 	struct filecore_args *argp;
    248 {
    249 	struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
    250 	struct buf *bp = NULL;
    251 	dev_t dev = devvp->v_rdev;
    252 	int error = EINVAL;
    253 	int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
    254 	extern struct vnode *rootvp;
    255 	struct filecore_disc_record *fcdr;
    256 	unsigned map;
    257 	unsigned log2secsize;
    258 
    259 	if (!ronly)
    260 		return EROFS;
    261 
    262 	/*
    263 	 * Disallow multiple mounts of the same device.
    264 	 * Disallow mounting of a device that is currently in use
    265 	 * (except for root, which might share swap device for miniroot).
    266 	 * Flush out any old buffers remaining from a previous use.
    267 	 */
    268 	if ((error = vfs_mountedon(devvp)) != 0)
    269 		return error;
    270 	if (vcount(devvp) > 1 && devvp != rootvp)
    271 		return EBUSY;
    272 	if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) != 0)
    273 		return (error);
    274 
    275 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
    276 	if (error)
    277 		return error;
    278 
    279 	/* Read the filecore boot block to check FS validity and to find the map */
    280 	error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
    281 			   FILECORE_BOOTBLOCK_SIZE, NOCRED, &bp);
    282 #ifdef FILECORE_DEBUG_BR
    283 		printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
    284 		       FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
    285 		       bp, error);
    286 #endif
    287 	if (error != 0)
    288 		goto out;
    289 	if (filecore_bbchecksum(bp->b_data) != 0) {
    290 		error = EINVAL;
    291 		goto out;
    292 	}
    293 	fcdr = (struct filecore_disc_record *)(bp->b_data+FILECORE_BB_DISCREC);
    294 	map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
    295 	    * (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
    296 	    << fcdr->log2bpmb) >> fcdr->log2secsize;
    297 	log2secsize = fcdr->log2secsize;
    298 	bp->b_flags |= B_AGE;
    299 #ifdef FILECORE_DEBUG_BR
    300 	printf("brelse(%p) vf1\n", bp);
    301 #endif
    302 	brelse(bp);
    303 	bp = NULL;
    304 
    305 	/* Read the bootblock in the map */
    306 	error = bread(devvp, map, 1 << log2secsize, NOCRED, &bp);
    307 #ifdef FILECORE_DEBUG_BR
    308 		printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
    309 		       map, 1 << log2secsize, bp, error);
    310 #endif
    311 	if (error != 0)
    312 		goto out;
    313        	fcdr = (struct filecore_disc_record *)(bp->b_data + 4);
    314 	fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK);
    315 	memset((caddr_t)fcmp, 0, sizeof *fcmp);
    316 	if (fcdr->log2bpmb > fcdr->log2secsize)
    317 		fcmp->log2bsize = fcdr->log2bpmb;
    318 	else	fcmp->log2bsize = fcdr->log2secsize;
    319 	fcmp->blksize = 1 << fcmp->log2bsize;
    320 	memcpy((caddr_t)&fcmp->drec, (caddr_t)fcdr, sizeof(*fcdr));
    321 	fcmp->map = map;
    322 	fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
    323 	    / (fcdr->idlen + 1);
    324 	fcmp->mask = (1 << fcdr->idlen) - 1;
    325 	if (fcdr->big_flag & 1) {
    326 		fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
    327 		    + fcdr->disc_size) / fcmp->blksize;
    328 	} else {
    329 		fcmp->nblks=fcdr->disc_size / fcmp->blksize;
    330 	}
    331 
    332 	bp->b_flags |= B_AGE;
    333 #ifdef FILECORE_DEBUG_BR
    334 	printf("brelse(%p) vf2\n", bp);
    335 #endif
    336 	brelse(bp);
    337 	bp = NULL;
    338 
    339 	mp->mnt_data = fcmp;
    340 	mp->mnt_stat.f_fsid.val[0] = (long)dev;
    341 	mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_FILECORE);
    342 	mp->mnt_maxsymlinklen = 0;
    343 	mp->mnt_flag |= MNT_LOCAL;
    344 	mp->mnt_dev_bshift = fcdr->log2secsize;
    345 	mp->mnt_fs_bshift = fcmp->log2bsize;
    346 
    347 	fcmp->fc_mountp = mp;
    348 	fcmp->fc_dev = dev;
    349 	fcmp->fc_devvp = devvp;
    350 	fcmp->fc_mntflags = argp->flags;
    351 	if (argp->flags & FILECOREMNT_USEUID) {
    352 		fcmp->fc_uid = p->p_cred->p_ruid;
    353 		fcmp->fc_gid = p->p_cred->p_rgid;
    354 	} else {
    355 		fcmp->fc_uid = argp->uid;
    356 		fcmp->fc_gid = argp->gid;
    357 	}
    358 
    359 	return 0;
    360 out:
    361 	if (bp) {
    362 #ifdef FILECORE_DEBUG_BR
    363 		printf("brelse(%p) vf3\n", bp);
    364 #endif
    365 		brelse(bp);
    366 	}
    367 	vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    368 	(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
    369 	VOP_UNLOCK(devvp, 0);
    370 	if (fcmp) {
    371 		free((caddr_t)fcmp, M_FILECOREMNT);
    372 		mp->mnt_data = NULL;
    373 	}
    374 	return error;
    375 }
    376 
    377 /*
    378  * Make a filesystem operational.
    379  * Nothing to do at the moment.
    380  */
    381 /* ARGSUSED */
    382 int
    383 filecore_start(mp, flags, p)
    384 	struct mount *mp;
    385 	int flags;
    386 	struct proc *p;
    387 {
    388 	return 0;
    389 }
    390 
    391 /*
    392  * unmount system call
    393  */
    394 int
    395 filecore_unmount(mp, mntflags, p)
    396 	struct mount *mp;
    397 	int mntflags;
    398 	struct proc *p;
    399 {
    400 	struct filecore_mnt *fcmp;
    401 	int error, flags = 0;
    402 
    403 	if (mntflags & MNT_FORCE)
    404 		flags |= FORCECLOSE;
    405 #if 0
    406 	mntflushbuf(mp, 0);
    407 	if (mntinvalbuf(mp))
    408 		return EBUSY;
    409 #endif
    410 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    411 		return (error);
    412 
    413 	fcmp = VFSTOFILECORE(mp);
    414 
    415 	if (fcmp->fc_devvp->v_type != VBAD)
    416 		fcmp->fc_devvp->v_specmountpoint = NULL;
    417 	vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
    418 	error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED, p);
    419 	vput(fcmp->fc_devvp);
    420 	free((caddr_t)fcmp, M_FILECOREMNT);
    421 	mp->mnt_data = NULL;
    422 	mp->mnt_flag &= ~MNT_LOCAL;
    423 	return (error);
    424 }
    425 
    426 /*
    427  * Return root of a filesystem
    428  */
    429 int
    430 filecore_root(mp, vpp)
    431 	struct mount *mp;
    432 	struct vnode **vpp;
    433 {
    434 	struct vnode *nvp;
    435         int error;
    436 
    437         if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp)) != 0)
    438                 return (error);
    439         *vpp = nvp;
    440         return (0);
    441 }
    442 
    443 /*
    444  * Do operations associated with quotas, not supported
    445  */
    446 /* ARGSUSED */
    447 int
    448 filecore_quotactl(mp, cmd, uid, arg, p)
    449 	struct mount *mp;
    450 	int cmd;
    451 	uid_t uid;
    452 	caddr_t arg;
    453 	struct proc *p;
    454 {
    455 
    456 	return (EOPNOTSUPP);
    457 }
    458 
    459 /*
    460  * Get file system statistics.
    461  */
    462 int
    463 filecore_statfs(mp, sbp, p)
    464 	struct mount *mp;
    465 	struct statfs *sbp;
    466 	struct proc *p;
    467 {
    468 	struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
    469 
    470 #ifdef COMPAT_09
    471 	sbp->f_type = 255;
    472 #else
    473 	sbp->f_type = 0;
    474 #endif
    475 	sbp->f_bsize = fcmp->blksize;
    476 	sbp->f_iosize = sbp->f_bsize;	/* XXX */
    477 	sbp->f_blocks = fcmp->nblks;
    478 	sbp->f_bfree = 0; /* total free blocks */
    479 	sbp->f_bavail = 0; /* blocks free for non superuser */
    480 	sbp->f_files =  0; /* total files */
    481 	sbp->f_ffree = 0; /* free file nodes */
    482 	copy_statfs_info(sbp, mp);
    483 	return 0;
    484 }
    485 
    486 /* ARGSUSED */
    487 int
    488 filecore_sync(mp, waitfor, cred, p)
    489 	struct mount *mp;
    490 	int waitfor;
    491 	struct ucred *cred;
    492 	struct proc *p;
    493 {
    494 	return (0);
    495 }
    496 
    497 /*
    498  * File handle to vnode
    499  *
    500  * Have to be really careful about stale file handles:
    501  * - check that the inode number is in range
    502  * - call iget() to get the locked inode
    503  * - check for an unallocated inode (i_mode == 0)
    504  * - check that the generation number matches
    505  */
    506 
    507 struct ifid {
    508 	ushort		ifid_len;
    509 	ushort		ifid_pad;
    510 	u_int32_t	ifid_ino;
    511 };
    512 
    513 /* ARGSUSED */
    514 int
    515 filecore_fhtovp(mp, fhp, vpp)
    516 	struct mount *mp;
    517 	struct fid *fhp;
    518 	struct vnode **vpp;
    519 {
    520 	struct ifid *ifhp = (struct ifid *)fhp;
    521 	struct vnode *nvp;
    522 	struct filecore_node *ip;
    523 	int error;
    524 
    525 	if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
    526 		*vpp = NULLVP;
    527 		return (error);
    528 	}
    529         ip = VTOI(nvp);
    530         if (filecore_staleinode(ip)) {
    531                 vput(nvp);
    532                 *vpp = NULLVP;
    533                 return (ESTALE);
    534         }
    535 	*vpp = nvp;
    536 	return (0);
    537 }
    538 
    539 /* ARGSUSED */
    540 int
    541 filecore_checkexp(mp, nam, exflagsp, credanonp)
    542 	struct mount *mp;
    543 	struct mbuf *nam;
    544 	int *exflagsp;
    545 	struct ucred **credanonp;
    546 {
    547 	struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
    548 	struct netcred *np;
    549 
    550 	/*
    551 	 * Get the export permission structure for this <mp, client> tuple.
    552 	 */
    553 	np = vfs_export_lookup(mp, &fcmp->fc_export, nam);
    554 	if (np == NULL)
    555 		return (EACCES);
    556 
    557 	*exflagsp = np->netc_exflags;
    558 	*credanonp = &np->netc_anon;
    559 	return (0);
    560 }
    561 
    562 /* This looks complicated. Look at other vgets as well as the iso9660 one.
    563  *
    564  * The filecore inode number is made up of 1 byte directory entry index and
    565  * 3 bytes of the internal disc address of the directory. On a read-only
    566  * filesystem this is unique. For a read-write version we may not be able to
    567  * do vget, see msdosfs.
    568  */
    569 
    570 int
    571 filecore_vget(mp, ino, vpp)
    572 	struct mount *mp;
    573 	ino_t ino;
    574 	struct vnode **vpp;
    575 {
    576 	struct filecore_mnt *fcmp;
    577 	struct filecore_node *ip;
    578 	struct buf *bp;
    579 	struct vnode *vp;
    580 	dev_t dev;
    581 	int error;
    582 
    583 	fcmp = VFSTOFILECORE(mp);
    584 	dev = fcmp->fc_dev;
    585 	if ((*vpp = filecore_ihashget(dev, ino)) != NULLVP)
    586 		return (0);
    587 
    588 	/* Allocate a new vnode/filecore_node. */
    589 	if ((error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, &vp))
    590 	    != 0) {
    591 		*vpp = NULLVP;
    592 		return (error);
    593 	}
    594 	ip = pool_get(&filecore_node_pool, PR_WAITOK);
    595 	memset(ip, 0, sizeof(struct filecore_node));
    596 	vp->v_data = ip;
    597 	ip->i_vnode = vp;
    598 	ip->i_dev = dev;
    599 	ip->i_number = ino;
    600 	ip->i_block = -1;
    601 	ip->i_parent = -2;
    602 
    603 	/*
    604 	 * Put it onto its hash chain and lock it so that other requests for
    605 	 * this inode will block if they arrive while we are sleeping waiting
    606 	 * for old data structures to be purged or for the contents of the
    607 	 * disk portion of this inode to be read.
    608 	 */
    609 	filecore_ihashins(ip);
    610 
    611 	if (ino == FILECORE_ROOTINO) {
    612 		/* Here we need to construct a root directory inode */
    613 		memcpy((caddr_t)ip->i_dirent.name, (caddr_t)"root", 4);
    614 		ip->i_dirent.load = 0;
    615 		ip->i_dirent.exec = 0;
    616 		ip->i_dirent.len = FILECORE_DIR_SIZE;
    617 		ip->i_dirent.addr = fcmp->drec.root;
    618 		ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
    619 
    620 	} else {
    621 		/* Read in Data from Directory Entry */
    622 		if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
    623 		    FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
    624 			vput(vp);
    625 #ifdef FILECORE_DEBUG_BR
    626 			printf("brelse(%p) vf4\n", bp);
    627 #endif
    628 			brelse(bp);
    629 			*vpp = NULL;
    630 			return (error);
    631 		}
    632 
    633 		memcpy((caddr_t)&ip->i_dirent,
    634 		    (caddr_t)fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
    635 		    sizeof(struct filecore_direntry));
    636 #ifdef FILECORE_DEBUG_BR
    637 		printf("brelse(%p) vf5\n", bp);
    638 #endif
    639 		brelse(bp);
    640 	}
    641 
    642 	ip->i_mnt = fcmp;
    643 	ip->i_devvp = fcmp->fc_devvp;
    644 	ip->i_diroff = 0;
    645 	VREF(ip->i_devvp);
    646 
    647 	/*
    648 	 * Setup type
    649 	 */
    650 	vp->v_type = VREG;
    651 	if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
    652 		vp->v_type = VDIR;
    653 
    654 	/*
    655 	 * Initialize the associated vnode
    656 	 */
    657 	switch (vp->v_type) {
    658 	case VFIFO:
    659 	case VCHR:
    660 	case VBLK:
    661 		/*
    662 		 * Devices not supported.
    663 		 */
    664 		vput(vp);
    665 		return (EOPNOTSUPP);
    666 	case VLNK:
    667 	case VNON:
    668 	case VSOCK:
    669 	case VDIR:
    670 	case VBAD:
    671 	case VREG:
    672 		break;
    673 	}
    674 
    675 	if (ino == FILECORE_ROOTINO)
    676 		vp->v_flag |= VROOT;
    677 
    678 	/*
    679 	 * XXX need generation number?
    680 	 */
    681 
    682 	genfs_node_init(vp, &filecore_genfsops);
    683 	vp->v_size = ip->i_size;
    684 	*vpp = vp;
    685 	return (0);
    686 }
    687 
    688 /*
    689  * Vnode pointer to File handle
    690  */
    691 /* ARGSUSED */
    692 int
    693 filecore_vptofh(vp, fhp)
    694 	struct vnode *vp;
    695 	struct fid *fhp;
    696 {
    697 	struct filecore_node *ip = VTOI(vp);
    698 	struct ifid *ifhp;
    699 
    700 	ifhp = (struct ifid *)fhp;
    701 	ifhp->ifid_len = sizeof(struct ifid);
    702 	ifhp->ifid_ino = ip->i_number;
    703        	return 0;
    704 }
    705 
    706 int
    707 filecore_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
    708 	int *name;
    709 	u_int namelen;
    710 	void *oldp;
    711 	size_t *oldlenp;
    712 	void *newp;
    713 	size_t newlen;
    714 	struct proc *p;
    715 {
    716 	return (EOPNOTSUPP);
    717 }
    718