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