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