tmpfs_vnops.c revision 197740
1/* $NetBSD: tmpfs_vnops.c,v 1.39 2007/07/23 15:41:01 jmmv Exp $ */ 2 3/*- 4 * Copyright (c) 2005, 2006 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#include <sys/cdefs.h> 37__FBSDID("$FreeBSD: head/sys/fs/tmpfs/tmpfs_vnops.c 197740 2009-10-04 10:38:04Z delphij $"); 38 39#include <sys/param.h> 40#include <sys/fcntl.h> 41#include <sys/lockf.h> 42#include <sys/namei.h> 43#include <sys/priv.h> 44#include <sys/proc.h> 45#include <sys/resourcevar.h> 46#include <sys/stat.h> 47#include <sys/systm.h> 48#include <sys/unistd.h> 49#include <sys/vnode.h> 50 51#include <vm/vm.h> 52#include <vm/vm_object.h> 53#include <vm/vm_page.h> 54#include <vm/vm_pager.h> 55 56#include <machine/_inttypes.h> 57 58#include <fs/fifofs/fifo.h> 59#include <fs/tmpfs/tmpfs_vnops.h> 60#include <fs/tmpfs/tmpfs.h> 61 62/* --------------------------------------------------------------------- */ 63 64static int 65tmpfs_lookup(struct vop_cachedlookup_args *v) 66{ 67 struct vnode *dvp = v->a_dvp; 68 struct vnode **vpp = v->a_vpp; 69 struct componentname *cnp = v->a_cnp; 70 71 int error; 72 struct tmpfs_dirent *de; 73 struct tmpfs_node *dnode; 74 75 dnode = VP_TO_TMPFS_DIR(dvp); 76 *vpp = NULLVP; 77 78 /* Check accessibility of requested node as a first step. */ 79 error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, cnp->cn_thread); 80 if (error != 0) 81 goto out; 82 83 /* We cannot be requesting the parent directory of the root node. */ 84 MPASS(IMPLIES(dnode->tn_type == VDIR && 85 dnode->tn_dir.tn_parent == dnode, 86 !(cnp->cn_flags & ISDOTDOT))); 87 88 if (cnp->cn_flags & ISDOTDOT) { 89 int ltype = 0; 90 91 ltype = VOP_ISLOCKED(dvp); 92 vhold(dvp); 93 VOP_UNLOCK(dvp, 0); 94 /* Allocate a new vnode on the matching entry. */ 95 error = tmpfs_alloc_vp(dvp->v_mount, dnode->tn_dir.tn_parent, 96 cnp->cn_lkflags, vpp); 97 98 vn_lock(dvp, ltype | LK_RETRY); 99 vdrop(dvp); 100 } else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') { 101 VREF(dvp); 102 *vpp = dvp; 103 error = 0; 104 } else { 105 de = tmpfs_dir_lookup(dnode, NULL, cnp); 106 if (de == NULL) { 107 /* The entry was not found in the directory. 108 * This is OK if we are creating or renaming an 109 * entry and are working on the last component of 110 * the path name. */ 111 if ((cnp->cn_flags & ISLASTCN) && 112 (cnp->cn_nameiop == CREATE || \ 113 cnp->cn_nameiop == RENAME)) { 114 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, 115 cnp->cn_thread); 116 if (error != 0) 117 goto out; 118 119 /* Keep the component name in the buffer for 120 * future uses. */ 121 cnp->cn_flags |= SAVENAME; 122 123 error = EJUSTRETURN; 124 } else 125 error = ENOENT; 126 } else { 127 struct tmpfs_node *tnode; 128 129 /* The entry was found, so get its associated 130 * tmpfs_node. */ 131 tnode = de->td_node; 132 133 /* If we are not at the last path component and 134 * found a non-directory or non-link entry (which 135 * may itself be pointing to a directory), raise 136 * an error. */ 137 if ((tnode->tn_type != VDIR && 138 tnode->tn_type != VLNK) && 139 !(cnp->cn_flags & ISLASTCN)) { 140 error = ENOTDIR; 141 goto out; 142 } 143 144 /* If we are deleting or renaming the entry, keep 145 * track of its tmpfs_dirent so that it can be 146 * easily deleted later. */ 147 if ((cnp->cn_flags & ISLASTCN) && 148 (cnp->cn_nameiop == DELETE || 149 cnp->cn_nameiop == RENAME)) { 150 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, 151 cnp->cn_thread); 152 if (error != 0) 153 goto out; 154 155 /* Allocate a new vnode on the matching entry. */ 156 error = tmpfs_alloc_vp(dvp->v_mount, tnode, 157 cnp->cn_lkflags, vpp); 158 if (error != 0) 159 goto out; 160 161 if ((dnode->tn_mode & S_ISTXT) && 162 VOP_ACCESS(dvp, VADMIN, cnp->cn_cred, cnp->cn_thread) && 163 VOP_ACCESS(*vpp, VADMIN, cnp->cn_cred, cnp->cn_thread)) { 164 error = EPERM; 165 vput(*vpp); 166 *vpp = NULL; 167 goto out; 168 } 169 cnp->cn_flags |= SAVENAME; 170 } else { 171 error = tmpfs_alloc_vp(dvp->v_mount, tnode, 172 cnp->cn_lkflags, vpp); 173 } 174 } 175 } 176 177 /* Store the result of this lookup in the cache. Avoid this if the 178 * request was for creation, as it does not improve timings on 179 * emprical tests. */ 180 if ((cnp->cn_flags & MAKEENTRY) && cnp->cn_nameiop != CREATE) 181 cache_enter(dvp, *vpp, cnp); 182 183out: 184 /* If there were no errors, *vpp cannot be null and it must be 185 * locked. */ 186 MPASS(IFF(error == 0, *vpp != NULLVP && VOP_ISLOCKED(*vpp))); 187 188 return error; 189} 190 191/* --------------------------------------------------------------------- */ 192 193static int 194tmpfs_create(struct vop_create_args *v) 195{ 196 struct vnode *dvp = v->a_dvp; 197 struct vnode **vpp = v->a_vpp; 198 struct componentname *cnp = v->a_cnp; 199 struct vattr *vap = v->a_vap; 200 201 MPASS(vap->va_type == VREG || vap->va_type == VSOCK); 202 203 return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL); 204} 205/* --------------------------------------------------------------------- */ 206 207static int 208tmpfs_mknod(struct vop_mknod_args *v) 209{ 210 struct vnode *dvp = v->a_dvp; 211 struct vnode **vpp = v->a_vpp; 212 struct componentname *cnp = v->a_cnp; 213 struct vattr *vap = v->a_vap; 214 215 if (vap->va_type != VBLK && vap->va_type != VCHR && 216 vap->va_type != VFIFO) 217 return EINVAL; 218 219 return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL); 220} 221 222/* --------------------------------------------------------------------- */ 223 224static int 225tmpfs_open(struct vop_open_args *v) 226{ 227 struct vnode *vp = v->a_vp; 228 int mode = v->a_mode; 229 230 int error; 231 struct tmpfs_node *node; 232 233 MPASS(VOP_ISLOCKED(vp)); 234 235 node = VP_TO_TMPFS_NODE(vp); 236 237 /* The file is still active but all its names have been removed 238 * (e.g. by a "rmdir $(pwd)"). It cannot be opened any more as 239 * it is about to die. */ 240 if (node->tn_links < 1) 241 return (ENOENT); 242 243 /* If the file is marked append-only, deny write requests. */ 244 if (node->tn_flags & APPEND && (mode & (FWRITE | O_APPEND)) == FWRITE) 245 error = EPERM; 246 else { 247 error = 0; 248 vnode_create_vobject(vp, node->tn_size, v->a_td); 249 } 250 251 MPASS(VOP_ISLOCKED(vp)); 252 return error; 253} 254 255/* --------------------------------------------------------------------- */ 256 257static int 258tmpfs_close(struct vop_close_args *v) 259{ 260 struct vnode *vp = v->a_vp; 261 262 struct tmpfs_node *node; 263 264 MPASS(VOP_ISLOCKED(vp)); 265 266 node = VP_TO_TMPFS_NODE(vp); 267 268 if (node->tn_links > 0) { 269 /* Update node times. No need to do it if the node has 270 * been deleted, because it will vanish after we return. */ 271 tmpfs_update(vp); 272 } 273 274 return 0; 275} 276 277/* --------------------------------------------------------------------- */ 278 279int 280tmpfs_access(struct vop_access_args *v) 281{ 282 struct vnode *vp = v->a_vp; 283 accmode_t accmode = v->a_accmode; 284 struct ucred *cred = v->a_cred; 285 286 int error; 287 struct tmpfs_node *node; 288 289 MPASS(VOP_ISLOCKED(vp)); 290 291 node = VP_TO_TMPFS_NODE(vp); 292 293 switch (vp->v_type) { 294 case VDIR: 295 /* FALLTHROUGH */ 296 case VLNK: 297 /* FALLTHROUGH */ 298 case VREG: 299 if (accmode & VWRITE && vp->v_mount->mnt_flag & MNT_RDONLY) { 300 error = EROFS; 301 goto out; 302 } 303 break; 304 305 case VBLK: 306 /* FALLTHROUGH */ 307 case VCHR: 308 /* FALLTHROUGH */ 309 case VSOCK: 310 /* FALLTHROUGH */ 311 case VFIFO: 312 break; 313 314 default: 315 error = EINVAL; 316 goto out; 317 } 318 319 if (accmode & VWRITE && node->tn_flags & IMMUTABLE) { 320 error = EPERM; 321 goto out; 322 } 323 324 error = vaccess(vp->v_type, node->tn_mode, node->tn_uid, 325 node->tn_gid, accmode, cred, NULL); 326 327out: 328 MPASS(VOP_ISLOCKED(vp)); 329 330 return error; 331} 332 333/* --------------------------------------------------------------------- */ 334 335int 336tmpfs_getattr(struct vop_getattr_args *v) 337{ 338 struct vnode *vp = v->a_vp; 339 struct vattr *vap = v->a_vap; 340 341 struct tmpfs_node *node; 342 343 node = VP_TO_TMPFS_NODE(vp); 344 345 tmpfs_update(vp); 346 347 vap->va_type = vp->v_type; 348 vap->va_mode = node->tn_mode; 349 vap->va_nlink = node->tn_links; 350 vap->va_uid = node->tn_uid; 351 vap->va_gid = node->tn_gid; 352 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0]; 353 vap->va_fileid = node->tn_id; 354 vap->va_size = node->tn_size; 355 vap->va_blocksize = PAGE_SIZE; 356 vap->va_atime = node->tn_atime; 357 vap->va_mtime = node->tn_mtime; 358 vap->va_ctime = node->tn_ctime; 359 vap->va_birthtime = node->tn_birthtime; 360 vap->va_gen = node->tn_gen; 361 vap->va_flags = node->tn_flags; 362 vap->va_rdev = (vp->v_type == VBLK || vp->v_type == VCHR) ? 363 node->tn_rdev : NODEV; 364 vap->va_bytes = round_page(node->tn_size); 365 vap->va_filerev = 0; 366 367 return 0; 368} 369 370/* --------------------------------------------------------------------- */ 371 372/* XXX Should this operation be atomic? I think it should, but code in 373 * XXX other places (e.g., ufs) doesn't seem to be... */ 374int 375tmpfs_setattr(struct vop_setattr_args *v) 376{ 377 struct vnode *vp = v->a_vp; 378 struct vattr *vap = v->a_vap; 379 struct ucred *cred = v->a_cred; 380 struct thread *td = curthread; 381 382 int error; 383 384 MPASS(VOP_ISLOCKED(vp)); 385 386 error = 0; 387 388 /* Abort if any unsettable attribute is given. */ 389 if (vap->va_type != VNON || 390 vap->va_nlink != VNOVAL || 391 vap->va_fsid != VNOVAL || 392 vap->va_fileid != VNOVAL || 393 vap->va_blocksize != VNOVAL || 394 vap->va_gen != VNOVAL || 395 vap->va_rdev != VNOVAL || 396 vap->va_bytes != VNOVAL) 397 error = EINVAL; 398 399 if (error == 0 && (vap->va_flags != VNOVAL)) 400 error = tmpfs_chflags(vp, vap->va_flags, cred, td); 401 402 if (error == 0 && (vap->va_size != VNOVAL)) 403 error = tmpfs_chsize(vp, vap->va_size, cred, td); 404 405 if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL)) 406 error = tmpfs_chown(vp, vap->va_uid, vap->va_gid, cred, td); 407 408 if (error == 0 && (vap->va_mode != (mode_t)VNOVAL)) 409 error = tmpfs_chmod(vp, vap->va_mode, cred, td); 410 411 if (error == 0 && ((vap->va_atime.tv_sec != VNOVAL && 412 vap->va_atime.tv_nsec != VNOVAL) || 413 (vap->va_mtime.tv_sec != VNOVAL && 414 vap->va_mtime.tv_nsec != VNOVAL) || 415 (vap->va_birthtime.tv_sec != VNOVAL && 416 vap->va_birthtime.tv_nsec != VNOVAL))) 417 error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime, 418 &vap->va_birthtime, vap->va_vaflags, cred, td); 419 420 /* Update the node times. We give preference to the error codes 421 * generated by this function rather than the ones that may arise 422 * from tmpfs_update. */ 423 tmpfs_update(vp); 424 425 MPASS(VOP_ISLOCKED(vp)); 426 427 return error; 428} 429 430/* --------------------------------------------------------------------- */ 431 432static int 433tmpfs_mappedread(vm_object_t vobj, vm_object_t tobj, size_t len, struct uio *uio) 434{ 435 vm_pindex_t idx; 436 vm_page_t m; 437 vm_offset_t offset; 438 off_t addr; 439 size_t tlen; 440 int error; 441 442 addr = uio->uio_offset; 443 idx = OFF_TO_IDX(addr); 444 offset = addr & PAGE_MASK; 445 tlen = MIN(PAGE_SIZE - offset, len); 446 447 if ((vobj == NULL) || 448 (vobj->resident_page_count == 0 && vobj->cache == NULL)) 449 goto nocache; 450 451 VM_OBJECT_LOCK(vobj); 452lookupvpg: 453 if (((m = vm_page_lookup(vobj, idx)) != NULL) && 454 vm_page_is_valid(m, offset, tlen)) { 455 if (vm_page_sleep_if_busy(m, FALSE, "tmfsmr")) 456 goto lookupvpg; 457 vm_page_busy(m); 458 VM_OBJECT_UNLOCK(vobj); 459 error = uiomove_fromphys(&m, offset, tlen, uio); 460 VM_OBJECT_LOCK(vobj); 461 vm_page_wakeup(m); 462 VM_OBJECT_UNLOCK(vobj); 463 return (error); 464 } 465 VM_OBJECT_UNLOCK(vobj); 466nocache: 467 VM_OBJECT_LOCK(tobj); 468 vm_object_pip_add(tobj, 1); 469 m = vm_page_grab(tobj, idx, VM_ALLOC_WIRED | 470 VM_ALLOC_ZERO | VM_ALLOC_NORMAL | VM_ALLOC_RETRY); 471 if (m->valid != VM_PAGE_BITS_ALL) { 472 if (vm_pager_has_page(tobj, idx, NULL, NULL)) { 473 error = vm_pager_get_pages(tobj, &m, 1, 0); 474 if (error != 0) { 475 printf("tmpfs get pages from pager error [read]\n"); 476 goto out; 477 } 478 } else 479 vm_page_zero_invalid(m, TRUE); 480 } 481 VM_OBJECT_UNLOCK(tobj); 482 error = uiomove_fromphys(&m, offset, tlen, uio); 483 VM_OBJECT_LOCK(tobj); 484out: 485 vm_page_lock_queues(); 486 vm_page_unwire(m, TRUE); 487 vm_page_unlock_queues(); 488 vm_page_wakeup(m); 489 vm_object_pip_subtract(tobj, 1); 490 VM_OBJECT_UNLOCK(tobj); 491 492 return (error); 493} 494 495static int 496tmpfs_read(struct vop_read_args *v) 497{ 498 struct vnode *vp = v->a_vp; 499 struct uio *uio = v->a_uio; 500 501 struct tmpfs_node *node; 502 vm_object_t uobj; 503 size_t len; 504 int resid; 505 506 int error = 0; 507 508 node = VP_TO_TMPFS_NODE(vp); 509 510 if (vp->v_type != VREG) { 511 error = EISDIR; 512 goto out; 513 } 514 515 if (uio->uio_offset < 0) { 516 error = EINVAL; 517 goto out; 518 } 519 520 node->tn_status |= TMPFS_NODE_ACCESSED; 521 522 uobj = node->tn_reg.tn_aobj; 523 while ((resid = uio->uio_resid) > 0) { 524 error = 0; 525 if (node->tn_size <= uio->uio_offset) 526 break; 527 len = MIN(node->tn_size - uio->uio_offset, resid); 528 if (len == 0) 529 break; 530 error = tmpfs_mappedread(vp->v_object, uobj, len, uio); 531 if ((error != 0) || (resid == uio->uio_resid)) 532 break; 533 } 534 535out: 536 537 return error; 538} 539 540/* --------------------------------------------------------------------- */ 541 542static int 543tmpfs_mappedwrite(vm_object_t vobj, vm_object_t tobj, size_t len, struct uio *uio) 544{ 545 vm_pindex_t idx; 546 vm_page_t vpg, tpg; 547 vm_offset_t offset; 548 off_t addr; 549 size_t tlen; 550 int error; 551 552 error = 0; 553 554 addr = uio->uio_offset; 555 idx = OFF_TO_IDX(addr); 556 offset = addr & PAGE_MASK; 557 tlen = MIN(PAGE_SIZE - offset, len); 558 559 if ((vobj == NULL) || 560 (vobj->resident_page_count == 0 && vobj->cache == NULL)) { 561 vpg = NULL; 562 goto nocache; 563 } 564 565 VM_OBJECT_LOCK(vobj); 566lookupvpg: 567 if (((vpg = vm_page_lookup(vobj, idx)) != NULL) && 568 vm_page_is_valid(vpg, offset, tlen)) { 569 if (vm_page_sleep_if_busy(vpg, FALSE, "tmfsmw")) 570 goto lookupvpg; 571 vm_page_busy(vpg); 572 vm_page_lock_queues(); 573 vm_page_undirty(vpg); 574 vm_page_unlock_queues(); 575 VM_OBJECT_UNLOCK(vobj); 576 error = uiomove_fromphys(&vpg, offset, tlen, uio); 577 } else { 578 if (__predict_false(vobj->cache != NULL)) 579 vm_page_cache_free(vobj, idx, idx + 1); 580 VM_OBJECT_UNLOCK(vobj); 581 vpg = NULL; 582 } 583nocache: 584 VM_OBJECT_LOCK(tobj); 585 vm_object_pip_add(tobj, 1); 586 tpg = vm_page_grab(tobj, idx, VM_ALLOC_WIRED | 587 VM_ALLOC_ZERO | VM_ALLOC_NORMAL | VM_ALLOC_RETRY); 588 if (tpg->valid != VM_PAGE_BITS_ALL) { 589 if (vm_pager_has_page(tobj, idx, NULL, NULL)) { 590 error = vm_pager_get_pages(tobj, &tpg, 1, 0); 591 if (error != 0) { 592 printf("tmpfs get pages from pager error [write]\n"); 593 goto out; 594 } 595 } else 596 vm_page_zero_invalid(tpg, TRUE); 597 } 598 VM_OBJECT_UNLOCK(tobj); 599 if (vpg == NULL) 600 error = uiomove_fromphys(&tpg, offset, tlen, uio); 601 else { 602 KASSERT(vpg->valid == VM_PAGE_BITS_ALL, ("parts of vpg invalid")); 603 pmap_copy_page(vpg, tpg); 604 } 605 VM_OBJECT_LOCK(tobj); 606out: 607 if (vobj != NULL) 608 VM_OBJECT_LOCK(vobj); 609 vm_page_lock_queues(); 610 if (error == 0) { 611 KASSERT(tpg->valid == VM_PAGE_BITS_ALL, 612 ("parts of tpg invalid")); 613 vm_page_dirty(tpg); 614 } 615 vm_page_unwire(tpg, TRUE); 616 vm_page_unlock_queues(); 617 vm_page_wakeup(tpg); 618 if (vpg != NULL) 619 vm_page_wakeup(vpg); 620 if (vobj != NULL) 621 VM_OBJECT_UNLOCK(vobj); 622 vm_object_pip_subtract(tobj, 1); 623 VM_OBJECT_UNLOCK(tobj); 624 625 return (error); 626} 627 628static int 629tmpfs_write(struct vop_write_args *v) 630{ 631 struct vnode *vp = v->a_vp; 632 struct uio *uio = v->a_uio; 633 int ioflag = v->a_ioflag; 634 struct thread *td = uio->uio_td; 635 636 boolean_t extended; 637 int error = 0; 638 off_t oldsize; 639 struct tmpfs_node *node; 640 vm_object_t uobj; 641 size_t len; 642 int resid; 643 644 node = VP_TO_TMPFS_NODE(vp); 645 oldsize = node->tn_size; 646 647 if (uio->uio_offset < 0 || vp->v_type != VREG) { 648 error = EINVAL; 649 goto out; 650 } 651 652 if (uio->uio_resid == 0) { 653 error = 0; 654 goto out; 655 } 656 657 if (ioflag & IO_APPEND) 658 uio->uio_offset = node->tn_size; 659 660 if (uio->uio_offset + uio->uio_resid > 661 VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize) 662 return (EFBIG); 663 664 if (vp->v_type == VREG && td != NULL) { 665 PROC_LOCK(td->td_proc); 666 if (uio->uio_offset + uio->uio_resid > 667 lim_cur(td->td_proc, RLIMIT_FSIZE)) { 668 psignal(td->td_proc, SIGXFSZ); 669 PROC_UNLOCK(td->td_proc); 670 return (EFBIG); 671 } 672 PROC_UNLOCK(td->td_proc); 673 } 674 675 extended = uio->uio_offset + uio->uio_resid > node->tn_size; 676 if (extended) { 677 error = tmpfs_reg_resize(vp, uio->uio_offset + uio->uio_resid); 678 if (error != 0) 679 goto out; 680 } 681 682 uobj = node->tn_reg.tn_aobj; 683 while ((resid = uio->uio_resid) > 0) { 684 if (node->tn_size <= uio->uio_offset) 685 break; 686 len = MIN(node->tn_size - uio->uio_offset, resid); 687 if (len == 0) 688 break; 689 error = tmpfs_mappedwrite(vp->v_object, uobj, len, uio); 690 if ((error != 0) || (resid == uio->uio_resid)) 691 break; 692 } 693 694 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED | 695 (extended ? TMPFS_NODE_CHANGED : 0); 696 697 if (node->tn_mode & (S_ISUID | S_ISGID)) { 698 if (priv_check_cred(v->a_cred, PRIV_VFS_RETAINSUGID, 0)) 699 node->tn_mode &= ~(S_ISUID | S_ISGID); 700 } 701 702 if (error != 0) 703 (void)tmpfs_reg_resize(vp, oldsize); 704 705out: 706 MPASS(IMPLIES(error == 0, uio->uio_resid == 0)); 707 MPASS(IMPLIES(error != 0, oldsize == node->tn_size)); 708 709 return error; 710} 711 712/* --------------------------------------------------------------------- */ 713 714static int 715tmpfs_fsync(struct vop_fsync_args *v) 716{ 717 struct vnode *vp = v->a_vp; 718 719 MPASS(VOP_ISLOCKED(vp)); 720 721 tmpfs_update(vp); 722 723 return 0; 724} 725 726/* --------------------------------------------------------------------- */ 727 728static int 729tmpfs_remove(struct vop_remove_args *v) 730{ 731 struct vnode *dvp = v->a_dvp; 732 struct vnode *vp = v->a_vp; 733 734 int error; 735 struct tmpfs_dirent *de; 736 struct tmpfs_mount *tmp; 737 struct tmpfs_node *dnode; 738 struct tmpfs_node *node; 739 740 MPASS(VOP_ISLOCKED(dvp)); 741 MPASS(VOP_ISLOCKED(vp)); 742 743 if (vp->v_type == VDIR) { 744 error = EISDIR; 745 goto out; 746 } 747 748 dnode = VP_TO_TMPFS_DIR(dvp); 749 node = VP_TO_TMPFS_NODE(vp); 750 tmp = VFS_TO_TMPFS(vp->v_mount); 751 de = tmpfs_dir_lookup(dnode, node, v->a_cnp); 752 MPASS(de != NULL); 753 754 /* Files marked as immutable or append-only cannot be deleted. */ 755 if ((node->tn_flags & (IMMUTABLE | APPEND | NOUNLINK)) || 756 (dnode->tn_flags & APPEND)) { 757 error = EPERM; 758 goto out; 759 } 760 761 /* Remove the entry from the directory; as it is a file, we do not 762 * have to change the number of hard links of the directory. */ 763 tmpfs_dir_detach(dvp, de); 764 765 /* Free the directory entry we just deleted. Note that the node 766 * referred by it will not be removed until the vnode is really 767 * reclaimed. */ 768 tmpfs_free_dirent(tmp, de, TRUE); 769 770 if (node->tn_links > 0) 771 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \ 772 TMPFS_NODE_MODIFIED; 773 error = 0; 774 775out: 776 777 return error; 778} 779 780/* --------------------------------------------------------------------- */ 781 782static int 783tmpfs_link(struct vop_link_args *v) 784{ 785 struct vnode *dvp = v->a_tdvp; 786 struct vnode *vp = v->a_vp; 787 struct componentname *cnp = v->a_cnp; 788 789 int error; 790 struct tmpfs_dirent *de; 791 struct tmpfs_node *node; 792 793 MPASS(VOP_ISLOCKED(dvp)); 794 MPASS(cnp->cn_flags & HASBUF); 795 MPASS(dvp != vp); /* XXX When can this be false? */ 796 797 node = VP_TO_TMPFS_NODE(vp); 798 799 /* XXX: Why aren't the following two tests done by the caller? */ 800 801 /* Hard links of directories are forbidden. */ 802 if (vp->v_type == VDIR) { 803 error = EPERM; 804 goto out; 805 } 806 807 /* Cannot create cross-device links. */ 808 if (dvp->v_mount != vp->v_mount) { 809 error = EXDEV; 810 goto out; 811 } 812 813 /* Ensure that we do not overflow the maximum number of links imposed 814 * by the system. */ 815 MPASS(node->tn_links <= LINK_MAX); 816 if (node->tn_links == LINK_MAX) { 817 error = EMLINK; 818 goto out; 819 } 820 821 /* We cannot create links of files marked immutable or append-only. */ 822 if (node->tn_flags & (IMMUTABLE | APPEND)) { 823 error = EPERM; 824 goto out; 825 } 826 827 /* Allocate a new directory entry to represent the node. */ 828 error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount), node, 829 cnp->cn_nameptr, cnp->cn_namelen, &de); 830 if (error != 0) 831 goto out; 832 833 /* Insert the new directory entry into the appropriate directory. */ 834 tmpfs_dir_attach(dvp, de); 835 836 /* vp link count has changed, so update node times. */ 837 node->tn_status |= TMPFS_NODE_CHANGED; 838 tmpfs_update(vp); 839 840 error = 0; 841 842out: 843 return error; 844} 845 846/* --------------------------------------------------------------------- */ 847 848static int 849tmpfs_rename(struct vop_rename_args *v) 850{ 851 struct vnode *fdvp = v->a_fdvp; 852 struct vnode *fvp = v->a_fvp; 853 struct componentname *fcnp = v->a_fcnp; 854 struct vnode *tdvp = v->a_tdvp; 855 struct vnode *tvp = v->a_tvp; 856 struct componentname *tcnp = v->a_tcnp; 857 858 char *newname; 859 int error; 860 struct tmpfs_dirent *de; 861 struct tmpfs_node *fdnode; 862 struct tmpfs_node *fnode; 863 struct tmpfs_node *tnode; 864 struct tmpfs_node *tdnode; 865 866 MPASS(VOP_ISLOCKED(tdvp)); 867 MPASS(IMPLIES(tvp != NULL, VOP_ISLOCKED(tvp))); 868 MPASS(fcnp->cn_flags & HASBUF); 869 MPASS(tcnp->cn_flags & HASBUF); 870 871 tnode = (tvp == NULL) ? NULL : VP_TO_TMPFS_NODE(tvp); 872 873 /* Disallow cross-device renames. 874 * XXX Why isn't this done by the caller? */ 875 if (fvp->v_mount != tdvp->v_mount || 876 (tvp != NULL && fvp->v_mount != tvp->v_mount)) { 877 error = EXDEV; 878 goto out; 879 } 880 881 tdnode = VP_TO_TMPFS_DIR(tdvp); 882 883 /* If source and target are the same file, there is nothing to do. */ 884 if (fvp == tvp) { 885 error = 0; 886 goto out; 887 } 888 889 /* If we need to move the directory between entries, lock the 890 * source so that we can safely operate on it. */ 891 if (tdvp != fdvp) { 892 error = vn_lock(fdvp, LK_EXCLUSIVE | LK_RETRY); 893 if (error != 0) 894 goto out; 895 } 896 fdnode = VP_TO_TMPFS_DIR(fdvp); 897 fnode = VP_TO_TMPFS_NODE(fvp); 898 de = tmpfs_dir_lookup(fdnode, fnode, fcnp); 899 900 /* Avoid manipulating '.' and '..' entries. */ 901 if (de == NULL) { 902 MPASS(fvp->v_type == VDIR); 903 error = EINVAL; 904 goto out_locked; 905 } 906 MPASS(de->td_node == fnode); 907 908 /* If re-naming a directory to another preexisting directory 909 * ensure that the target directory is empty so that its 910 * removal causes no side effects. 911 * Kern_rename gurantees the destination to be a directory 912 * if the source is one. */ 913 if (tvp != NULL) { 914 MPASS(tnode != NULL); 915 916 if ((tnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) || 917 (tdnode->tn_flags & (APPEND | IMMUTABLE))) { 918 error = EPERM; 919 goto out_locked; 920 } 921 922 if (fnode->tn_type == VDIR && tnode->tn_type == VDIR) { 923 if (tnode->tn_size > 0) { 924 error = ENOTEMPTY; 925 goto out_locked; 926 } 927 } else if (fnode->tn_type == VDIR && tnode->tn_type != VDIR) { 928 error = ENOTDIR; 929 goto out_locked; 930 } else if (fnode->tn_type != VDIR && tnode->tn_type == VDIR) { 931 error = EISDIR; 932 goto out_locked; 933 } else { 934 MPASS(fnode->tn_type != VDIR && 935 tnode->tn_type != VDIR); 936 } 937 } 938 939 if ((fnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) 940 || (fdnode->tn_flags & (APPEND | IMMUTABLE))) { 941 error = EPERM; 942 goto out_locked; 943 } 944 945 /* Ensure that we have enough memory to hold the new name, if it 946 * has to be changed. */ 947 if (fcnp->cn_namelen != tcnp->cn_namelen || 948 bcmp(fcnp->cn_nameptr, tcnp->cn_nameptr, fcnp->cn_namelen) != 0) { 949 newname = malloc(tcnp->cn_namelen, M_TMPFSNAME, M_WAITOK); 950 } else 951 newname = NULL; 952 953 /* If the node is being moved to another directory, we have to do 954 * the move. */ 955 if (fdnode != tdnode) { 956 /* In case we are moving a directory, we have to adjust its 957 * parent to point to the new parent. */ 958 if (de->td_node->tn_type == VDIR) { 959 struct tmpfs_node *n; 960 961 /* Ensure the target directory is not a child of the 962 * directory being moved. Otherwise, we'd end up 963 * with stale nodes. */ 964 n = tdnode; 965 while (n != n->tn_dir.tn_parent) { 966 if (n == fnode) { 967 error = EINVAL; 968 if (newname != NULL) 969 free(newname, M_TMPFSNAME); 970 goto out_locked; 971 } 972 n = n->tn_dir.tn_parent; 973 } 974 975 /* Adjust the parent pointer. */ 976 TMPFS_VALIDATE_DIR(fnode); 977 de->td_node->tn_dir.tn_parent = tdnode; 978 979 /* As a result of changing the target of the '..' 980 * entry, the link count of the source and target 981 * directories has to be adjusted. */ 982 fdnode->tn_links--; 983 tdnode->tn_links++; 984 } 985 986 /* Do the move: just remove the entry from the source directory 987 * and insert it into the target one. */ 988 tmpfs_dir_detach(fdvp, de); 989 tmpfs_dir_attach(tdvp, de); 990 } 991 992 /* If the name has changed, we need to make it effective by changing 993 * it in the directory entry. */ 994 if (newname != NULL) { 995 MPASS(tcnp->cn_namelen <= MAXNAMLEN); 996 997 free(de->td_name, M_TMPFSNAME); 998 de->td_namelen = (uint16_t)tcnp->cn_namelen; 999 memcpy(newname, tcnp->cn_nameptr, tcnp->cn_namelen); 1000 de->td_name = newname; 1001 1002 fnode->tn_status |= TMPFS_NODE_CHANGED; 1003 tdnode->tn_status |= TMPFS_NODE_MODIFIED; 1004 } 1005 1006 /* If we are overwriting an entry, we have to remove the old one 1007 * from the target directory. */ 1008 if (tvp != NULL) { 1009 /* Remove the old entry from the target directory. */ 1010 de = tmpfs_dir_lookup(tdnode, tnode, tcnp); 1011 tmpfs_dir_detach(tdvp, de); 1012 1013 /* Free the directory entry we just deleted. Note that the 1014 * node referred by it will not be removed until the vnode is 1015 * really reclaimed. */ 1016 tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), de, TRUE); 1017 } 1018 1019 error = 0; 1020 1021out_locked: 1022 if (fdnode != tdnode) 1023 VOP_UNLOCK(fdvp, 0); 1024 1025out: 1026 /* Release target nodes. */ 1027 /* XXX: I don't understand when tdvp can be the same as tvp, but 1028 * other code takes care of this... */ 1029 if (tdvp == tvp) 1030 vrele(tdvp); 1031 else 1032 vput(tdvp); 1033 if (tvp != NULL) 1034 vput(tvp); 1035 1036 /* Release source nodes. */ 1037 vrele(fdvp); 1038 vrele(fvp); 1039 1040 return error; 1041} 1042 1043/* --------------------------------------------------------------------- */ 1044 1045static int 1046tmpfs_mkdir(struct vop_mkdir_args *v) 1047{ 1048 struct vnode *dvp = v->a_dvp; 1049 struct vnode **vpp = v->a_vpp; 1050 struct componentname *cnp = v->a_cnp; 1051 struct vattr *vap = v->a_vap; 1052 1053 MPASS(vap->va_type == VDIR); 1054 1055 return tmpfs_alloc_file(dvp, vpp, vap, cnp, NULL); 1056} 1057 1058/* --------------------------------------------------------------------- */ 1059 1060static int 1061tmpfs_rmdir(struct vop_rmdir_args *v) 1062{ 1063 struct vnode *dvp = v->a_dvp; 1064 struct vnode *vp = v->a_vp; 1065 1066 int error; 1067 struct tmpfs_dirent *de; 1068 struct tmpfs_mount *tmp; 1069 struct tmpfs_node *dnode; 1070 struct tmpfs_node *node; 1071 1072 MPASS(VOP_ISLOCKED(dvp)); 1073 MPASS(VOP_ISLOCKED(vp)); 1074 1075 tmp = VFS_TO_TMPFS(dvp->v_mount); 1076 dnode = VP_TO_TMPFS_DIR(dvp); 1077 node = VP_TO_TMPFS_DIR(vp); 1078 1079 /* Directories with more than two entries ('.' and '..') cannot be 1080 * removed. */ 1081 if (node->tn_size > 0) { 1082 error = ENOTEMPTY; 1083 goto out; 1084 } 1085 1086 if ((dnode->tn_flags & APPEND) 1087 || (node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND))) { 1088 error = EPERM; 1089 goto out; 1090 } 1091 1092 /* This invariant holds only if we are not trying to remove "..". 1093 * We checked for that above so this is safe now. */ 1094 MPASS(node->tn_dir.tn_parent == dnode); 1095 1096 /* Get the directory entry associated with node (vp). This was 1097 * filled by tmpfs_lookup while looking up the entry. */ 1098 de = tmpfs_dir_lookup(dnode, node, v->a_cnp); 1099 MPASS(TMPFS_DIRENT_MATCHES(de, 1100 v->a_cnp->cn_nameptr, 1101 v->a_cnp->cn_namelen)); 1102 1103 /* Check flags to see if we are allowed to remove the directory. */ 1104 if (dnode->tn_flags & APPEND 1105 || node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) { 1106 error = EPERM; 1107 goto out; 1108 } 1109 1110 /* Detach the directory entry from the directory (dnode). */ 1111 tmpfs_dir_detach(dvp, de); 1112 1113 node->tn_links--; 1114 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \ 1115 TMPFS_NODE_MODIFIED; 1116 node->tn_dir.tn_parent->tn_links--; 1117 node->tn_dir.tn_parent->tn_status |= TMPFS_NODE_ACCESSED | \ 1118 TMPFS_NODE_CHANGED | TMPFS_NODE_MODIFIED; 1119 1120 cache_purge(dvp); 1121 cache_purge(vp); 1122 1123 /* Free the directory entry we just deleted. Note that the node 1124 * referred by it will not be removed until the vnode is really 1125 * reclaimed. */ 1126 tmpfs_free_dirent(tmp, de, TRUE); 1127 1128 /* Release the deleted vnode (will destroy the node, notify 1129 * interested parties and clean it from the cache). */ 1130 1131 dnode->tn_status |= TMPFS_NODE_CHANGED; 1132 tmpfs_update(dvp); 1133 1134 error = 0; 1135 1136out: 1137 return error; 1138} 1139 1140/* --------------------------------------------------------------------- */ 1141 1142static int 1143tmpfs_symlink(struct vop_symlink_args *v) 1144{ 1145 struct vnode *dvp = v->a_dvp; 1146 struct vnode **vpp = v->a_vpp; 1147 struct componentname *cnp = v->a_cnp; 1148 struct vattr *vap = v->a_vap; 1149 char *target = v->a_target; 1150 1151#ifdef notyet /* XXX FreeBSD BUG: kern_symlink is not setting VLNK */ 1152 MPASS(vap->va_type == VLNK); 1153#else 1154 vap->va_type = VLNK; 1155#endif 1156 1157 return tmpfs_alloc_file(dvp, vpp, vap, cnp, target); 1158} 1159 1160/* --------------------------------------------------------------------- */ 1161 1162static int 1163tmpfs_readdir(struct vop_readdir_args *v) 1164{ 1165 struct vnode *vp = v->a_vp; 1166 struct uio *uio = v->a_uio; 1167 int *eofflag = v->a_eofflag; 1168 u_long **cookies = v->a_cookies; 1169 int *ncookies = v->a_ncookies; 1170 1171 int error; 1172 off_t startoff; 1173 off_t cnt = 0; 1174 struct tmpfs_node *node; 1175 1176 /* This operation only makes sense on directory nodes. */ 1177 if (vp->v_type != VDIR) 1178 return ENOTDIR; 1179 1180 node = VP_TO_TMPFS_DIR(vp); 1181 1182 startoff = uio->uio_offset; 1183 1184 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) { 1185 error = tmpfs_dir_getdotdent(node, uio); 1186 if (error != 0) 1187 goto outok; 1188 cnt++; 1189 } 1190 1191 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT) { 1192 error = tmpfs_dir_getdotdotdent(node, uio); 1193 if (error != 0) 1194 goto outok; 1195 cnt++; 1196 } 1197 1198 error = tmpfs_dir_getdents(node, uio, &cnt); 1199 1200outok: 1201 MPASS(error >= -1); 1202 1203 if (error == -1) 1204 error = 0; 1205 1206 if (eofflag != NULL) 1207 *eofflag = 1208 (error == 0 && uio->uio_offset == TMPFS_DIRCOOKIE_EOF); 1209 1210 /* Update NFS-related variables. */ 1211 if (error == 0 && cookies != NULL && ncookies != NULL) { 1212 off_t i; 1213 off_t off = startoff; 1214 struct tmpfs_dirent *de = NULL; 1215 1216 *ncookies = cnt; 1217 *cookies = malloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK); 1218 1219 for (i = 0; i < cnt; i++) { 1220 MPASS(off != TMPFS_DIRCOOKIE_EOF); 1221 if (off == TMPFS_DIRCOOKIE_DOT) { 1222 off = TMPFS_DIRCOOKIE_DOTDOT; 1223 } else { 1224 if (off == TMPFS_DIRCOOKIE_DOTDOT) { 1225 de = TAILQ_FIRST(&node->tn_dir.tn_dirhead); 1226 } else if (de != NULL) { 1227 de = TAILQ_NEXT(de, td_entries); 1228 } else { 1229 de = tmpfs_dir_lookupbycookie(node, 1230 off); 1231 MPASS(de != NULL); 1232 de = TAILQ_NEXT(de, td_entries); 1233 } 1234 if (de == NULL) 1235 off = TMPFS_DIRCOOKIE_EOF; 1236 else 1237 off = tmpfs_dircookie(de); 1238 } 1239 1240 (*cookies)[i] = off; 1241 } 1242 MPASS(uio->uio_offset == off); 1243 } 1244 1245 return error; 1246} 1247 1248/* --------------------------------------------------------------------- */ 1249 1250static int 1251tmpfs_readlink(struct vop_readlink_args *v) 1252{ 1253 struct vnode *vp = v->a_vp; 1254 struct uio *uio = v->a_uio; 1255 1256 int error; 1257 struct tmpfs_node *node; 1258 1259 MPASS(uio->uio_offset == 0); 1260 MPASS(vp->v_type == VLNK); 1261 1262 node = VP_TO_TMPFS_NODE(vp); 1263 1264 error = uiomove(node->tn_link, MIN(node->tn_size, uio->uio_resid), 1265 uio); 1266 node->tn_status |= TMPFS_NODE_ACCESSED; 1267 1268 return error; 1269} 1270 1271/* --------------------------------------------------------------------- */ 1272 1273static int 1274tmpfs_inactive(struct vop_inactive_args *v) 1275{ 1276 struct vnode *vp = v->a_vp; 1277 struct thread *l = v->a_td; 1278 1279 struct tmpfs_node *node; 1280 1281 MPASS(VOP_ISLOCKED(vp)); 1282 1283 node = VP_TO_TMPFS_NODE(vp); 1284 1285 if (node->tn_links == 0) 1286 vrecycle(vp, l); 1287 1288 return 0; 1289} 1290 1291/* --------------------------------------------------------------------- */ 1292 1293int 1294tmpfs_reclaim(struct vop_reclaim_args *v) 1295{ 1296 struct vnode *vp = v->a_vp; 1297 1298 struct tmpfs_mount *tmp; 1299 struct tmpfs_node *node; 1300 1301 node = VP_TO_TMPFS_NODE(vp); 1302 tmp = VFS_TO_TMPFS(vp->v_mount); 1303 1304 vnode_destroy_vobject(vp); 1305 cache_purge(vp); 1306 tmpfs_free_vp(vp); 1307 1308 /* If the node referenced by this vnode was deleted by the user, 1309 * we must free its associated data structures (now that the vnode 1310 * is being reclaimed). */ 1311 if (node->tn_links == 0) 1312 tmpfs_free_node(tmp, node); 1313 1314 MPASS(vp->v_data == NULL); 1315 return 0; 1316} 1317 1318/* --------------------------------------------------------------------- */ 1319 1320static int 1321tmpfs_print(struct vop_print_args *v) 1322{ 1323 struct vnode *vp = v->a_vp; 1324 1325 struct tmpfs_node *node; 1326 1327 node = VP_TO_TMPFS_NODE(vp); 1328 1329 printf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n", 1330 node, node->tn_flags, node->tn_links); 1331 printf("\tmode 0%o, owner %d, group %d, size %" PRIdMAX 1332 ", status 0x%x\n", 1333 node->tn_mode, node->tn_uid, node->tn_gid, 1334 (uintmax_t)node->tn_size, node->tn_status); 1335 1336 if (vp->v_type == VFIFO) 1337 fifo_printinfo(vp); 1338 1339 printf("\n"); 1340 1341 return 0; 1342} 1343 1344/* --------------------------------------------------------------------- */ 1345 1346static int 1347tmpfs_pathconf(struct vop_pathconf_args *v) 1348{ 1349 int name = v->a_name; 1350 register_t *retval = v->a_retval; 1351 1352 int error; 1353 1354 error = 0; 1355 1356 switch (name) { 1357 case _PC_LINK_MAX: 1358 *retval = LINK_MAX; 1359 break; 1360 1361 case _PC_NAME_MAX: 1362 *retval = NAME_MAX; 1363 break; 1364 1365 case _PC_PATH_MAX: 1366 *retval = PATH_MAX; 1367 break; 1368 1369 case _PC_PIPE_BUF: 1370 *retval = PIPE_BUF; 1371 break; 1372 1373 case _PC_CHOWN_RESTRICTED: 1374 *retval = 1; 1375 break; 1376 1377 case _PC_NO_TRUNC: 1378 *retval = 1; 1379 break; 1380 1381 case _PC_SYNC_IO: 1382 *retval = 1; 1383 break; 1384 1385 case _PC_FILESIZEBITS: 1386 *retval = 0; /* XXX Don't know which value should I return. */ 1387 break; 1388 1389 default: 1390 error = EINVAL; 1391 } 1392 1393 return error; 1394} 1395 1396static int 1397tmpfs_vptofh(struct vop_vptofh_args *ap) 1398{ 1399 struct tmpfs_fid *tfhp; 1400 struct tmpfs_node *node; 1401 1402 tfhp = (struct tmpfs_fid *)ap->a_fhp; 1403 node = VP_TO_TMPFS_NODE(ap->a_vp); 1404 1405 tfhp->tf_len = sizeof(struct tmpfs_fid); 1406 tfhp->tf_id = node->tn_id; 1407 tfhp->tf_gen = node->tn_gen; 1408 1409 return (0); 1410} 1411 1412/* --------------------------------------------------------------------- */ 1413 1414/* 1415 * vnode operations vector used for files stored in a tmpfs file system. 1416 */ 1417struct vop_vector tmpfs_vnodeop_entries = { 1418 .vop_default = &default_vnodeops, 1419 .vop_lookup = vfs_cache_lookup, 1420 .vop_cachedlookup = tmpfs_lookup, 1421 .vop_create = tmpfs_create, 1422 .vop_mknod = tmpfs_mknod, 1423 .vop_open = tmpfs_open, 1424 .vop_close = tmpfs_close, 1425 .vop_access = tmpfs_access, 1426 .vop_getattr = tmpfs_getattr, 1427 .vop_setattr = tmpfs_setattr, 1428 .vop_read = tmpfs_read, 1429 .vop_write = tmpfs_write, 1430 .vop_fsync = tmpfs_fsync, 1431 .vop_remove = tmpfs_remove, 1432 .vop_link = tmpfs_link, 1433 .vop_rename = tmpfs_rename, 1434 .vop_mkdir = tmpfs_mkdir, 1435 .vop_rmdir = tmpfs_rmdir, 1436 .vop_symlink = tmpfs_symlink, 1437 .vop_readdir = tmpfs_readdir, 1438 .vop_readlink = tmpfs_readlink, 1439 .vop_inactive = tmpfs_inactive, 1440 .vop_reclaim = tmpfs_reclaim, 1441 .vop_print = tmpfs_print, 1442 .vop_pathconf = tmpfs_pathconf, 1443 .vop_vptofh = tmpfs_vptofh, 1444 .vop_bmap = VOP_EOPNOTSUPP, 1445}; 1446 1447