filecore_vfsops.c revision 1.76 1 /* $NetBSD: filecore_vfsops.c,v 1.76 2014/04/16 18:55:18 maxv 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.76 2014/04/16 18:55:18 maxv 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 (args == NULL)
233 return EINVAL;
234 if (*data_len < sizeof *args)
235 return EINVAL;
236
237 if (mp->mnt_flag & MNT_GETARGS) {
238 fcmp = VFSTOFILECORE(mp);
239 if (fcmp == NULL)
240 return EIO;
241 args->flags = fcmp->fc_mntflags;
242 args->uid = fcmp->fc_uid;
243 args->gid = fcmp->fc_gid;
244 args->fspec = NULL;
245 *data_len = sizeof *args;
246 return 0;
247 }
248
249 if ((mp->mnt_flag & MNT_RDONLY) == 0)
250 return (EROFS);
251
252 if ((mp->mnt_flag & MNT_UPDATE) && args->fspec == NULL)
253 return EINVAL;
254
255 /*
256 * Not an update, or updating the name: look up the name
257 * and verify that it refers to a sensible block device.
258 */
259 error = namei_simple_user(args->fspec,
260 NSM_FOLLOW_NOEMULROOT, &devvp);
261 if (error != 0)
262 return (error);
263
264 if (devvp->v_type != VBLK) {
265 vrele(devvp);
266 return ENOTBLK;
267 }
268 if (bdevsw_lookup(devvp->v_rdev) == NULL) {
269 vrele(devvp);
270 return ENXIO;
271 }
272 /*
273 * If mount by non-root, then verify that user has necessary
274 * permissions on the device.
275 */
276 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
277 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
278 KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp, KAUTH_ARG(VREAD));
279 VOP_UNLOCK(devvp);
280 if (error) {
281 vrele(devvp);
282 return (error);
283 }
284 if ((mp->mnt_flag & MNT_UPDATE) == 0)
285 error = filecore_mountfs(devvp, mp, l, args);
286 else {
287 fcmp = VFSTOFILECORE(mp);
288 if (devvp != fcmp->fc_devvp)
289 error = EINVAL; /* needs translation */
290 else
291 vrele(devvp);
292 }
293 if (error) {
294 vrele(devvp);
295 return error;
296 }
297 fcmp = VFSTOFILECORE(mp);
298 return set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
299 mp->mnt_op->vfs_name, mp, l);
300 }
301
302 /*
303 * Common code for mount and mountroot
304 */
305 static int
306 filecore_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, struct filecore_args *argp)
307 {
308 struct filecore_mnt *fcmp = (struct filecore_mnt *)0;
309 struct buf *bp = NULL;
310 dev_t dev = devvp->v_rdev;
311 int error = EINVAL;
312 int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
313 struct filecore_disc_record *fcdr;
314 unsigned map;
315 unsigned log2secsize;
316
317 if (!ronly)
318 return EROFS;
319
320 if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)) != 0)
321 return (error);
322
323 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
324 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED);
325 VOP_UNLOCK(devvp);
326 if (error)
327 return error;
328
329 /* Read the filecore boot block to check FS validity and to find the map */
330 error = bread(devvp, FILECORE_BOOTBLOCK_BLKN,
331 FILECORE_BOOTBLOCK_SIZE, NOCRED, 0, &bp);
332 #ifdef FILECORE_DEBUG_BR
333 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
334 FILECORE_BOOTBLOCK_BLKN, FILECORE_BOOTBLOCK_SIZE,
335 bp, error);
336 #endif
337 if (error != 0)
338 goto out;
339
340 KASSERT(bp != NULL);
341 if (filecore_bbchecksum(bp->b_data) != 0) {
342 error = EINVAL;
343 goto out;
344 }
345 fcdr = (struct filecore_disc_record *)((char *)(bp->b_data) +
346 FILECORE_BB_DISCREC);
347 map = ((((8 << fcdr->log2secsize) - fcdr->zone_spare)
348 * (fcdr->nzones / 2) - 8 * FILECORE_DISCREC_SIZE)
349 << fcdr->log2bpmb) >> fcdr->log2secsize;
350 log2secsize = fcdr->log2secsize;
351 #ifdef FILECORE_DEBUG_BR
352 printf("brelse(%p) vf1\n", bp);
353 #endif
354 brelse(bp, BC_AGE);
355 bp = NULL;
356
357 /* Read the bootblock in the map */
358 error = bread(devvp, map, 1 << log2secsize, NOCRED, 0, &bp);
359 #ifdef FILECORE_DEBUG_BR
360 printf("bread(%p, %x, %d, CRED, %p)=%d\n", devvp,
361 map, 1 << log2secsize, bp, error);
362 #endif
363 if (error != 0)
364 goto out;
365 fcdr = (struct filecore_disc_record *)((char *)(bp->b_data) + 4);
366 fcmp = kmem_zalloc(sizeof(*fcmp), KM_SLEEP);
367 if (fcdr->log2bpmb > fcdr->log2secsize)
368 fcmp->log2bsize = fcdr->log2bpmb;
369 else fcmp->log2bsize = fcdr->log2secsize;
370 fcmp->blksize = 1 << fcmp->log2bsize;
371 memcpy(&fcmp->drec, fcdr, sizeof(*fcdr));
372 fcmp->map = map;
373 fcmp->idspz = ((8 << fcdr->log2secsize) - fcdr->zone_spare)
374 / (fcdr->idlen + 1);
375 fcmp->mask = (1 << fcdr->idlen) - 1;
376 if (fcdr->big_flag & 1) {
377 fcmp->nblks = ((((u_int64_t)fcdr->disc_size_2) << 32)
378 + fcdr->disc_size) / fcmp->blksize;
379 } else {
380 fcmp->nblks=fcdr->disc_size / fcmp->blksize;
381 }
382
383 #ifdef FILECORE_DEBUG_BR
384 printf("brelse(%p) vf2\n", bp);
385 #endif
386 brelse(bp, BC_AGE);
387 bp = NULL;
388
389 mp->mnt_data = fcmp;
390 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
391 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_FILECORE);
392 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
393 mp->mnt_stat.f_namemax = 10;
394 mp->mnt_flag |= MNT_LOCAL;
395 mp->mnt_dev_bshift = fcdr->log2secsize;
396 mp->mnt_fs_bshift = fcmp->log2bsize;
397
398 fcmp->fc_mountp = mp;
399 fcmp->fc_dev = dev;
400 fcmp->fc_devvp = devvp;
401 fcmp->fc_mntflags = argp->flags;
402 if (argp->flags & FILECOREMNT_USEUID) {
403 fcmp->fc_uid = kauth_cred_getuid(l->l_cred);
404 fcmp->fc_gid = kauth_cred_getgid(l->l_cred);
405 } else {
406 fcmp->fc_uid = argp->uid;
407 fcmp->fc_gid = argp->gid;
408 }
409
410 return 0;
411 out:
412 if (bp) {
413 #ifdef FILECORE_DEBUG_BR
414 printf("brelse(%p) vf3\n", bp);
415 #endif
416 brelse(bp, 0);
417 }
418 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
419 (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED);
420 VOP_UNLOCK(devvp);
421 return error;
422 }
423
424 /*
425 * Make a filesystem operational.
426 * Nothing to do at the moment.
427 */
428 /* ARGSUSED */
429 int
430 filecore_start(struct mount *mp, int flags)
431 {
432 return 0;
433 }
434
435 /*
436 * unmount system call
437 */
438 int
439 filecore_unmount(struct mount *mp, int mntflags)
440 {
441 struct filecore_mnt *fcmp;
442 int error, flags = 0;
443
444 if (mntflags & MNT_FORCE)
445 flags |= FORCECLOSE;
446 if ((error = vflush(mp, NULLVP, flags)) != 0)
447 return (error);
448
449 fcmp = VFSTOFILECORE(mp);
450
451 if (fcmp->fc_devvp->v_type != VBAD)
452 spec_node_setmountedfs(fcmp->fc_devvp, NULL);
453 vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY);
454 error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED);
455 vput(fcmp->fc_devvp);
456 kmem_free(fcmp, sizeof(*fcmp));
457 mp->mnt_data = NULL;
458 mp->mnt_flag &= ~MNT_LOCAL;
459 return (error);
460 }
461
462 /*
463 * Return root of a filesystem
464 */
465 int
466 filecore_root(struct mount *mp, struct vnode **vpp)
467 {
468 struct vnode *nvp;
469 int error;
470
471 if ((error = VFS_VGET(mp, FILECORE_ROOTINO, &nvp)) != 0)
472 return (error);
473 *vpp = nvp;
474 return (0);
475 }
476
477 /*
478 * Get file system statistics.
479 */
480 int
481 filecore_statvfs(struct mount *mp, struct statvfs *sbp)
482 {
483 struct filecore_mnt *fcmp = VFSTOFILECORE(mp);
484
485 sbp->f_bsize = fcmp->blksize;
486 sbp->f_frsize = sbp->f_bsize; /* XXX */
487 sbp->f_iosize = sbp->f_bsize; /* XXX */
488 sbp->f_blocks = fcmp->nblks;
489 sbp->f_bfree = 0; /* total free blocks */
490 sbp->f_bavail = 0; /* blocks free for non superuser */
491 sbp->f_bresvd = 0; /* reserved blocks */
492 sbp->f_files = 0; /* total files */
493 sbp->f_ffree = 0; /* free file nodes for non superuser */
494 sbp->f_favail = 0; /* free file nodes */
495 sbp->f_fresvd = 0; /* reserved file nodes */
496 copy_statvfs_info(sbp, mp);
497 return 0;
498 }
499
500 /* ARGSUSED */
501 int
502 filecore_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
503 {
504 return (0);
505 }
506
507 /*
508 * File handle to vnode
509 *
510 * Have to be really careful about stale file handles:
511 * - check that the inode number is in range
512 * - call iget() to get the locked inode
513 * - check for an unallocated inode (i_mode == 0)
514 * - check that the generation number matches
515 */
516
517 struct ifid {
518 ushort ifid_len;
519 ushort ifid_pad;
520 u_int32_t ifid_ino;
521 };
522
523 /* ARGSUSED */
524 int
525 filecore_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
526 {
527 struct ifid ifh;
528 struct vnode *nvp;
529 struct filecore_node *ip;
530 int error;
531
532 if (fhp->fid_len != sizeof(struct ifid))
533 return EINVAL;
534
535 memcpy(&ifh, fhp, sizeof(ifh));
536 if ((error = VFS_VGET(mp, ifh.ifid_ino, &nvp)) != 0) {
537 *vpp = NULLVP;
538 return (error);
539 }
540 ip = VTOI(nvp);
541 if (filecore_staleinode(ip)) {
542 vput(nvp);
543 *vpp = NULLVP;
544 return (ESTALE);
545 }
546 *vpp = nvp;
547 return (0);
548 }
549
550 /* This looks complicated. Look at other vgets as well as the iso9660 one.
551 *
552 * The filecore inode number is made up of 1 byte directory entry index and
553 * 3 bytes of the internal disc address of the directory. On a read-only
554 * filesystem this is unique. For a read-write version we may not be able to
555 * do vget, see msdosfs.
556 */
557
558 int
559 filecore_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
560 {
561 struct filecore_mnt *fcmp;
562 struct filecore_node *ip;
563 struct buf *bp;
564 struct vnode *vp;
565 dev_t dev;
566 int error;
567
568 fcmp = VFSTOFILECORE(mp);
569 dev = fcmp->fc_dev;
570 if ((*vpp = filecore_ihashget(dev, ino)) != NULLVP)
571 return (0);
572
573 /* Allocate a new vnode/filecore_node. */
574 error = getnewvnode(VT_FILECORE, mp, filecore_vnodeop_p, NULL, &vp);
575 if (error) {
576 *vpp = NULLVP;
577 return (error);
578 }
579 ip = pool_get(&filecore_node_pool, PR_WAITOK);
580 memset(ip, 0, sizeof(struct filecore_node));
581 vp->v_data = ip;
582 ip->i_vnode = vp;
583 ip->i_dev = dev;
584 ip->i_number = ino;
585 ip->i_block = -1;
586 ip->i_parent = -2;
587 genfs_node_init(vp, &filecore_genfsops);
588
589 /*
590 * Put it onto its hash chain and lock it so that other requests for
591 * this inode will block if they arrive while we are sleeping waiting
592 * for old data structures to be purged or for the contents of the
593 * disk portion of this inode to be read.
594 */
595 filecore_ihashins(ip);
596
597 if (ino == FILECORE_ROOTINO) {
598 /* Here we need to construct a root directory inode */
599 memcpy(ip->i_dirent.name, "root", 4);
600 ip->i_dirent.load = 0;
601 ip->i_dirent.exec = 0;
602 ip->i_dirent.len = FILECORE_DIR_SIZE;
603 ip->i_dirent.addr = fcmp->drec.root;
604 ip->i_dirent.attr = FILECORE_ATTR_DIR | FILECORE_ATTR_READ;
605
606 } else {
607 /* Read in Data from Directory Entry */
608 if ((error = filecore_bread(fcmp, ino & FILECORE_INO_MASK,
609 FILECORE_DIR_SIZE, NOCRED, &bp)) != 0) {
610 vput(vp);
611 *vpp = NULL;
612 return (error);
613 }
614
615 memcpy(&ip->i_dirent,
616 fcdirentry(bp->b_data, ino >> FILECORE_INO_INDEX),
617 sizeof(struct filecore_direntry));
618 #ifdef FILECORE_DEBUG_BR
619 printf("brelse(%p) vf5\n", bp);
620 #endif
621 brelse(bp, 0);
622 }
623
624 ip->i_mnt = fcmp;
625 ip->i_devvp = fcmp->fc_devvp;
626 ip->i_diroff = 0;
627 vref(ip->i_devvp);
628
629 /*
630 * Setup type
631 */
632 vp->v_type = VREG;
633 if (ip->i_dirent.attr & FILECORE_ATTR_DIR)
634 vp->v_type = VDIR;
635
636 /*
637 * Initialize the associated vnode
638 */
639 switch (vp->v_type) {
640 case VFIFO:
641 case VCHR:
642 case VBLK:
643 /*
644 * Devices not supported.
645 */
646 vput(vp);
647 return (EOPNOTSUPP);
648 case VLNK:
649 case VNON:
650 case VSOCK:
651 case VDIR:
652 case VBAD:
653 case VREG:
654 break;
655 }
656
657 if (ino == FILECORE_ROOTINO)
658 vp->v_vflag |= VV_ROOT;
659
660 /*
661 * XXX need generation number?
662 */
663
664 uvm_vnp_setsize(vp, ip->i_size);
665 *vpp = vp;
666 return (0);
667 }
668
669 /*
670 * Vnode pointer to File handle
671 */
672 /* ARGSUSED */
673 int
674 filecore_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
675 {
676 struct filecore_node *ip = VTOI(vp);
677 struct ifid ifh;
678
679 if (*fh_size < sizeof(struct ifid)) {
680 *fh_size = sizeof(struct ifid);
681 return E2BIG;
682 }
683 memset(&ifh, 0, sizeof(ifh));
684 ifh.ifid_len = sizeof(struct ifid);
685 ifh.ifid_ino = ip->i_number;
686 memcpy(fhp, &ifh, sizeof(ifh));
687 return 0;
688 }
689