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