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