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