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