kernel - TMPFS - Initial port of NetBSD's tmpfs
[dragonfly.git] / sys / vfs / tmpfs / tmpfs_vnops.c
blob40754e4373b3c1b84684f4d56f18449173633c80
1 /* $NetBSD: tmpfs_vnops.c,v 1.39 2007/07/23 15:41:01 jmmv Exp $ */
3 /*-
4 * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
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.
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.
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.
34 * tmpfs vnode interface.
36 #include <sys/cdefs.h>
38 #include <sys/kernel.h>
39 #include <sys/kern_syscall.h>
40 #include <sys/param.h>
41 #include <sys/fcntl.h>
42 #include <sys/lockf.h>
43 #include <sys/priv.h>
44 #include <sys/proc.h>
45 #include <sys/resourcevar.h>
46 #include <sys/sched.h>
47 #include <sys/sfbuf.h>
48 #include <sys/stat.h>
49 #include <sys/systm.h>
50 #include <sys/unistd.h>
51 #include <sys/vfsops.h>
52 #include <sys/vnode.h>
54 #include <sys/mplock2.h>
56 #include <vm/vm.h>
57 #include <vm/vm_object.h>
58 #include <vm/vm_page.h>
59 #include <vm/vm_pager.h>
61 #include <vfs/fifofs/fifo.h>
62 #include <vfs/tmpfs/tmpfs_vnops.h>
63 #include <vfs/tmpfs/tmpfs.h>
65 MALLOC_DECLARE(M_TMPFS);
67 /* --------------------------------------------------------------------- */
69 static int
70 tmpfs_nresolve(struct vop_nresolve_args *v)
72 struct vnode *dvp = v->a_dvp;
73 struct vnode *vp = NULL;
74 struct namecache *ncp = v->a_nch->ncp;
75 struct ucred *cred = v->a_cred;
77 int error;
78 struct tmpfs_dirent *de;
79 struct tmpfs_node *dnode;
81 dnode = VP_TO_TMPFS_DIR(dvp);
83 if (!vn_islocked(dvp));
84 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
86 /* Check accessibility of requested node as a first step. */
87 error = VOP_ACCESS(dvp, VEXEC, cred);
88 if (error != 0)
89 goto out;
91 if (dnode->tn_dir.tn_parent == NULL) {
92 error = ENOENT;
93 goto out;
96 de = tmpfs_dir_lookup(dnode, NULL, ncp);
97 if (de == NULL) {
98 /* The entry was not found in the directory.
99 * This is OK if we are creating or renaming an
100 * entry and are working on the last component of
101 * the path name. */
102 error = VOP_ACCESS(dvp, VWRITE, cred);
103 if (error != 0)
104 goto out;
105 else {
106 error = ENOENT;
107 goto out;
109 } else {
110 struct tmpfs_node *tnode;
112 /* The entry was found, so get its associated
113 * tmpfs_node. */
114 tnode = de->td_node;
116 /* If we are not at the last path component and
117 * found a non-directory or non-link entry (which
118 * may itself be pointing to a directory), raise
119 * an error. */
120 if (tnode->tn_links > 1 &&
121 tnode->tn_type != VDIR && tnode->tn_type != VLNK) {
122 error = ENOTDIR;
123 goto out;
126 error = VOP_ACCESS(dvp, VWRITE, cred);
127 if (error != 0)
128 goto out;
130 /* Allocate a new vnode on the matching entry. */
131 error = tmpfs_alloc_vp(dvp->v_mount, tnode,
132 LK_EXCLUSIVE | LK_RETRY, &vp);
133 if (error != 0)
134 goto out;
136 if ((dnode->tn_mode & S_ISTXT) &&
137 VOP_ACCESS(vp, VWRITE, cred)) {
138 error = EPERM;
139 vp = NULL;
140 goto out;
144 KKASSERT(vp);
146 out:
147 vn_unlock(dvp);
148 /* Store the result of this lookup in the cache. Avoid this if the
149 * request was for creation, as it does not improve timings on
150 * emprical tests. */
151 if (vp) {
152 vn_unlock(vp);
153 cache_setvp(v->a_nch, vp);
154 vrele(vp);
156 if (error == ENOENT) {
157 cache_setvp(v->a_nch, NULL);
159 return error;
162 static int
163 tmpfs_nlookupdotdot(struct vop_nlookupdotdot_args *v)
165 struct vnode *dvp = v->a_dvp;
166 struct vnode **vpp = v->a_vpp;
167 struct tmpfs_node *dnode = VP_TO_TMPFS_NODE(dvp);
168 struct ucred *cred = v->a_cred;
169 int error;
171 *vpp = NULL;
172 /* Check accessibility of requested node as a first step. */
173 error = VOP_ACCESS(dvp, VEXEC, cred);
174 if (error != 0)
175 return error;
177 if (dnode->tn_dir.tn_parent != NULL) {
178 /* Allocate a new vnode on the matching entry. */
179 error = tmpfs_alloc_vp(dvp->v_mount, dnode->tn_dir.tn_parent,
180 LK_EXCLUSIVE | LK_RETRY, vpp);
182 if (*vpp)
183 vn_unlock(*vpp);
186 return (*vpp == NULL) ? ENOENT : 0;
189 /* --------------------------------------------------------------------- */
191 static int
192 tmpfs_ncreate(struct vop_ncreate_args *v)
194 struct vnode *dvp = v->a_dvp;
195 struct vnode **vpp = v->a_vpp;
196 struct namecache *ncp = v->a_nch->ncp;
197 struct vattr *vap = v->a_vap;
198 struct ucred *cred = v->a_cred;
199 int error;
201 KKASSERT(vap->va_type == VREG || vap->va_type == VSOCK);
203 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
204 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
205 if (error == 0) {
206 cache_setunresolved(v->a_nch);
207 cache_setvp(v->a_nch, *vpp);
209 vn_unlock(dvp);
211 return error;
213 /* --------------------------------------------------------------------- */
215 static int
216 tmpfs_nmknod(struct vop_nmknod_args *v)
218 struct vnode *dvp = v->a_dvp;
219 struct vnode **vpp = v->a_vpp;
220 struct namecache *ncp = v->a_nch->ncp;
221 struct vattr *vap = v->a_vap;
222 struct ucred *cred = v->a_cred;
223 int error;
225 if (vap->va_type != VBLK && vap->va_type != VCHR &&
226 vap->va_type != VFIFO)
227 return EINVAL;
229 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
230 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
231 if (error == 0) {
232 cache_setunresolved(v->a_nch);
233 cache_setvp(v->a_nch, *vpp);
235 vn_unlock(dvp);
237 return error;
240 /* --------------------------------------------------------------------- */
242 static int
243 tmpfs_open(struct vop_open_args *v)
245 struct vnode *vp = v->a_vp;
246 int mode = v->a_mode;
248 int error;
249 struct tmpfs_node *node;
251 KKASSERT(vn_islocked(vp));
253 node = VP_TO_TMPFS_NODE(vp);
255 /* The file is still active but all its names have been removed
256 * (e.g. by a "rmdir $(pwd)"). It cannot be opened any more as
257 * it is about to die. */
258 if (node->tn_links < 1)
259 return (ENOENT);
261 /* If the file is marked append-only, deny write requests. */
262 if (node->tn_flags & APPEND && (mode & (FWRITE | O_APPEND)) == FWRITE)
263 error = EPERM;
264 else {
265 return (vop_stdopen(v));
268 KKASSERT(vn_islocked(vp));
269 return error;
272 /* --------------------------------------------------------------------- */
274 static int
275 tmpfs_close(struct vop_close_args *v)
277 struct vnode *vp = v->a_vp;
278 struct tmpfs_node *node;
280 node = VP_TO_TMPFS_NODE(vp);
282 if (node->tn_links > 0) {
283 /* Update node times. No need to do it if the node has
284 * been deleted, because it will vanish after we return. */
285 tmpfs_update(vp);
288 return vop_stdclose(v);
291 /* --------------------------------------------------------------------- */
294 tmpfs_access(struct vop_access_args *v)
296 struct vnode *vp = v->a_vp;
297 int error;
298 struct tmpfs_node *node;
300 KKASSERT(vn_islocked(vp));
302 node = VP_TO_TMPFS_NODE(vp);
304 switch (vp->v_type) {
305 case VDIR:
306 /* FALLTHROUGH */
307 case VLNK:
308 /* FALLTHROUGH */
309 case VREG:
310 if (VWRITE && vp->v_mount->mnt_flag & MNT_RDONLY) {
311 error = EROFS;
312 goto out;
314 break;
316 case VBLK:
317 /* FALLTHROUGH */
318 case VCHR:
319 /* FALLTHROUGH */
320 case VSOCK:
321 /* FALLTHROUGH */
322 case VFIFO:
323 break;
325 default:
326 error = EINVAL;
327 goto out;
330 if (VWRITE && node->tn_flags & IMMUTABLE) {
331 error = EPERM;
332 goto out;
335 error = vop_helper_access(v, node->tn_uid, node->tn_gid, node->tn_mode, 0);
337 out:
339 return error;
342 /* --------------------------------------------------------------------- */
345 tmpfs_getattr(struct vop_getattr_args *v)
347 struct vnode *vp = v->a_vp;
348 struct vattr *vap = v->a_vap;
350 struct tmpfs_node *node;
351 int needunlock = 0;
353 if(!vn_islocked(vp)) {
354 needunlock = 1;
355 vn_lock(vp, LK_SHARED | LK_RETRY);
358 node = VP_TO_TMPFS_NODE(vp);
360 tmpfs_update(vp);
362 vap->va_type = vp->v_type;
363 vap->va_mode = node->tn_mode;
364 vap->va_nlink = node->tn_links;
365 vap->va_uid = node->tn_uid;
366 vap->va_gid = node->tn_gid;
367 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
368 vap->va_fileid = node->tn_id;
369 vap->va_size = node->tn_size;
370 vap->va_blocksize = PAGE_SIZE;
371 vap->va_atime.tv_sec = node->tn_atime;
372 vap->va_atime.tv_nsec = node->tn_atimensec;
373 vap->va_mtime.tv_sec = node->tn_mtime;
374 vap->va_mtime.tv_nsec = node->tn_mtimensec;
375 vap->va_ctime.tv_sec = node->tn_ctime;
376 vap->va_ctime.tv_nsec = node->tn_ctimensec;
377 vap->va_gen = node->tn_gen;
378 vap->va_flags = node->tn_flags;
379 if (vp->v_type == VBLK || vp->v_type == VCHR)
381 vap->va_rmajor = umajor(node->tn_rdev);
382 vap->va_rminor = uminor(node->tn_rdev);
384 vap->va_bytes = round_page(node->tn_size);
385 vap->va_filerev = 0;
387 if (needunlock)
388 vn_unlock(vp);
390 return 0;
393 /* --------------------------------------------------------------------- */
396 tmpfs_setattr(struct vop_setattr_args *v)
398 struct vnode *vp = v->a_vp;
399 struct vattr *vap = v->a_vap;
400 struct ucred *cred = v->a_cred;
402 int error = 0;
403 int needunlock = 0;
405 if(!vn_islocked(vp)) {
406 needunlock = 1;
407 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
410 /* Abort if any unsettable attribute is given. */
411 if (vap->va_type != VNON ||
412 vap->va_nlink != VNOVAL ||
413 vap->va_fsid != VNOVAL ||
414 vap->va_fileid != VNOVAL ||
415 vap->va_blocksize != VNOVAL ||
416 vap->va_gen != VNOVAL ||
417 vap->va_rmajor != VNOVAL ||
418 vap->va_bytes != VNOVAL)
419 error = EINVAL;
421 if (error == 0 && (vap->va_flags != VNOVAL))
422 error = tmpfs_chflags(vp, vap->va_flags, cred);
424 if (error == 0 && (vap->va_size != VNOVAL))
425 error = tmpfs_chsize(vp, vap->va_size, cred);
427 if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL))
428 error = tmpfs_chown(vp, vap->va_uid, vap->va_gid, cred);
430 if (error == 0 && (vap->va_mode != (mode_t)VNOVAL))
431 error = tmpfs_chmod(vp, vap->va_mode, cred);
433 if (error == 0 && ((vap->va_atime.tv_sec != VNOVAL &&
434 vap->va_atime.tv_nsec != VNOVAL) ||
435 (vap->va_mtime.tv_sec != VNOVAL &&
436 vap->va_mtime.tv_nsec != VNOVAL) ))
437 error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime,
438 vap->va_vaflags, cred);
440 /* Update the node times. We give preference to the error codes
441 * generated by this function rather than the ones that may arise
442 * from tmpfs_update. */
443 tmpfs_update(vp);
445 if (needunlock)
446 vn_unlock(vp);
448 return error;
451 /* --------------------------------------------------------------------- */
453 static int
454 tmpfs_fsync(struct vop_fsync_args *v)
456 struct vnode *vp = v->a_vp;
458 tmpfs_update(vp);
461 return 0;
464 /* --------------------------------------------------------------------- */
466 static int
467 tmpfs_read (struct vop_read_args *ap)
469 struct buf *bp;
470 struct vnode *vp = ap->a_vp;
471 struct uio *uio = ap->a_uio;
472 struct tmpfs_node *node;
473 int error;
474 off_t offset;
475 off_t base_offset;
476 size_t len;
477 int got_mplock;
479 error = 0;
480 if (uio->uio_resid == 0) {
481 return error;
484 node = VP_TO_TMPFS_NODE(vp);
486 if (uio->uio_offset < 0)
487 return (EINVAL);
488 if (vp->v_type != VREG)
489 return (EINVAL);
491 vn_lock(vp, LK_SHARED | LK_RETRY);
493 #ifdef SMP
494 if(curthread->td_mpcount)
495 got_mplock = -1;
496 else
497 got_mplock = 0;
498 #else
499 got_mplock = -1;
500 #endif
502 while (uio->uio_resid > 0 && uio->uio_offset < node->tn_size) {
504 * Use buffer cache I/O (via tmpfs_strategy)
506 offset = (off_t)uio->uio_offset & BMASK;
507 base_offset = (off_t)uio->uio_offset - offset;
508 bp = getcacheblk(vp, base_offset);
509 if (bp == NULL)
511 if (got_mplock == 0) {
512 got_mplock = 1;
513 get_mplock();
516 error = bread(vp, base_offset, BSIZE, &bp);
517 if (error) {
518 brelse(bp);
519 kprintf("tmpfs_read bread error %d\n", error);
520 break;
524 if (got_mplock == 0) {
525 got_mplock = 1;
526 get_mplock();
530 * Figure out how many bytes we can actually copy this loop.
532 len = BSIZE - offset;
533 if (len > uio->uio_resid)
534 len = uio->uio_resid;
535 if (len > node->tn_size - uio->uio_offset)
536 len = (size_t)(node->tn_size - uio->uio_offset);
538 error = uiomove((char *)bp->b_data + offset, len, uio);
539 bqrelse(bp);
540 if (error) {
541 kprintf("tmpfs_read uiomove error %d\n", error);
542 break;
546 if (got_mplock > 0)
547 rel_mplock();
549 TMPFS_NODE_LOCK(node);
550 node->tn_status |= TMPFS_NODE_ACCESSED;
551 TMPFS_NODE_UNLOCK(node);
553 vn_unlock(vp);
555 return(error);
558 static int
559 tmpfs_write (struct vop_write_args *ap)
561 struct buf *bp;
562 struct vnode *vp = ap->a_vp;
563 struct uio *uio = ap->a_uio;
564 struct thread *td = uio->uio_td;
565 struct tmpfs_node *node;
566 boolean_t extended;
567 off_t oldsize;
568 int error;
569 off_t offset;
570 off_t base_offset;
571 size_t len;
572 struct rlimit limit;
573 int got_mplock;
574 int trivial = 0;
576 error = 0;
577 if (uio->uio_resid == 0) {
578 return error;
581 node = VP_TO_TMPFS_NODE(vp);
583 if (vp->v_type != VREG)
584 return (EINVAL);
586 oldsize = node->tn_size;
587 if (ap->a_ioflag & IO_APPEND)
588 uio->uio_offset = node->tn_size;
591 * Check for illegal write offsets.
593 if (uio->uio_offset + uio->uio_resid >
594 VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize)
595 return (EFBIG);
597 if (vp->v_type == VREG && td != NULL) {
598 error = kern_getrlimit(RLIMIT_FSIZE, &limit);
599 if (error != 0)
600 return error;
601 if (uio->uio_offset + uio->uio_resid > limit.rlim_cur) {
602 ksignal(td->td_proc, SIGXFSZ);
603 return (EFBIG);
609 * Extend the file's size if necessary
611 extended = (uio->uio_offset + uio->uio_resid) > node->tn_size;
613 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
614 #ifdef SMP
615 if(curthread->td_mpcount)
616 got_mplock = -1;
617 else {
618 got_mplock = 1;
619 get_mplock();
621 #else
622 got_mplock = -1;
623 #endif
624 crit_enter();
625 while (uio->uio_resid > 0) {
627 * Use buffer cache I/O (via tmpfs_strategy)
629 offset = (off_t)uio->uio_offset & BMASK;
630 base_offset = (off_t)uio->uio_offset - offset;
631 len = BSIZE - offset;
632 if (len > uio->uio_resid)
633 len = uio->uio_resid;
635 if ((uio->uio_offset + len) > node->tn_size) {
636 trivial = uio->uio_offset <= node->tn_size;
637 error = tmpfs_reg_resize(vp, uio->uio_offset + len, trivial);
638 if (error)
639 break;
642 bp = getblk(vp, base_offset, BSIZE, GETBLK_BHEAVY, 0);
643 vfs_bio_clrbuf(bp);
645 error = uiomove((char *)bp->b_data + offset, len, uio);
646 if (error) {
647 kprintf("tmpfs_write uiomove error %d\n", error);
648 brelse(bp);
649 break;
652 if (uio->uio_offset > node->tn_size)
653 node->tn_size = uio->uio_offset;
656 * The data has been loaded into the buffer, write it out. (via tmpfs_strategy)
658 * call bdwrite() because we don't care about storage io flag (ap->a_ioflag) for a swap I/O
659 * maybe bawrite() for IO_DIRECT, bwrite() for IO_SYNC
661 * XXX: need to implement tmpfs_bmap() for a dirty bit handling of bdwrite()
663 bdwrite(bp);
664 if (bp->b_error) {
665 kprintf("tmpfs_write bwrite error %d\n", error);
666 break;
669 crit_exit();
671 if (got_mplock > 0)
672 rel_mplock();
674 if (error) {
675 if (extended)
676 (void)tmpfs_reg_resize(vp, oldsize, trivial);
677 return error;
680 TMPFS_NODE_LOCK(node);
681 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED |
682 (extended? TMPFS_NODE_CHANGED : 0);
684 if (node->tn_mode & (S_ISUID | S_ISGID)) {
685 if (priv_check_cred(ap->a_cred, PRIV_VFS_RETAINSUGID, 0))
686 node->tn_mode &= ~(S_ISUID | S_ISGID);
688 TMPFS_NODE_UNLOCK(node);
690 vn_unlock(vp);
692 return(error);
695 static int
696 tmpfs_advlock (struct vop_advlock_args *ap)
698 struct tmpfs_node *node;
699 struct vnode *vp = ap->a_vp;
701 node = VP_TO_TMPFS_NODE(vp);
703 return (lf_advlock(ap, &node->tn_advlock, node->tn_size));
707 static int
708 tmpfs_strategy(struct vop_strategy_args *ap)
710 struct bio *bio = ap->a_bio;
711 struct vnode *vp = ap->a_vp;
712 struct tmpfs_node *node;
713 vm_object_t uobj;
715 if (vp->v_type != VREG)
716 return EINVAL;
718 node = VP_TO_TMPFS_NODE(vp);
720 uobj = node->tn_reg.tn_aobj;
722 * call swap_pager_strategy to store vm object into swap device
724 swap_pager_strategy(uobj, bio);
726 return 0;
729 static int
730 tmpfs_bmap(struct vop_bmap_args *ap)
732 if (ap->a_doffsetp != NULL)
733 *ap->a_doffsetp = ap->a_loffset;
734 if (ap->a_runp != NULL)
735 *ap->a_runp = 0;
736 if (ap->a_runb != NULL)
737 *ap->a_runb = 0;
739 return 0;
741 /* --------------------------------------------------------------------- */
743 static int
744 tmpfs_nremove(struct vop_nremove_args *v)
746 struct vnode *dvp = v->a_dvp;
747 struct namecache *ncp = v->a_nch->ncp;
748 struct vnode *vp = ncp->nc_vp;
749 int error;
750 struct tmpfs_dirent *de;
751 struct tmpfs_mount *tmp;
752 struct tmpfs_node *dnode;
753 struct tmpfs_node *node;
755 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
756 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
758 if (vp->v_type == VDIR) {
759 error = EISDIR;
760 goto out;
763 dnode = VP_TO_TMPFS_DIR(dvp);
764 node = VP_TO_TMPFS_NODE(vp);
765 tmp = VFS_TO_TMPFS(vp->v_mount);
766 de = tmpfs_dir_lookup(dnode, node, ncp);
767 if (de == NULL) {
768 error = ENOENT;
769 goto out;
772 /* Files marked as immutable or append-only cannot be deleted. */
773 if ((node->tn_flags & (IMMUTABLE | APPEND | NOUNLINK)) ||
774 (dnode->tn_flags & APPEND)) {
775 error = EPERM;
776 goto out;
779 /* Remove the entry from the directory; as it is a file, we do not
780 * have to change the number of hard links of the directory. */
781 tmpfs_dir_detach(dvp, de);
783 /* Free the directory entry we just deleted. Note that the node
784 * referred by it will not be removed until the vnode is really
785 * reclaimed. */
786 tmpfs_free_dirent(tmp, de, TRUE);
788 if (node->tn_links > 0) {
789 TMPFS_NODE_LOCK(node);
790 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
791 TMPFS_NODE_MODIFIED;
792 TMPFS_NODE_UNLOCK(node);
795 cache_setunresolved(v->a_nch);
796 cache_setvp(v->a_nch, NULL);
797 cache_inval_vp(vp, CINV_DESTROY);
798 error = 0;
801 out:
802 vn_unlock(vp);
803 vn_unlock(dvp);
805 return error;
808 /* --------------------------------------------------------------------- */
810 static int
811 tmpfs_nlink(struct vop_nlink_args *v)
813 struct vnode *dvp = v->a_dvp;
814 struct vnode *vp = v->a_vp;
815 struct namecache *ncp = v->a_nch->ncp;
817 int error;
818 struct tmpfs_dirent *de;
819 struct tmpfs_node *node;
821 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
822 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
825 KKASSERT(dvp != vp); /* XXX When can this be false? */
827 node = VP_TO_TMPFS_NODE(vp);
829 /* XXX: Why aren't the following two tests done by the caller? */
831 /* Hard links of directories are forbidden. */
832 if (vp->v_type == VDIR) {
833 error = EPERM;
834 goto out;
837 /* Cannot create cross-device links. */
838 if (dvp->v_mount != vp->v_mount) {
839 error = EXDEV;
840 goto out;
843 /* Ensure that we do not overflow the maximum number of links imposed
844 * by the system. */
845 KKASSERT(node->tn_links <= LINK_MAX);
846 if (node->tn_links == LINK_MAX) {
847 error = EMLINK;
848 goto out;
851 /* We cannot create links of files marked immutable or append-only. */
852 if (node->tn_flags & (IMMUTABLE | APPEND)) {
853 error = EPERM;
854 goto out;
857 /* Allocate a new directory entry to represent the node. */
858 error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount), node,
859 ncp->nc_name, ncp->nc_nlen, &de);
860 if (error != 0)
861 goto out;
863 /* Insert the new directory entry into the appropriate directory. */
864 tmpfs_dir_attach(dvp, de);
866 /* vp link count has changed, so update node times. */
868 TMPFS_NODE_LOCK(node);
869 node->tn_status |= TMPFS_NODE_CHANGED;
870 TMPFS_NODE_UNLOCK(node);
871 tmpfs_update(vp);
873 cache_setunresolved(v->a_nch);
874 cache_setvp(v->a_nch, vp);
875 error = 0;
877 out:
878 vn_unlock(vp);
879 vn_unlock(dvp);
881 return error;
884 /* --------------------------------------------------------------------- */
886 static int
887 tmpfs_nrename(struct vop_nrename_args *v)
889 struct vnode *fdvp = v->a_fdvp;
890 struct namecache *fncp = v->a_fnch->ncp;
891 struct vnode *fvp = fncp->nc_vp;
892 struct vnode *tdvp = v->a_tdvp;
893 struct namecache *tncp = v->a_tnch->ncp;
894 struct vnode *tvp = tncp->nc_vp;
896 char *newname;
897 int error;
898 struct tmpfs_dirent *de;
899 struct tmpfs_mount *tmp;
900 struct tmpfs_node *fdnode;
901 struct tmpfs_node *fnode;
902 struct tmpfs_node *tnode;
903 struct tmpfs_node *tdnode;
905 vn_lock(tdvp, LK_EXCLUSIVE | LK_RETRY);
906 if(tvp != NULL && tdvp != tvp)
907 vn_lock(tvp, LK_EXCLUSIVE | LK_RETRY);
909 tnode = (tvp == NULL) ? NULL : VP_TO_TMPFS_NODE(tvp);
911 /* Disallow cross-device renames.
912 * XXX Why isn't this done by the caller? */
913 if (fvp->v_mount != tdvp->v_mount ||
914 (tvp != NULL && fvp->v_mount != tvp->v_mount)) {
915 error = EXDEV;
916 goto out;
919 tmp = VFS_TO_TMPFS(tdvp->v_mount);
920 tdnode = VP_TO_TMPFS_DIR(tdvp);
922 /* If source and target are the same file, there is nothing to do. */
923 if (fvp == tvp) {
924 error = 0;
925 goto out;
928 /* If we need to move the directory between entries, lock the
929 * source so that we can safely operate on it. */
930 if (tdvp != fdvp) {
931 error = vn_lock(fdvp, LK_EXCLUSIVE | LK_RETRY);
932 if (error != 0)
933 goto out;
935 fdnode = VP_TO_TMPFS_DIR(fdvp);
936 fnode = VP_TO_TMPFS_NODE(fvp);
937 de = tmpfs_dir_lookup(fdnode, fnode, fncp);
939 /* Avoid manipulating '.' and '..' entries. */
940 if (de == NULL) {
941 error = ENOENT;
942 goto out_locked;
944 KKASSERT(de->td_node == fnode);
946 /* If re-naming a directory to another preexisting directory
947 * ensure that the target directory is empty so that its
948 * removal causes no side effects.
949 * Kern_rename gurantees the destination to be a directory
950 * if the source is one. */
951 if (tvp != NULL) {
952 KKASSERT(tnode != NULL);
954 if ((tnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
955 (tdnode->tn_flags & (APPEND | IMMUTABLE))) {
956 error = EPERM;
957 goto out_locked;
960 if (fnode->tn_type == VDIR && tnode->tn_type == VDIR) {
961 if (tnode->tn_size > 0) {
962 error = ENOTEMPTY;
963 goto out_locked;
965 } else if (fnode->tn_type == VDIR && tnode->tn_type != VDIR) {
966 error = ENOTDIR;
967 goto out_locked;
968 } else if (fnode->tn_type != VDIR && tnode->tn_type == VDIR) {
969 error = EISDIR;
970 goto out_locked;
971 } else {
972 KKASSERT(fnode->tn_type != VDIR &&
973 tnode->tn_type != VDIR);
977 if ((fnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND))
978 || (fdnode->tn_flags & (APPEND | IMMUTABLE))) {
979 error = EPERM;
980 goto out_locked;
983 /* Ensure that we have enough memory to hold the new name, if it
984 * has to be changed. */
985 if (fncp->nc_nlen != tncp->nc_nlen ||
986 bcmp(fncp->nc_name, tncp->nc_name, fncp->nc_nlen) != 0) {
987 newname = kmalloc(tncp->nc_nlen, M_TMPFSNAME, M_WAITOK);
988 } else
989 newname = NULL;
991 /* If the node is being moved to another directory, we have to do
992 * the move. */
993 if (fdnode != tdnode) {
994 /* In case we are moving a directory, we have to adjust its
995 * parent to point to the new parent. */
996 if (de->td_node->tn_type == VDIR) {
997 struct tmpfs_node *n;
999 /* Ensure the target directory is not a child of the
1000 * directory being moved. Otherwise, we'd end up
1001 * with stale nodes. */
1002 n = tdnode;
1003 /* TMPFS_LOCK garanties that no nodes are freed while
1004 * traversing the list. Nodes can only be marked as
1005 * removed: tn_parent == NULL. */
1006 TMPFS_LOCK(tmp);
1007 TMPFS_NODE_LOCK(n);
1008 while (n != n->tn_dir.tn_parent) {
1009 struct tmpfs_node *parent;
1011 if (n == fnode) {
1012 TMPFS_NODE_UNLOCK(n);
1013 TMPFS_UNLOCK(tmp);
1014 error = EINVAL;
1015 if (newname != NULL)
1016 kfree(newname, M_TMPFSNAME);
1017 goto out_locked;
1019 parent = n->tn_dir.tn_parent;
1020 if (parent == NULL) {
1021 n = NULL;
1022 break;
1024 TMPFS_NODE_LOCK(parent);
1025 if (parent->tn_dir.tn_parent == NULL) {
1026 TMPFS_NODE_UNLOCK(parent);
1027 n = NULL;
1028 break;
1030 n = parent;
1032 TMPFS_NODE_UNLOCK(n);
1033 TMPFS_UNLOCK(tmp);
1034 if (n == NULL) {
1035 error = EINVAL;
1036 if (newname != NULL)
1037 kfree(newname, M_TMPFSNAME);
1038 goto out_locked;
1041 /* Adjust the parent pointer. */
1042 TMPFS_VALIDATE_DIR(fnode);
1043 TMPFS_NODE_LOCK(de->td_node);
1044 de->td_node->tn_dir.tn_parent = tdnode;
1046 /* As a result of changing the target of the '..'
1047 * entry, the link count of the source and target
1048 * directories has to be adjusted. */
1049 TMPFS_NODE_LOCK(tdnode);
1050 TMPFS_ASSERT_LOCKED(tdnode);
1051 TMPFS_NODE_LOCK(fdnode);
1052 TMPFS_ASSERT_LOCKED(fdnode);
1054 tdnode->tn_links++;
1055 fdnode->tn_links--;
1057 TMPFS_NODE_UNLOCK(fdnode);
1058 TMPFS_NODE_UNLOCK(tdnode);
1059 TMPFS_NODE_UNLOCK(de->td_node);
1062 /* Do the move: just remove the entry from the source directory
1063 * and insert it into the target one. */
1064 tmpfs_dir_detach(fdvp, de);
1065 tmpfs_dir_attach(tdvp, de);
1068 /* If the name has changed, we need to make it effective by changing
1069 * it in the directory entry. */
1070 if (newname != NULL) {
1072 kfree(de->td_name, M_TMPFSNAME);
1073 de->td_namelen = (uint16_t)tncp->nc_nlen;
1074 bcopy(tncp->nc_name, newname, tncp->nc_nlen);
1075 newname[tncp->nc_nlen] = '\0';
1076 de->td_name = newname;
1078 TMPFS_NODE_LOCK(tdnode);
1079 TMPFS_NODE_LOCK(fdnode);
1081 fnode->tn_status |= TMPFS_NODE_CHANGED;
1082 tdnode->tn_status |= TMPFS_NODE_MODIFIED;
1084 TMPFS_NODE_UNLOCK(fdnode);
1085 TMPFS_NODE_UNLOCK(tdnode);
1088 /* If we are overwriting an entry, we have to remove the old one
1089 * from the target directory. */
1090 if (tvp != NULL) {
1091 /* Remove the old entry from the target directory. */
1092 de = tmpfs_dir_lookup(tdnode, tnode, tncp);
1093 tmpfs_dir_detach(tdvp, de);
1095 /* Free the directory entry we just deleted. Note that the
1096 * node referred by it will not be removed until the vnode is
1097 * really reclaimed. */
1098 tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), de, TRUE);
1100 cache_inval_vp(tvp, CINV_DESTROY);
1103 cache_rename(v->a_fnch, v->a_tnch);
1104 error = 0;
1106 out_locked:
1107 if (fdnode != tdnode)
1108 vn_unlock(fdvp);
1110 out:
1111 /* Release target nodes. */
1112 /* XXX: I don't understand when tdvp can be the same as tvp, but
1113 * other code takes care of this... */
1114 if (tdvp == tvp)
1115 vrele(tdvp);
1116 else {
1117 if (tvp != NULL)
1118 vn_unlock(tvp);
1119 vn_unlock(tdvp);
1122 return error;
1125 /* --------------------------------------------------------------------- */
1127 static int
1128 tmpfs_nmkdir(struct vop_nmkdir_args *v)
1130 struct vnode *dvp = v->a_dvp;
1131 struct vnode **vpp = v->a_vpp;
1132 struct namecache *ncp = v->a_nch->ncp;
1133 struct vattr *vap = v->a_vap;
1134 struct ucred *cred = v->a_cred;
1135 int error;
1137 KKASSERT(vap->va_type == VDIR);
1139 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1140 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
1141 if (error == 0) {
1142 cache_setunresolved(v->a_nch);
1143 cache_setvp(v->a_nch, *vpp);
1145 vn_unlock(dvp);
1147 return error;
1150 /* --------------------------------------------------------------------- */
1152 static int
1153 tmpfs_nrmdir(struct vop_nrmdir_args *v)
1155 struct vnode *dvp = v->a_dvp;
1156 struct namecache *ncp = v->a_nch->ncp;
1157 struct vnode *vp = ncp->nc_vp;
1159 int error;
1160 struct tmpfs_dirent *de;
1161 struct tmpfs_mount *tmp;
1162 struct tmpfs_node *dnode;
1163 struct tmpfs_node *node;
1165 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1166 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1168 tmp = VFS_TO_TMPFS(dvp->v_mount);
1169 dnode = VP_TO_TMPFS_DIR(dvp);
1170 node = VP_TO_TMPFS_DIR(vp);
1172 /* Directories with more than two entries ('.' and '..') cannot be
1173 * removed. */
1174 if (node->tn_size > 0) {
1175 error = ENOTEMPTY;
1176 goto out;
1179 if ((dnode->tn_flags & APPEND)
1180 || (node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
1181 error = EPERM;
1182 goto out;
1185 /* This invariant holds only if we are not trying to remove "..".
1186 * We checked for that above so this is safe now. */
1187 KKASSERT(node->tn_dir.tn_parent == dnode);
1189 /* Get the directory entry associated with node (vp). This was
1190 * filled by tmpfs_lookup while looking up the entry. */
1191 de = tmpfs_dir_lookup(dnode, node, ncp);
1192 KKASSERT(TMPFS_DIRENT_MATCHES(de,
1193 ncp->nc_name,
1194 ncp->nc_nlen));
1196 /* Check flags to see if we are allowed to remove the directory. */
1197 if (dnode->tn_flags & APPEND
1198 || node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) {
1199 error = EPERM;
1200 goto out;
1204 /* Detach the directory entry from the directory (dnode). */
1205 tmpfs_dir_detach(dvp, de);
1207 /* No vnode should be allocated for this entry from this point */
1208 TMPFS_NODE_LOCK(node);
1209 TMPFS_ASSERT_ELOCKED(node);
1210 TMPFS_NODE_LOCK(dnode);
1211 TMPFS_ASSERT_ELOCKED(dnode);
1213 node->tn_links--;
1214 node->tn_dir.tn_parent = NULL;
1215 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
1216 TMPFS_NODE_MODIFIED;
1218 dnode->tn_links--;
1219 dnode->tn_status |= TMPFS_NODE_ACCESSED | \
1220 TMPFS_NODE_CHANGED | TMPFS_NODE_MODIFIED;
1222 TMPFS_NODE_UNLOCK(dnode);
1223 TMPFS_NODE_UNLOCK(node);
1225 /* Free the directory entry we just deleted. Note that the node
1226 * referred by it will not be removed until the vnode is really
1227 * reclaimed. */
1228 tmpfs_free_dirent(tmp, de, TRUE);
1230 /* Release the deleted vnode (will destroy the node, notify
1231 * interested parties and clean it from the cache). */
1233 TMPFS_NODE_LOCK(dnode);
1234 dnode->tn_status |= TMPFS_NODE_CHANGED;
1235 TMPFS_NODE_UNLOCK(dnode);
1236 tmpfs_update(dvp);
1238 cache_setunresolved(v->a_nch);
1239 cache_setvp(v->a_nch, NULL);
1240 cache_inval_vp(vp, CINV_DESTROY);
1241 error = 0;
1243 out:
1244 vn_unlock(vp);
1245 vn_unlock(dvp);
1247 return error;
1250 /* --------------------------------------------------------------------- */
1252 static int
1253 tmpfs_nsymlink(struct vop_nsymlink_args *v)
1255 struct vnode *dvp = v->a_dvp;
1256 struct vnode **vpp = v->a_vpp;
1257 struct namecache *ncp = v->a_nch->ncp;
1258 struct vattr *vap = v->a_vap;
1259 struct ucred *cred = v->a_cred;
1260 char *target = v->a_target;
1261 int error;
1263 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1264 vap->va_type = VLNK;
1265 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, target);
1266 if (error == 0) {
1267 cache_setunresolved(v->a_nch);
1268 cache_setvp(v->a_nch, *vpp);
1270 vn_unlock(dvp);
1272 return error;
1275 /* --------------------------------------------------------------------- */
1277 static int
1278 tmpfs_readdir(struct vop_readdir_args *v)
1280 struct vnode *vp = v->a_vp;
1281 struct uio *uio = v->a_uio;
1282 int *eofflag = v->a_eofflag;
1283 off_t **cookies = v->a_cookies;
1284 int *ncookies = v->a_ncookies;
1286 int error;
1287 off_t startoff;
1288 off_t cnt = 0;
1289 struct tmpfs_node *node;
1291 /* This operation only makes sense on directory nodes. */
1292 if (vp->v_type != VDIR)
1293 return ENOTDIR;
1295 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1297 node = VP_TO_TMPFS_DIR(vp);
1298 startoff = uio->uio_offset;
1300 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) {
1301 error = tmpfs_dir_getdotdent(node, uio);
1302 if (error != 0)
1303 goto outok;
1304 cnt++;
1307 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT) {
1308 error = tmpfs_dir_getdotdotdent(node, uio);
1309 if (error != 0)
1310 goto outok;
1311 cnt++;
1314 error = tmpfs_dir_getdents(node, uio, &cnt);
1316 outok:
1317 KKASSERT(error >= -1);
1319 if (error == -1)
1320 error = 0;
1322 if (eofflag != NULL)
1323 *eofflag =
1324 (error == 0 && uio->uio_offset == TMPFS_DIRCOOKIE_EOF);
1326 /* Update NFS-related variables. */
1327 if (error == 0 && cookies != NULL && ncookies != NULL) {
1328 off_t i;
1329 off_t off = startoff;
1330 struct tmpfs_dirent *de = NULL;
1332 *ncookies = cnt;
1333 *cookies = kmalloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK);
1335 for (i = 0; i < cnt; i++) {
1336 KKASSERT(off != TMPFS_DIRCOOKIE_EOF);
1337 if (off == TMPFS_DIRCOOKIE_DOT) {
1338 off = TMPFS_DIRCOOKIE_DOTDOT;
1339 } else {
1340 if (off == TMPFS_DIRCOOKIE_DOTDOT) {
1341 de = TAILQ_FIRST(&node->tn_dir.tn_dirhead);
1342 } else if (de != NULL) {
1343 de = TAILQ_NEXT(de, td_entries);
1344 } else {
1345 de = tmpfs_dir_lookupbycookie(node,
1346 off);
1347 KKASSERT(de != NULL);
1348 de = TAILQ_NEXT(de, td_entries);
1350 if (de == NULL)
1351 off = TMPFS_DIRCOOKIE_EOF;
1352 else
1353 off = tmpfs_dircookie(de);
1356 (*cookies)[i] = off;
1358 KKASSERT(uio->uio_offset == off);
1360 vn_unlock(vp);
1362 return error;
1365 /* --------------------------------------------------------------------- */
1367 static int
1368 tmpfs_readlink(struct vop_readlink_args *v)
1370 struct vnode *vp = v->a_vp;
1371 struct uio *uio = v->a_uio;
1373 int error;
1374 struct tmpfs_node *node;
1376 KKASSERT(uio->uio_offset == 0);
1377 KKASSERT(vp->v_type == VLNK);
1379 node = VP_TO_TMPFS_NODE(vp);
1381 error = uiomove(node->tn_link, MIN(node->tn_size, uio->uio_resid),
1382 uio);
1383 TMPFS_NODE_LOCK(node);
1384 node->tn_status |= TMPFS_NODE_ACCESSED;
1385 TMPFS_NODE_UNLOCK(node);
1387 return error;
1390 /* --------------------------------------------------------------------- */
1392 static int
1393 tmpfs_inactive(struct vop_inactive_args *v)
1395 struct vnode *vp = v->a_vp;
1397 struct tmpfs_node *node;
1399 KKASSERT(vn_islocked(vp));
1401 node = VP_TO_TMPFS_NODE(vp);
1403 TMPFS_NODE_LOCK(node);
1404 if (node->tn_links == 0 &&
1405 (node->tn_vpstate & TMPFS_VNODE_DOOMED)) {
1406 TMPFS_NODE_UNLOCK(node);
1407 vrecycle(vp);
1409 else
1410 TMPFS_NODE_UNLOCK(node);
1412 return 0;
1415 /* --------------------------------------------------------------------- */
1418 tmpfs_reclaim(struct vop_reclaim_args *v)
1420 struct vnode *vp = v->a_vp;
1422 struct tmpfs_mount *tmp;
1423 struct tmpfs_node *node;
1425 node = VP_TO_TMPFS_NODE(vp);
1426 tmp = VFS_TO_TMPFS(vp->v_mount);
1428 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1429 tmpfs_free_vp(vp);
1431 /* If the node referenced by this vnode was deleted by the user,
1432 * we must free its associated data structures (now that the vnode
1433 * is being reclaimed). */
1434 TMPFS_NODE_LOCK(node);
1435 if (node->tn_links == 0 &&
1436 (node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0) {
1437 node->tn_vpstate = TMPFS_VNODE_DOOMED;
1438 TMPFS_NODE_UNLOCK(node);
1439 tmpfs_free_node(tmp, node);
1441 else
1442 TMPFS_NODE_UNLOCK(node);
1444 vn_unlock(vp);
1446 KKASSERT(vp->v_data == NULL);
1447 return 0;
1450 /* --------------------------------------------------------------------- */
1452 static int
1453 tmpfs_print(struct vop_print_args *v)
1455 struct vnode *vp = v->a_vp;
1457 struct tmpfs_node *node;
1459 node = VP_TO_TMPFS_NODE(vp);
1461 kprintf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n",
1462 node, node->tn_flags, node->tn_links);
1463 kprintf("\tmode 0%o, owner %d, group %d, size %ju, status 0x%x\n",
1464 node->tn_mode, node->tn_uid, node->tn_gid,
1465 (uintmax_t)node->tn_size, node->tn_status);
1467 if (vp->v_type == VFIFO)
1468 fifo_printinfo(vp);
1470 kprintf("\n");
1472 return 0;
1475 /* --------------------------------------------------------------------- */
1477 static int
1478 tmpfs_pathconf(struct vop_pathconf_args *v)
1480 int name = v->a_name;
1481 register_t *retval = v->a_retval;
1483 int error;
1485 error = 0;
1487 switch (name) {
1488 case _PC_LINK_MAX:
1489 *retval = LINK_MAX;
1490 break;
1492 case _PC_NAME_MAX:
1493 *retval = NAME_MAX;
1494 break;
1496 case _PC_PATH_MAX:
1497 *retval = PATH_MAX;
1498 break;
1500 case _PC_PIPE_BUF:
1501 *retval = PIPE_BUF;
1502 break;
1504 case _PC_CHOWN_RESTRICTED:
1505 *retval = 1;
1506 break;
1508 case _PC_NO_TRUNC:
1509 *retval = 1;
1510 break;
1512 case _PC_SYNC_IO:
1513 *retval = 1;
1514 break;
1516 case _PC_FILESIZEBITS:
1517 *retval = 0; /* XXX Don't know which value should I return. */
1518 break;
1520 default:
1521 error = EINVAL;
1524 return error;
1527 /* --------------------------------------------------------------------- */
1530 * vnode operations vector used for files stored in a tmpfs file system.
1532 struct vop_ops tmpfs_vnode_vops = {
1533 .vop_default = vop_defaultop,
1534 .vop_getpages = vop_stdgetpages,
1535 .vop_putpages = vop_stdputpages,
1536 .vop_ncreate = tmpfs_ncreate,
1537 .vop_nresolve = tmpfs_nresolve,
1538 .vop_nlookupdotdot = tmpfs_nlookupdotdot,
1539 .vop_nmknod = tmpfs_nmknod,
1540 .vop_open = tmpfs_open,
1541 .vop_close = tmpfs_close,
1542 .vop_access = tmpfs_access,
1543 .vop_getattr = tmpfs_getattr,
1544 .vop_setattr = tmpfs_setattr,
1545 .vop_read = tmpfs_read,
1546 .vop_write = tmpfs_write,
1547 .vop_fsync = tmpfs_fsync,
1548 .vop_nremove = tmpfs_nremove,
1549 .vop_nlink = tmpfs_nlink,
1550 .vop_nrename = tmpfs_nrename,
1551 .vop_nmkdir = tmpfs_nmkdir,
1552 .vop_nrmdir = tmpfs_nrmdir,
1553 .vop_nsymlink = tmpfs_nsymlink,
1554 .vop_readdir = tmpfs_readdir,
1555 .vop_readlink = tmpfs_readlink,
1556 .vop_inactive = tmpfs_inactive,
1557 .vop_reclaim = tmpfs_reclaim,
1558 .vop_print = tmpfs_print,
1559 .vop_pathconf = tmpfs_pathconf,
1560 // .vop_bmap = tmpfs_bmap,
1561 .vop_bmap = (void *)vop_eopnotsupp,
1562 .vop_strategy = tmpfs_strategy,
1563 .vop_advlock = tmpfs_advlock,