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