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