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