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