1 /* $NetBSD: tmpfs_vnops.c,v 1.148 2021/10/20 03:08:17 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 2005, 2006, 2007, 2020 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code 9 * 2005 program. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * tmpfs vnode interface. 35 */ 36 37 #include <sys/cdefs.h> 38 __KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.148 2021/10/20 03:08:17 thorpej Exp $"); 39 40 #include <sys/param.h> 41 #include <sys/dirent.h> 42 #include <sys/fcntl.h> 43 #include <sys/event.h> 44 #include <sys/malloc.h> 45 #include <sys/namei.h> 46 #include <sys/stat.h> 47 #include <sys/uio.h> 48 #include <sys/unistd.h> 49 #include <sys/vnode.h> 50 #include <sys/lockf.h> 51 #include <sys/kauth.h> 52 #include <sys/atomic.h> 53 54 #include <uvm/uvm_object.h> 55 56 #include <miscfs/fifofs/fifo.h> 57 #include <miscfs/genfs/genfs.h> 58 #include <fs/tmpfs/tmpfs_vnops.h> 59 #include <fs/tmpfs/tmpfs.h> 60 61 /* 62 * vnode operations vector used for files stored in a tmpfs file system. 63 */ 64 int (**tmpfs_vnodeop_p)(void *); 65 const struct vnodeopv_entry_desc tmpfs_vnodeop_entries[] = { 66 { &vop_default_desc, vn_default_error }, 67 { &vop_parsepath_desc, genfs_parsepath }, 68 { &vop_lookup_desc, tmpfs_lookup }, 69 { &vop_create_desc, tmpfs_create }, 70 { &vop_mknod_desc, tmpfs_mknod }, 71 { &vop_open_desc, tmpfs_open }, 72 { &vop_close_desc, tmpfs_close }, 73 { &vop_access_desc, tmpfs_access }, 74 { &vop_accessx_desc, genfs_accessx }, 75 { &vop_getattr_desc, tmpfs_getattr }, 76 { &vop_setattr_desc, tmpfs_setattr }, 77 { &vop_read_desc, tmpfs_read }, 78 { &vop_write_desc, tmpfs_write }, 79 { &vop_fallocate_desc, genfs_eopnotsupp }, 80 { &vop_fdiscard_desc, genfs_eopnotsupp }, 81 { &vop_ioctl_desc, genfs_enoioctl }, 82 { &vop_fcntl_desc, genfs_fcntl }, 83 { &vop_poll_desc, genfs_poll }, 84 { &vop_kqfilter_desc, genfs_kqfilter }, 85 { &vop_revoke_desc, genfs_revoke }, 86 { &vop_mmap_desc, genfs_mmap }, 87 { &vop_fsync_desc, tmpfs_fsync }, 88 { &vop_seek_desc, genfs_seek }, 89 { &vop_remove_desc, tmpfs_remove }, 90 { &vop_link_desc, tmpfs_link }, 91 { &vop_rename_desc, tmpfs_rename }, 92 { &vop_mkdir_desc, tmpfs_mkdir }, 93 { &vop_rmdir_desc, tmpfs_rmdir }, 94 { &vop_symlink_desc, tmpfs_symlink }, 95 { &vop_readdir_desc, tmpfs_readdir }, 96 { &vop_readlink_desc, tmpfs_readlink }, 97 { &vop_abortop_desc, genfs_abortop }, 98 { &vop_inactive_desc, tmpfs_inactive }, 99 { &vop_reclaim_desc, tmpfs_reclaim }, 100 { &vop_lock_desc, genfs_lock }, 101 { &vop_unlock_desc, genfs_unlock }, 102 { &vop_bmap_desc, genfs_eopnotsupp }, 103 { &vop_strategy_desc, genfs_eopnotsupp }, 104 { &vop_print_desc, tmpfs_print }, 105 { &vop_pathconf_desc, tmpfs_pathconf }, 106 { &vop_islocked_desc, genfs_islocked }, 107 { &vop_advlock_desc, tmpfs_advlock }, 108 { &vop_bwrite_desc, genfs_nullop }, 109 { &vop_getpages_desc, tmpfs_getpages }, 110 { &vop_putpages_desc, tmpfs_putpages }, 111 { &vop_whiteout_desc, tmpfs_whiteout }, 112 { NULL, NULL } 113 }; 114 115 const struct vnodeopv_desc tmpfs_vnodeop_opv_desc = { 116 &tmpfs_vnodeop_p, tmpfs_vnodeop_entries 117 }; 118 119 /* 120 * tmpfs_lookup: path name traversal routine. 121 * 122 * Arguments: dvp (directory being searched), vpp (result), 123 * cnp (component name - path). 124 * 125 * => Caller holds a reference and lock on dvp. 126 * => We return looked-up vnode (vpp) locked, with a reference held. 127 */ 128 int 129 tmpfs_lookup(void *v) 130 { 131 struct vop_lookup_v2_args /* { 132 struct vnode *a_dvp; 133 struct vnode **a_vpp; 134 struct componentname *a_cnp; 135 } */ *ap = v; 136 vnode_t *dvp = ap->a_dvp, **vpp = ap->a_vpp; 137 struct componentname *cnp = ap->a_cnp; 138 const bool lastcn = (cnp->cn_flags & ISLASTCN) != 0; 139 tmpfs_node_t *dnode, *tnode; 140 tmpfs_dirent_t *de; 141 int cachefound, iswhiteout; 142 int error; 143 144 KASSERT(VOP_ISLOCKED(dvp)); 145 146 dnode = VP_TO_TMPFS_DIR(dvp); 147 *vpp = NULL; 148 149 /* Check accessibility of directory. */ 150 error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred); 151 if (error) { 152 goto out; 153 } 154 155 /* 156 * If requesting the last path component on a read-only file system 157 * with a write operation, deny it. 158 */ 159 if (lastcn && (dvp->v_mount->mnt_flag & MNT_RDONLY) != 0 && 160 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) { 161 error = EROFS; 162 goto out; 163 } 164 165 /* 166 * Avoid doing a linear scan of the directory if the requested 167 * directory/name couple is already in the cache. 168 */ 169 cachefound = cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen, 170 cnp->cn_nameiop, cnp->cn_flags, 171 &iswhiteout, vpp); 172 if (iswhiteout) { 173 cnp->cn_flags |= ISWHITEOUT; 174 } 175 if (cachefound && *vpp == NULLVP) { 176 /* Negative cache hit. */ 177 error = ENOENT; 178 goto out; 179 } else if (cachefound) { 180 error = 0; 181 goto out; 182 } 183 184 /* 185 * Treat an unlinked directory as empty (no "." or "..") 186 */ 187 if (dnode->tn_links == 0) { 188 KASSERT(dnode->tn_size == 0); 189 error = ENOENT; 190 goto out; 191 } 192 193 if (cnp->cn_flags & ISDOTDOT) { 194 tmpfs_node_t *pnode; 195 196 /* 197 * Lookup of ".." case. 198 */ 199 if (lastcn && cnp->cn_nameiop == RENAME) { 200 error = EINVAL; 201 goto out; 202 } 203 KASSERT(dnode->tn_type == VDIR); 204 pnode = dnode->tn_spec.tn_dir.tn_parent; 205 if (pnode == NULL) { 206 error = ENOENT; 207 goto done; 208 } 209 210 error = vcache_get(dvp->v_mount, &pnode, sizeof(pnode), vpp); 211 goto done; 212 } else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') { 213 /* 214 * Lookup of "." case. 215 */ 216 if (lastcn && cnp->cn_nameiop == RENAME) { 217 error = EISDIR; 218 goto out; 219 } 220 vref(dvp); 221 *vpp = dvp; 222 error = 0; 223 goto done; 224 } 225 226 /* 227 * Other lookup cases: perform directory scan. 228 */ 229 de = tmpfs_dir_lookup(dnode, cnp); 230 if (de == NULL || de->td_node == TMPFS_NODE_WHITEOUT) { 231 /* 232 * The entry was not found in the directory. This is valid 233 * if we are creating or renaming an entry and are working 234 * on the last component of the path name. 235 */ 236 if (lastcn && (cnp->cn_nameiop == CREATE || 237 cnp->cn_nameiop == RENAME)) { 238 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred); 239 if (error) { 240 goto out; 241 } 242 error = EJUSTRETURN; 243 } else { 244 error = ENOENT; 245 } 246 if (de) { 247 KASSERT(de->td_node == TMPFS_NODE_WHITEOUT); 248 cnp->cn_flags |= ISWHITEOUT; 249 } 250 goto done; 251 } 252 253 tnode = de->td_node; 254 255 /* 256 * If it is not the last path component and found a non-directory 257 * or non-link entry (which may itself be pointing to a directory), 258 * raise an error. 259 */ 260 if (!lastcn && tnode->tn_type != VDIR && tnode->tn_type != VLNK) { 261 error = ENOTDIR; 262 goto out; 263 } 264 265 /* Check the permissions. */ 266 if (lastcn && (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) { 267 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred); 268 if (error) 269 goto out; 270 271 if ((dnode->tn_mode & S_ISTXT) != 0) { 272 error = kauth_authorize_vnode(cnp->cn_cred, 273 KAUTH_VNODE_DELETE, tnode->tn_vnode, 274 dnode->tn_vnode, genfs_can_sticky(dvp, cnp->cn_cred, 275 dnode->tn_uid, tnode->tn_uid)); 276 if (error) { 277 error = EPERM; 278 goto out; 279 } 280 } 281 } 282 283 /* Get a vnode for the matching entry. */ 284 error = vcache_get(dvp->v_mount, &tnode, sizeof(tnode), vpp); 285 done: 286 /* 287 * Cache the result, unless request was for creation (as it does 288 * not improve the performance). 289 */ 290 if (cnp->cn_nameiop != CREATE) { 291 cache_enter(dvp, *vpp, cnp->cn_nameptr, cnp->cn_namelen, 292 cnp->cn_flags); 293 } 294 out: 295 KASSERT(VOP_ISLOCKED(dvp)); 296 297 return error; 298 } 299 300 int 301 tmpfs_create(void *v) 302 { 303 struct vop_create_v3_args /* { 304 struct vnode *a_dvp; 305 struct vnode **a_vpp; 306 struct componentname *a_cnp; 307 struct vattr *a_vap; 308 } */ *ap = v; 309 vnode_t *dvp = ap->a_dvp, **vpp = ap->a_vpp; 310 struct componentname *cnp = ap->a_cnp; 311 struct vattr *vap = ap->a_vap; 312 313 KASSERT(VOP_ISLOCKED(dvp)); 314 KASSERT(vap->va_type == VREG || vap->va_type == VSOCK); 315 return tmpfs_construct_node(dvp, vpp, vap, cnp, NULL); 316 } 317 318 int 319 tmpfs_mknod(void *v) 320 { 321 struct vop_mknod_v3_args /* { 322 struct vnode *a_dvp; 323 struct vnode **a_vpp; 324 struct componentname *a_cnp; 325 struct vattr *a_vap; 326 } */ *ap = v; 327 vnode_t *dvp = ap->a_dvp, **vpp = ap->a_vpp; 328 struct componentname *cnp = ap->a_cnp; 329 struct vattr *vap = ap->a_vap; 330 enum vtype vt = vap->va_type; 331 332 if (vt != VBLK && vt != VCHR && vt != VFIFO) { 333 *vpp = NULL; 334 return EINVAL; 335 } 336 return tmpfs_construct_node(dvp, vpp, vap, cnp, NULL); 337 } 338 339 int 340 tmpfs_open(void *v) 341 { 342 struct vop_open_args /* { 343 struct vnode *a_vp; 344 int a_mode; 345 kauth_cred_t a_cred; 346 } */ *ap = v; 347 vnode_t *vp = ap->a_vp; 348 mode_t mode = ap->a_mode; 349 tmpfs_node_t *node; 350 351 KASSERT(VOP_ISLOCKED(vp)); 352 353 node = VP_TO_TMPFS_NODE(vp); 354 355 /* If the file is marked append-only, deny write requests. */ 356 if ((node->tn_flags & APPEND) != 0 && 357 (mode & (FWRITE | O_APPEND)) == FWRITE) { 358 return EPERM; 359 } 360 return 0; 361 } 362 363 int 364 tmpfs_close(void *v) 365 { 366 struct vop_close_args /* { 367 struct vnode *a_vp; 368 int a_fflag; 369 kauth_cred_t a_cred; 370 } */ *ap = v; 371 vnode_t *vp __diagused = ap->a_vp; 372 373 KASSERT(VOP_ISLOCKED(vp)); 374 return 0; 375 } 376 377 int 378 tmpfs_access(void *v) 379 { 380 struct vop_access_args /* { 381 struct vnode *a_vp; 382 accmode_t a_accmode; 383 kauth_cred_t a_cred; 384 } */ *ap = v; 385 vnode_t *vp = ap->a_vp; 386 accmode_t accmode = ap->a_accmode; 387 kauth_cred_t cred = ap->a_cred; 388 tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp); 389 const bool writing = (accmode & VWRITE) != 0; 390 391 KASSERT(VOP_ISLOCKED(vp)); 392 393 /* Possible? */ 394 switch (vp->v_type) { 395 case VDIR: 396 case VLNK: 397 case VREG: 398 if (writing && (vp->v_mount->mnt_flag & MNT_RDONLY) != 0) { 399 return EROFS; 400 } 401 break; 402 case VBLK: 403 case VCHR: 404 case VSOCK: 405 case VFIFO: 406 break; 407 default: 408 return EINVAL; 409 } 410 if (writing && (node->tn_flags & IMMUTABLE) != 0) { 411 return EPERM; 412 } 413 414 return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(accmode, 415 vp->v_type, node->tn_mode), vp, NULL, genfs_can_access(vp, cred, 416 node->tn_uid, node->tn_gid, node->tn_mode, NULL, accmode)); 417 } 418 419 int 420 tmpfs_getattr(void *v) 421 { 422 struct vop_getattr_args /* { 423 struct vnode *a_vp; 424 struct vattr *a_vap; 425 kauth_cred_t a_cred; 426 } */ *ap = v; 427 vnode_t *vp = ap->a_vp; 428 struct vattr *vap = ap->a_vap; 429 tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp); 430 431 vattr_null(vap); 432 433 vap->va_type = vp->v_type; 434 vap->va_mode = node->tn_mode; 435 vap->va_nlink = node->tn_links; 436 vap->va_uid = node->tn_uid; 437 vap->va_gid = node->tn_gid; 438 vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0]; 439 vap->va_fileid = node->tn_id; 440 vap->va_size = node->tn_size; 441 vap->va_blocksize = PAGE_SIZE; 442 vap->va_gen = TMPFS_NODE_GEN(node); 443 vap->va_flags = node->tn_flags; 444 vap->va_rdev = (vp->v_type == VBLK || vp->v_type == VCHR) ? 445 node->tn_spec.tn_dev.tn_rdev : VNOVAL; 446 vap->va_bytes = round_page(node->tn_size); 447 vap->va_filerev = VNOVAL; 448 vap->va_vaflags = 0; 449 vap->va_spare = VNOVAL; /* XXX */ 450 451 mutex_enter(&node->tn_timelock); 452 tmpfs_update_locked(vp, 0); 453 vap->va_atime = node->tn_atime; 454 vap->va_mtime = node->tn_mtime; 455 vap->va_ctime = node->tn_ctime; 456 vap->va_birthtime = node->tn_birthtime; 457 mutex_exit(&node->tn_timelock); 458 459 return 0; 460 } 461 462 int 463 tmpfs_setattr(void *v) 464 { 465 struct vop_setattr_args /* { 466 struct vnode *a_vp; 467 struct vattr *a_vap; 468 kauth_cred_t a_cred; 469 } */ *ap = v; 470 vnode_t *vp = ap->a_vp; 471 struct vattr *vap = ap->a_vap; 472 kauth_cred_t cred = ap->a_cred; 473 lwp_t *l = curlwp; 474 int error = 0; 475 476 KASSERT(VOP_ISLOCKED(vp)); 477 478 /* Abort if any unsettable attribute is given. */ 479 if (vap->va_type != VNON || vap->va_nlink != VNOVAL || 480 vap->va_fsid != VNOVAL || vap->va_fileid != VNOVAL || 481 vap->va_blocksize != VNOVAL || vap->va_ctime.tv_sec != VNOVAL || 482 vap->va_gen != VNOVAL || vap->va_rdev != VNOVAL || 483 vap->va_bytes != VNOVAL) { 484 return EINVAL; 485 } 486 487 if (error == 0 && vap->va_flags != VNOVAL) 488 error = tmpfs_chflags(vp, vap->va_flags, cred, l); 489 490 if (error == 0 && vap->va_size != VNOVAL) 491 error = tmpfs_chsize(vp, vap->va_size, cred, l); 492 493 if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL)) 494 error = tmpfs_chown(vp, vap->va_uid, vap->va_gid, cred, l); 495 496 if (error == 0 && vap->va_mode != VNOVAL) 497 error = tmpfs_chmod(vp, vap->va_mode, cred, l); 498 499 const bool chsometime = 500 vap->va_atime.tv_sec != VNOVAL || 501 vap->va_mtime.tv_sec != VNOVAL || 502 vap->va_birthtime.tv_sec != VNOVAL; 503 if (error == 0 && chsometime) { 504 error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime, 505 &vap->va_birthtime, vap->va_vaflags, cred, l); 506 } 507 return error; 508 } 509 510 int 511 tmpfs_read(void *v) 512 { 513 struct vop_read_args /* { 514 struct vnode *a_vp; 515 struct uio *a_uio; 516 int a_ioflag; 517 kauth_cred_t a_cred; 518 } */ *ap = v; 519 vnode_t *vp = ap->a_vp; 520 struct uio *uio = ap->a_uio; 521 const int ioflag = ap->a_ioflag; 522 tmpfs_node_t *node; 523 struct uvm_object *uobj; 524 int error; 525 526 KASSERT(VOP_ISLOCKED(vp)); 527 528 if (vp->v_type == VDIR) { 529 return EISDIR; 530 } 531 if (uio->uio_offset < 0 || vp->v_type != VREG) { 532 return EINVAL; 533 } 534 535 /* Note: reading zero bytes should not update atime. */ 536 if (uio->uio_resid == 0) { 537 return 0; 538 } 539 540 node = VP_TO_TMPFS_NODE(vp); 541 uobj = node->tn_spec.tn_reg.tn_aobj; 542 error = 0; 543 544 while (error == 0 && uio->uio_resid > 0) { 545 vsize_t len; 546 547 if (node->tn_size <= uio->uio_offset) { 548 break; 549 } 550 len = MIN(node->tn_size - uio->uio_offset, uio->uio_resid); 551 if (len == 0) { 552 break; 553 } 554 error = ubc_uiomove(uobj, uio, len, IO_ADV_DECODE(ioflag), 555 UBC_READ | UBC_PARTIALOK | UBC_VNODE_FLAGS(vp)); 556 } 557 558 tmpfs_update(vp, TMPFS_UPDATE_ATIME); 559 return error; 560 } 561 562 int 563 tmpfs_write(void *v) 564 { 565 struct vop_write_args /* { 566 struct vnode *a_vp; 567 struct uio *a_uio; 568 int a_ioflag; 569 kauth_cred_t a_cred; 570 } */ *ap = v; 571 vnode_t *vp = ap->a_vp; 572 struct uio *uio = ap->a_uio; 573 const int ioflag = ap->a_ioflag; 574 tmpfs_node_t *node; 575 struct uvm_object *uobj; 576 off_t oldsize; 577 int error, ubc_flags; 578 579 KASSERT(VOP_ISLOCKED(vp)); 580 581 node = VP_TO_TMPFS_NODE(vp); 582 oldsize = node->tn_size; 583 584 if ((vp->v_mount->mnt_flag & MNT_RDONLY) != 0) { 585 error = EROFS; 586 goto out; 587 } 588 589 if (uio->uio_offset < 0 || vp->v_type != VREG) { 590 error = EINVAL; 591 goto out; 592 } 593 if (uio->uio_resid == 0) { 594 error = 0; 595 goto out; 596 } 597 if (ioflag & IO_APPEND) { 598 uio->uio_offset = node->tn_size; 599 } 600 601 if (uio->uio_offset + uio->uio_resid > node->tn_size) { 602 error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid); 603 if (error) 604 goto out; 605 } 606 607 /* 608 * If we're extending the file and have data to write that would 609 * not leave an un-zeroed hole, we can avoid fault processing and 610 * zeroing of pages on allocation. 611 * 612 * Don't do this if the file is mapped and we need to touch an 613 * existing page, because writing a mapping of the file into itself 614 * could cause a deadlock on PG_BUSY. 615 * 616 * New pages will not become visible until finished here (because 617 * of PG_BUSY and the vnode lock). 618 */ 619 ubc_flags = UBC_WRITE | UBC_VNODE_FLAGS(vp); 620 #if 0 621 /* 622 * XXX disable use of UBC_FAULTBUSY for now, this check is insufficient 623 * because it does not zero uninitialized parts of pages in all of 624 * the cases where zeroing is needed. 625 */ 626 if (uio->uio_offset >= oldsize && 627 ((uio->uio_offset & (PAGE_SIZE - 1)) == 0 || 628 ((vp->v_vflag & VV_MAPPED) == 0 && 629 trunc_page(uio->uio_offset) == trunc_page(oldsize)))) { 630 ubc_flags |= UBC_FAULTBUSY; 631 } 632 #endif 633 634 uobj = node->tn_spec.tn_reg.tn_aobj; 635 error = 0; 636 while (error == 0 && uio->uio_resid > 0) { 637 vsize_t len; 638 639 len = MIN(node->tn_size - uio->uio_offset, uio->uio_resid); 640 if (len == 0) { 641 break; 642 } 643 error = ubc_uiomove(uobj, uio, len, IO_ADV_DECODE(ioflag), 644 ubc_flags); 645 } 646 if (error) { 647 (void)tmpfs_reg_resize(vp, oldsize); 648 } 649 650 tmpfs_update(vp, TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME); 651 out: 652 if (error) { 653 KASSERT(oldsize == node->tn_size); 654 } else { 655 KASSERT(uio->uio_resid == 0); 656 } 657 return error; 658 } 659 660 int 661 tmpfs_fsync(void *v) 662 { 663 struct vop_fsync_args /* { 664 struct vnode *a_vp; 665 kauth_cred_t a_cred; 666 int a_flags; 667 off_t a_offlo; 668 off_t a_offhi; 669 struct lwp *a_l; 670 } */ *ap = v; 671 vnode_t *vp __diagused = ap->a_vp; 672 673 /* Nothing to do. Should be up to date. */ 674 KASSERT(VOP_ISLOCKED(vp)); 675 return 0; 676 } 677 678 /* 679 * tmpfs_remove: unlink a file. 680 * 681 * => Both directory (dvp) and file (vp) are locked. 682 * => We unlock and drop the reference on both. 683 */ 684 int 685 tmpfs_remove(void *v) 686 { 687 struct vop_remove_v3_args /* { 688 struct vnode *a_dvp; 689 struct vnode *a_vp; 690 struct componentname *a_cnp; 691 nlink_t ctx_vp_new_nlink; 692 } */ *ap = v; 693 vnode_t *dvp = ap->a_dvp, *vp = ap->a_vp; 694 tmpfs_node_t *dnode, *node; 695 tmpfs_dirent_t *de; 696 int error, tflags; 697 698 KASSERT(VOP_ISLOCKED(dvp)); 699 KASSERT(VOP_ISLOCKED(vp)); 700 701 if (vp->v_type == VDIR) { 702 error = EPERM; 703 goto out; 704 } 705 dnode = VP_TO_TMPFS_DIR(dvp); 706 node = VP_TO_TMPFS_NODE(vp); 707 708 /* 709 * Files marked as immutable or append-only cannot be deleted. 710 * Likewise, files residing on directories marked as append-only 711 * cannot be deleted. 712 */ 713 if (node->tn_flags & (IMMUTABLE | APPEND)) { 714 error = EPERM; 715 goto out; 716 } 717 if (dnode->tn_flags & APPEND) { 718 error = EPERM; 719 goto out; 720 } 721 722 /* Lookup the directory entry (check the cached hint first). */ 723 de = tmpfs_dir_cached(node); 724 if (de == NULL) { 725 struct componentname *cnp = ap->a_cnp; 726 de = tmpfs_dir_lookup(dnode, cnp); 727 } 728 KASSERT(de && de->td_node == node); 729 730 /* 731 * Remove the entry from the directory (drops the link count) and 732 * destroy it or replace with a whiteout. 733 * 734 * Note: the inode referred by it will not be destroyed until the 735 * vnode is reclaimed/recycled. 736 */ 737 738 tmpfs_dir_detach(dnode, de); 739 740 if (ap->a_cnp->cn_flags & DOWHITEOUT) 741 tmpfs_dir_attach(dnode, de, TMPFS_NODE_WHITEOUT); 742 else 743 tmpfs_free_dirent(VFS_TO_TMPFS(vp->v_mount), de); 744 745 tflags = TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME; 746 if (node->tn_links > 0) { 747 /* We removed a hard link. */ 748 tflags |= TMPFS_UPDATE_CTIME; 749 } 750 ap->ctx_vp_new_nlink = node->tn_links; 751 tmpfs_update(dvp, tflags); 752 error = 0; 753 out: 754 /* Drop the reference and unlock the node. */ 755 if (dvp == vp) { 756 vrele(vp); 757 } else { 758 vput(vp); 759 } 760 return error; 761 } 762 763 /* 764 * tmpfs_link: create a hard link. 765 */ 766 int 767 tmpfs_link(void *v) 768 { 769 struct vop_link_v2_args /* { 770 struct vnode *a_dvp; 771 struct vnode *a_vp; 772 struct componentname *a_cnp; 773 } */ *ap = v; 774 vnode_t *dvp = ap->a_dvp; 775 vnode_t *vp = ap->a_vp; 776 struct componentname *cnp = ap->a_cnp; 777 tmpfs_node_t *dnode, *node; 778 tmpfs_dirent_t *de; 779 int error; 780 781 KASSERT(dvp != vp); 782 KASSERT(VOP_ISLOCKED(dvp)); 783 KASSERT(vp->v_type != VDIR); 784 KASSERT(dvp->v_mount == vp->v_mount); 785 786 dnode = VP_TO_TMPFS_DIR(dvp); 787 node = VP_TO_TMPFS_NODE(vp); 788 789 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 790 791 /* Check for maximum number of links limit. */ 792 if (node->tn_links == LINK_MAX) { 793 error = EMLINK; 794 goto out; 795 } 796 KASSERT(node->tn_links < LINK_MAX); 797 798 /* We cannot create links of files marked immutable or append-only. */ 799 if (node->tn_flags & (IMMUTABLE | APPEND)) { 800 error = EPERM; 801 goto out; 802 } 803 804 /* Allocate a new directory entry to represent the inode. */ 805 error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount), 806 cnp->cn_nameptr, cnp->cn_namelen, &de); 807 if (error) { 808 goto out; 809 } 810 811 /* 812 * Insert the entry into the directory. 813 * It will increase the inode link count. 814 */ 815 tmpfs_dir_attach(dnode, de, node); 816 tmpfs_update(dvp, TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME); 817 818 /* Update the timestamps. */ 819 tmpfs_update(vp, TMPFS_UPDATE_CTIME); 820 error = 0; 821 out: 822 VOP_UNLOCK(vp); 823 return error; 824 } 825 826 int 827 tmpfs_mkdir(void *v) 828 { 829 struct vop_mkdir_v3_args /* { 830 struct vnode *a_dvp; 831 struct vnode **a_vpp; 832 struct componentname *a_cnp; 833 struct vattr *a_vap; 834 } */ *ap = v; 835 vnode_t *dvp = ap->a_dvp; 836 vnode_t **vpp = ap->a_vpp; 837 struct componentname *cnp = ap->a_cnp; 838 struct vattr *vap = ap->a_vap; 839 840 KASSERT(vap->va_type == VDIR); 841 return tmpfs_construct_node(dvp, vpp, vap, cnp, NULL); 842 } 843 844 int 845 tmpfs_rmdir(void *v) 846 { 847 struct vop_rmdir_v2_args /* { 848 struct vnode *a_dvp; 849 struct vnode *a_vp; 850 struct componentname *a_cnp; 851 } */ *ap = v; 852 vnode_t *dvp = ap->a_dvp; 853 vnode_t *vp = ap->a_vp; 854 tmpfs_mount_t *tmp = VFS_TO_TMPFS(dvp->v_mount); 855 tmpfs_node_t *dnode = VP_TO_TMPFS_DIR(dvp); 856 tmpfs_node_t *node = VP_TO_TMPFS_DIR(vp); 857 tmpfs_dirent_t *de; 858 int error = 0; 859 860 KASSERT(VOP_ISLOCKED(dvp)); 861 KASSERT(VOP_ISLOCKED(vp)); 862 863 /* 864 * Directories with more than two entries ('.' and '..') cannot be 865 * removed. There may be whiteout entries, which we will destroy. 866 */ 867 if (node->tn_size > 0) { 868 /* 869 * If never had whiteout entries, the directory is certainly 870 * not empty. Otherwise, scan for any non-whiteout entry. 871 */ 872 if ((node->tn_gen & TMPFS_WHITEOUT_BIT) == 0) { 873 error = ENOTEMPTY; 874 goto out; 875 } 876 TAILQ_FOREACH(de, &node->tn_spec.tn_dir.tn_dir, td_entries) { 877 if (de->td_node != TMPFS_NODE_WHITEOUT) { 878 error = ENOTEMPTY; 879 goto out; 880 } 881 } 882 KASSERT(error == 0); 883 } 884 885 KASSERT(node->tn_spec.tn_dir.tn_parent == dnode); 886 887 /* Lookup the directory entry (check the cached hint first). */ 888 de = tmpfs_dir_cached(node); 889 if (de == NULL) { 890 struct componentname *cnp = ap->a_cnp; 891 de = tmpfs_dir_lookup(dnode, cnp); 892 } 893 KASSERT(de && de->td_node == node); 894 895 /* Check flags to see if we are allowed to remove the directory. */ 896 if (dnode->tn_flags & APPEND || node->tn_flags & (IMMUTABLE | APPEND)) { 897 error = EPERM; 898 goto out; 899 } 900 901 /* Decrement the link count for the virtual '.' entry. */ 902 node->tn_links--; 903 904 /* Detach the directory entry from the directory. */ 905 tmpfs_dir_detach(dnode, de); 906 907 /* Purge the cache for parent. */ 908 cache_purge(dvp); 909 910 /* 911 * Destroy the directory entry or replace it with a whiteout. 912 * 913 * Note: the inode referred by it will not be destroyed until the 914 * vnode is reclaimed. 915 */ 916 if (ap->a_cnp->cn_flags & DOWHITEOUT) 917 tmpfs_dir_attach(dnode, de, TMPFS_NODE_WHITEOUT); 918 else 919 tmpfs_free_dirent(tmp, de); 920 921 /* Destroy the whiteout entries from the node. */ 922 while ((de = TAILQ_FIRST(&node->tn_spec.tn_dir.tn_dir)) != NULL) { 923 KASSERT(de->td_node == TMPFS_NODE_WHITEOUT); 924 tmpfs_dir_detach(node, de); 925 tmpfs_free_dirent(tmp, de); 926 } 927 tmpfs_update(dvp, TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME); 928 929 KASSERT(node->tn_size == 0); 930 KASSERT(node->tn_links == 0); 931 out: 932 /* Release the node. */ 933 KASSERT(dvp != vp); 934 vput(vp); 935 return error; 936 } 937 938 int 939 tmpfs_symlink(void *v) 940 { 941 struct vop_symlink_v3_args /* { 942 struct vnode *a_dvp; 943 struct vnode **a_vpp; 944 struct componentname *a_cnp; 945 struct vattr *a_vap; 946 char *a_target; 947 } */ *ap = v; 948 vnode_t *dvp = ap->a_dvp; 949 vnode_t **vpp = ap->a_vpp; 950 struct componentname *cnp = ap->a_cnp; 951 struct vattr *vap = ap->a_vap; 952 char *target = ap->a_target; 953 954 KASSERT(vap->va_type == VLNK); 955 return tmpfs_construct_node(dvp, vpp, vap, cnp, target); 956 } 957 958 int 959 tmpfs_readdir(void *v) 960 { 961 struct vop_readdir_args /* { 962 struct vnode *a_vp; 963 struct uio *a_uio; 964 kauth_cred_t a_cred; 965 int *a_eofflag; 966 off_t **a_cookies; 967 int *ncookies; 968 } */ *ap = v; 969 vnode_t *vp = ap->a_vp; 970 struct uio *uio = ap->a_uio; 971 int *eofflag = ap->a_eofflag; 972 off_t **cookies = ap->a_cookies; 973 int *ncookies = ap->a_ncookies; 974 off_t startoff, cnt; 975 tmpfs_node_t *node; 976 int error; 977 978 KASSERT(VOP_ISLOCKED(vp)); 979 980 /* This operation only makes sense on directory nodes. */ 981 if (vp->v_type != VDIR) { 982 return ENOTDIR; 983 } 984 node = VP_TO_TMPFS_DIR(vp); 985 startoff = uio->uio_offset; 986 cnt = 0; 987 988 /* 989 * Retrieve the directory entries, unless it is being destroyed. 990 */ 991 if (node->tn_links) { 992 error = tmpfs_dir_getdents(node, uio, &cnt); 993 } else { 994 error = 0; 995 } 996 997 if (eofflag != NULL) { 998 *eofflag = !error && uio->uio_offset == TMPFS_DIRSEQ_EOF; 999 } 1000 if (error || cookies == NULL || ncookies == NULL) { 1001 return error; 1002 } 1003 1004 /* Update NFS-related variables, if any. */ 1005 tmpfs_dirent_t *de = NULL; 1006 off_t i, off = startoff; 1007 1008 *cookies = malloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK); 1009 *ncookies = cnt; 1010 1011 for (i = 0; i < cnt; i++) { 1012 KASSERT(off != TMPFS_DIRSEQ_EOF); 1013 if (off != TMPFS_DIRSEQ_DOT) { 1014 if (off == TMPFS_DIRSEQ_DOTDOT) { 1015 de = TAILQ_FIRST(&node->tn_spec.tn_dir.tn_dir); 1016 } else if (de != NULL) { 1017 de = TAILQ_NEXT(de, td_entries); 1018 } else { 1019 de = tmpfs_dir_lookupbyseq(node, off); 1020 KASSERT(de != NULL); 1021 de = TAILQ_NEXT(de, td_entries); 1022 } 1023 if (de == NULL) { 1024 off = TMPFS_DIRSEQ_EOF; 1025 } else { 1026 off = tmpfs_dir_getseq(node, de); 1027 } 1028 } else { 1029 off = TMPFS_DIRSEQ_DOTDOT; 1030 } 1031 (*cookies)[i] = off; 1032 } 1033 KASSERT(uio->uio_offset == off); 1034 return error; 1035 } 1036 1037 int 1038 tmpfs_readlink(void *v) 1039 { 1040 struct vop_readlink_args /* { 1041 struct vnode *a_vp; 1042 struct uio *a_uio; 1043 kauth_cred_t a_cred; 1044 } */ *ap = v; 1045 vnode_t *vp = ap->a_vp; 1046 struct uio *uio = ap->a_uio; 1047 tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp); 1048 int error; 1049 1050 KASSERT(VOP_ISLOCKED(vp)); 1051 KASSERT(uio->uio_offset == 0); 1052 KASSERT(vp->v_type == VLNK); 1053 1054 /* Note: readlink(2) returns the path without NUL terminator. */ 1055 if (node->tn_size > 0) { 1056 error = uiomove(node->tn_spec.tn_lnk.tn_link, 1057 MIN(node->tn_size, uio->uio_resid), uio); 1058 } else { 1059 error = 0; 1060 } 1061 tmpfs_update(vp, TMPFS_UPDATE_ATIME); 1062 1063 return error; 1064 } 1065 1066 int 1067 tmpfs_inactive(void *v) 1068 { 1069 struct vop_inactive_v2_args /* { 1070 struct vnode *a_vp; 1071 bool *a_recycle; 1072 } */ *ap = v; 1073 vnode_t *vp = ap->a_vp; 1074 tmpfs_node_t *node; 1075 int error = 0; 1076 1077 KASSERT(VOP_ISLOCKED(vp)); 1078 1079 node = VP_TO_TMPFS_NODE(vp); 1080 if (node->tn_links == 0) { 1081 /* 1082 * Mark node as dead by setting its generation to zero. 1083 */ 1084 atomic_and_32(&node->tn_gen, ~TMPFS_NODE_GEN_MASK); 1085 1086 /* 1087 * If the file has been deleted, truncate it, otherwise VFS 1088 * will quite rightly try to write back dirty data, which in 1089 * the case of tmpfs/UAO means needless page deactivations. 1090 */ 1091 if (vp->v_type == VREG) { 1092 error = tmpfs_reg_resize(vp, 0); 1093 } 1094 *ap->a_recycle = true; 1095 } else { 1096 tmpfs_update(vp, 0); 1097 *ap->a_recycle = false; 1098 } 1099 1100 return error; 1101 } 1102 1103 int 1104 tmpfs_reclaim(void *v) 1105 { 1106 struct vop_reclaim_v2_args /* { 1107 struct vnode *a_vp; 1108 } */ *ap = v; 1109 vnode_t *vp = ap->a_vp; 1110 tmpfs_mount_t *tmp = VFS_TO_TMPFS(vp->v_mount); 1111 tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp); 1112 1113 /* Unlock vnode. We still have exclusive access to it. */ 1114 VOP_UNLOCK(vp); 1115 1116 /* Disassociate inode from vnode. */ 1117 node->tn_vnode = NULL; 1118 vp->v_data = NULL; 1119 1120 /* If inode is not referenced, i.e. no links, then destroy it. */ 1121 if (node->tn_links == 0) 1122 tmpfs_free_node(tmp, node); 1123 return 0; 1124 } 1125 1126 int 1127 tmpfs_pathconf(void *v) 1128 { 1129 struct vop_pathconf_args /* { 1130 struct vnode *a_vp; 1131 int a_name; 1132 register_t *a_retval; 1133 } */ *ap = v; 1134 register_t *retval = ap->a_retval; 1135 1136 switch (ap->a_name) { 1137 case _PC_LINK_MAX: 1138 *retval = LINK_MAX; 1139 return 0; 1140 case _PC_NAME_MAX: 1141 *retval = TMPFS_MAXNAMLEN; 1142 return 0; 1143 case _PC_PATH_MAX: 1144 *retval = PATH_MAX; 1145 return 0; 1146 case _PC_PIPE_BUF: 1147 *retval = PIPE_BUF; 1148 return 0; 1149 case _PC_CHOWN_RESTRICTED: 1150 *retval = 1; 1151 return 0; 1152 case _PC_NO_TRUNC: 1153 *retval = 1; 1154 return 0; 1155 case _PC_SYNC_IO: 1156 *retval = 1; 1157 return 0; 1158 case _PC_FILESIZEBITS: 1159 *retval = sizeof(off_t) * CHAR_BIT; 1160 return 0; 1161 default: 1162 return genfs_pathconf(ap); 1163 } 1164 } 1165 1166 int 1167 tmpfs_advlock(void *v) 1168 { 1169 struct vop_advlock_args /* { 1170 struct vnode *a_vp; 1171 void * a_id; 1172 int a_op; 1173 struct flock *a_fl; 1174 int a_flags; 1175 } */ *ap = v; 1176 vnode_t *vp = ap->a_vp; 1177 tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp); 1178 1179 return lf_advlock(v, &node->tn_lockf, node->tn_size); 1180 } 1181 1182 int 1183 tmpfs_getpages(void *v) 1184 { 1185 struct vop_getpages_args /* { 1186 struct vnode *a_vp; 1187 voff_t a_offset; 1188 struct vm_page **a_m; 1189 int *a_count; 1190 int a_centeridx; 1191 vm_prot_t a_access_type; 1192 int a_advice; 1193 int a_flags; 1194 } */ * const ap = v; 1195 vnode_t *vp = ap->a_vp; 1196 const voff_t offset = ap->a_offset; 1197 struct vm_page **pgs = ap->a_m; 1198 const int centeridx = ap->a_centeridx; 1199 const vm_prot_t access_type = ap->a_access_type; 1200 const int advice = ap->a_advice; 1201 const int flags = ap->a_flags; 1202 int error, iflag, npages = *ap->a_count; 1203 tmpfs_node_t *node; 1204 struct uvm_object *uobj; 1205 1206 KASSERT(vp->v_type == VREG); 1207 KASSERT(rw_lock_held(vp->v_uobj.vmobjlock)); 1208 1209 /* 1210 * Currently, PGO_PASTEOF is not supported. 1211 */ 1212 if (vp->v_size <= offset + (centeridx << PAGE_SHIFT)) { 1213 if ((flags & PGO_LOCKED) == 0) 1214 rw_exit(vp->v_uobj.vmobjlock); 1215 return EINVAL; 1216 } 1217 1218 if (vp->v_size < offset + (npages << PAGE_SHIFT)) { 1219 npages = (round_page(vp->v_size) - offset) >> PAGE_SHIFT; 1220 } 1221 1222 /* 1223 * Check for reclaimed vnode. v_interlock is not held here, but 1224 * VI_DEADCHECK is set with vmobjlock held. 1225 */ 1226 iflag = atomic_load_relaxed(&vp->v_iflag); 1227 if (__predict_false((iflag & VI_DEADCHECK) != 0)) { 1228 mutex_enter(vp->v_interlock); 1229 error = vdead_check(vp, VDEAD_NOWAIT); 1230 mutex_exit(vp->v_interlock); 1231 if (error) { 1232 if ((flags & PGO_LOCKED) == 0) 1233 rw_exit(vp->v_uobj.vmobjlock); 1234 return error; 1235 } 1236 } 1237 1238 node = VP_TO_TMPFS_NODE(vp); 1239 uobj = node->tn_spec.tn_reg.tn_aobj; 1240 1241 /* 1242 * Update timestamp lazily. The update will be made real when 1243 * a synchronous update is next made -- or by tmpfs_getattr, 1244 * tmpfs_putpages, and tmpfs_inactive. 1245 */ 1246 if ((flags & PGO_NOTIMESTAMP) == 0) { 1247 u_int tflags = 0; 1248 1249 if ((vp->v_mount->mnt_flag & MNT_NOATIME) == 0) 1250 tflags |= TMPFS_UPDATE_ATIME; 1251 1252 if ((access_type & VM_PROT_WRITE) != 0) { 1253 tflags |= TMPFS_UPDATE_MTIME; 1254 if (vp->v_mount->mnt_flag & MNT_RELATIME) 1255 tflags |= TMPFS_UPDATE_ATIME; 1256 } 1257 tmpfs_update_lazily(vp, tflags); 1258 } 1259 1260 /* Invoke the pager. The vnode vmobjlock is shared with the UAO. */ 1261 KASSERT(vp->v_uobj.vmobjlock == uobj->vmobjlock); 1262 error = (*uobj->pgops->pgo_get)(uobj, offset, pgs, &npages, centeridx, 1263 access_type, advice, flags); 1264 #if defined(DEBUG) 1265 if (!error && pgs) { 1266 KASSERT(pgs[centeridx] != NULL); 1267 } 1268 #endif 1269 return error; 1270 } 1271 1272 int 1273 tmpfs_putpages(void *v) 1274 { 1275 struct vop_putpages_args /* { 1276 struct vnode *a_vp; 1277 voff_t a_offlo; 1278 voff_t a_offhi; 1279 int a_flags; 1280 } */ * const ap = v; 1281 vnode_t *vp = ap->a_vp; 1282 const voff_t offlo = ap->a_offlo; 1283 const voff_t offhi = ap->a_offhi; 1284 const int flags = ap->a_flags; 1285 tmpfs_node_t *node; 1286 struct uvm_object *uobj; 1287 int error; 1288 1289 KASSERT(rw_write_held(vp->v_uobj.vmobjlock)); 1290 1291 if (vp->v_type != VREG) { 1292 rw_exit(vp->v_uobj.vmobjlock); 1293 return 0; 1294 } 1295 1296 node = VP_TO_TMPFS_NODE(vp); 1297 uobj = node->tn_spec.tn_reg.tn_aobj; 1298 1299 KASSERT(vp->v_uobj.vmobjlock == uobj->vmobjlock); 1300 error = (*uobj->pgops->pgo_put)(uobj, offlo, offhi, flags); 1301 1302 /* XXX mtime */ 1303 1304 /* Process deferred updates. */ 1305 tmpfs_update(vp, 0); 1306 return error; 1307 } 1308 1309 int 1310 tmpfs_whiteout(void *v) 1311 { 1312 struct vop_whiteout_args /* { 1313 struct vnode *a_dvp; 1314 struct componentname *a_cnp; 1315 int a_flags; 1316 } */ *ap = v; 1317 vnode_t *dvp = ap->a_dvp; 1318 struct componentname *cnp = ap->a_cnp; 1319 const int flags = ap->a_flags; 1320 tmpfs_mount_t *tmp = VFS_TO_TMPFS(dvp->v_mount); 1321 tmpfs_node_t *dnode = VP_TO_TMPFS_DIR(dvp); 1322 tmpfs_dirent_t *de; 1323 int error; 1324 1325 switch (flags) { 1326 case LOOKUP: 1327 break; 1328 case CREATE: 1329 error = tmpfs_alloc_dirent(tmp, cnp->cn_nameptr, 1330 cnp->cn_namelen, &de); 1331 if (error) 1332 return error; 1333 tmpfs_dir_attach(dnode, de, TMPFS_NODE_WHITEOUT); 1334 break; 1335 case DELETE: 1336 cnp->cn_flags &= ~DOWHITEOUT; /* when in doubt, cargo cult */ 1337 de = tmpfs_dir_lookup(dnode, cnp); 1338 if (de == NULL) 1339 return ENOENT; 1340 tmpfs_dir_detach(dnode, de); 1341 tmpfs_free_dirent(tmp, de); 1342 break; 1343 } 1344 tmpfs_update(dvp, TMPFS_UPDATE_MTIME | TMPFS_UPDATE_CTIME); 1345 return 0; 1346 } 1347 1348 int 1349 tmpfs_print(void *v) 1350 { 1351 struct vop_print_args /* { 1352 struct vnode *a_vp; 1353 } */ *ap = v; 1354 vnode_t *vp = ap->a_vp; 1355 tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp); 1356 1357 printf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n" 1358 "\tmode 0%o, owner %d, group %d, size %" PRIdMAX, 1359 node, node->tn_flags, node->tn_links, node->tn_mode, node->tn_uid, 1360 node->tn_gid, (uintmax_t)node->tn_size); 1361 if (vp->v_type == VFIFO) { 1362 VOCALL(fifo_vnodeop_p, VOFFSET(vop_print), v); 1363 } 1364 printf("\n"); 1365 return 0; 1366 } 1367