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