2 * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * $NetBSD: tmpfs_vnops.c,v 1.39 2007/07/23 15:41:01 jmmv Exp $
34 * tmpfs vnode interface.
37 #include <sys/kernel.h>
38 #include <sys/kern_syscall.h>
39 #include <sys/param.h>
40 #include <sys/fcntl.h>
41 #include <sys/lockf.h>
44 #include <sys/resourcevar.h>
45 #include <sys/sched.h>
47 #include <sys/systm.h>
48 #include <sys/unistd.h>
49 #include <sys/vfsops.h>
50 #include <sys/vnode.h>
51 #include <sys/mountctl.h>
54 #include <vm/vm_extern.h>
55 #include <vm/vm_object.h>
56 #include <vm/vm_page.h>
57 #include <vm/vm_pager.h>
58 #include <vm/swap_pager.h>
62 #include <vfs/fifofs/fifo.h>
63 #include <vfs/tmpfs/tmpfs_vnops.h>
65 #include <vfs/tmpfs/tmpfs.h>
69 static void tmpfs_strategy_done(struct bio *bio);
73 tmpfs_knote(struct vnode *vp, int flags)
76 KNOTE(&vp->v_pollinfo.vpi_kqinfo.ki_note, flags);
80 /* --------------------------------------------------------------------- */
83 tmpfs_nresolve(struct vop_nresolve_args *v)
85 struct vnode *dvp = v->a_dvp;
86 struct vnode *vp = NULL;
87 struct namecache *ncp = v->a_nch->ncp;
88 struct tmpfs_node *tnode;
92 struct tmpfs_dirent *de;
93 struct tmpfs_node *dnode;
96 lwkt_gettoken(&mp->mnt_token);
98 dnode = VP_TO_TMPFS_DIR(dvp);
100 de = tmpfs_dir_lookup(dnode, NULL, ncp);
105 * Allocate a vnode for the node we found.
108 error = tmpfs_alloc_vp(dvp->v_mount, tnode,
109 LK_EXCLUSIVE | LK_RETRY, &vp);
117 * Store the result of this lookup in the cache. Avoid this if the
118 * request was for creation, as it does not improve timings on
123 cache_setvp(v->a_nch, vp);
125 } else if (error == ENOENT) {
126 cache_setvp(v->a_nch, NULL);
129 lwkt_reltoken(&mp->mnt_token);
134 tmpfs_nlookupdotdot(struct vop_nlookupdotdot_args *v)
136 struct vnode *dvp = v->a_dvp;
137 struct vnode **vpp = v->a_vpp;
138 struct tmpfs_node *dnode = VP_TO_TMPFS_NODE(dvp);
139 struct ucred *cred = v->a_cred;
146 lwkt_gettoken(&mp->mnt_token);
148 /* Check accessibility of requested node as a first step. */
149 error = VOP_ACCESS(dvp, VEXEC, cred);
151 lwkt_reltoken(&mp->mnt_token);
155 if (dnode->tn_dir.tn_parent != NULL) {
156 /* Allocate a new vnode on the matching entry. */
157 error = tmpfs_alloc_vp(dvp->v_mount, dnode->tn_dir.tn_parent,
158 LK_EXCLUSIVE | LK_RETRY, vpp);
164 lwkt_reltoken(&mp->mnt_token);
166 return (*vpp == NULL) ? ENOENT : 0;
169 /* --------------------------------------------------------------------- */
172 tmpfs_ncreate(struct vop_ncreate_args *v)
174 struct vnode *dvp = v->a_dvp;
175 struct vnode **vpp = v->a_vpp;
176 struct namecache *ncp = v->a_nch->ncp;
177 struct vattr *vap = v->a_vap;
178 struct ucred *cred = v->a_cred;
183 lwkt_gettoken(&mp->mnt_token);
185 KKASSERT(vap->va_type == VREG || vap->va_type == VSOCK);
187 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
189 cache_setunresolved(v->a_nch);
190 cache_setvp(v->a_nch, *vpp);
191 tmpfs_knote(dvp, NOTE_WRITE);
194 lwkt_reltoken(&mp->mnt_token);
198 /* --------------------------------------------------------------------- */
201 tmpfs_nmknod(struct vop_nmknod_args *v)
203 struct vnode *dvp = v->a_dvp;
204 struct vnode **vpp = v->a_vpp;
205 struct namecache *ncp = v->a_nch->ncp;
206 struct vattr *vap = v->a_vap;
207 struct ucred *cred = v->a_cred;
208 struct mount *mp = dvp->v_mount;
211 lwkt_gettoken(&mp->mnt_token);
213 if (vap->va_type != VBLK && vap->va_type != VCHR &&
214 vap->va_type != VFIFO) {
215 lwkt_reltoken(&mp->mnt_token);
219 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
221 cache_setunresolved(v->a_nch);
222 cache_setvp(v->a_nch, *vpp);
223 tmpfs_knote(dvp, NOTE_WRITE);
226 lwkt_reltoken(&mp->mnt_token);
231 /* --------------------------------------------------------------------- */
234 tmpfs_open(struct vop_open_args *v)
236 struct vnode *vp = v->a_vp;
237 int mode = v->a_mode;
238 struct mount *mp = vp->v_mount;
239 struct tmpfs_node *node;
242 lwkt_gettoken(&mp->mnt_token);
243 node = VP_TO_TMPFS_NODE(vp);
246 /* The file is still active but all its names have been removed
247 * (e.g. by a "rmdir $(pwd)"). It cannot be opened any more as
248 * it is about to die. */
249 if (node->tn_links < 1)
253 /* If the file is marked append-only, deny write requests. */
254 if ((node->tn_flags & APPEND) &&
255 (mode & (FWRITE | O_APPEND)) == FWRITE) {
258 error = (vop_stdopen(v));
261 lwkt_reltoken(&mp->mnt_token);
265 /* --------------------------------------------------------------------- */
268 tmpfs_close(struct vop_close_args *v)
270 struct vnode *vp = v->a_vp;
271 struct tmpfs_node *node;
274 lwkt_gettoken(&vp->v_mount->mnt_token);
275 node = VP_TO_TMPFS_NODE(vp);
277 if (node->tn_links > 0) {
279 * Update node times. No need to do it if the node has
280 * been deleted, because it will vanish after we return.
285 error = vop_stdclose(v);
287 lwkt_reltoken(&vp->v_mount->mnt_token);
292 /* --------------------------------------------------------------------- */
295 tmpfs_access(struct vop_access_args *v)
297 struct vnode *vp = v->a_vp;
299 struct tmpfs_node *node;
301 lwkt_gettoken(&vp->v_mount->mnt_token);
302 node = VP_TO_TMPFS_NODE(vp);
304 switch (vp->v_type) {
310 if ((v->a_mode & VWRITE) &&
311 (vp->v_mount->mnt_flag & MNT_RDONLY)) {
331 if ((v->a_mode & VWRITE) && (node->tn_flags & IMMUTABLE)) {
336 error = vop_helper_access(v, node->tn_uid, node->tn_gid,
340 lwkt_reltoken(&vp->v_mount->mnt_token);
344 /* --------------------------------------------------------------------- */
347 tmpfs_getattr(struct vop_getattr_args *v)
349 struct vnode *vp = v->a_vp;
350 struct vattr *vap = v->a_vap;
351 struct tmpfs_node *node;
353 lwkt_gettoken(&vp->v_mount->mnt_token);
354 node = VP_TO_TMPFS_NODE(vp);
358 vap->va_type = vp->v_type;
359 vap->va_mode = node->tn_mode;
360 vap->va_nlink = node->tn_links;
361 vap->va_uid = node->tn_uid;
362 vap->va_gid = node->tn_gid;
363 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
364 vap->va_fileid = node->tn_id;
365 vap->va_size = node->tn_size;
366 vap->va_blocksize = PAGE_SIZE;
367 vap->va_atime.tv_sec = node->tn_atime;
368 vap->va_atime.tv_nsec = node->tn_atimensec;
369 vap->va_mtime.tv_sec = node->tn_mtime;
370 vap->va_mtime.tv_nsec = node->tn_mtimensec;
371 vap->va_ctime.tv_sec = node->tn_ctime;
372 vap->va_ctime.tv_nsec = node->tn_ctimensec;
373 vap->va_gen = node->tn_gen;
374 vap->va_flags = node->tn_flags;
375 if (vp->v_type == VBLK || vp->v_type == VCHR)
377 vap->va_rmajor = umajor(node->tn_rdev);
378 vap->va_rminor = uminor(node->tn_rdev);
380 vap->va_bytes = round_page(node->tn_size);
383 lwkt_reltoken(&vp->v_mount->mnt_token);
388 /* --------------------------------------------------------------------- */
391 tmpfs_setattr(struct vop_setattr_args *v)
393 struct vnode *vp = v->a_vp;
394 struct vattr *vap = v->a_vap;
395 struct ucred *cred = v->a_cred;
396 struct tmpfs_node *node = VP_TO_TMPFS_NODE(vp);
400 lwkt_gettoken(&vp->v_mount->mnt_token);
401 if (error == 0 && (vap->va_flags != VNOVAL)) {
402 error = tmpfs_chflags(vp, vap->va_flags, cred);
403 kflags |= NOTE_ATTRIB;
406 if (error == 0 && (vap->va_size != VNOVAL)) {
407 if (vap->va_size > node->tn_size)
408 kflags |= NOTE_WRITE | NOTE_EXTEND;
410 kflags |= NOTE_WRITE;
411 error = tmpfs_chsize(vp, vap->va_size, cred);
414 if (error == 0 && (vap->va_uid != (uid_t)VNOVAL ||
415 vap->va_gid != (gid_t)VNOVAL)) {
416 error = tmpfs_chown(vp, vap->va_uid, vap->va_gid, cred);
417 kflags |= NOTE_ATTRIB;
420 if (error == 0 && (vap->va_mode != (mode_t)VNOVAL)) {
421 error = tmpfs_chmod(vp, vap->va_mode, cred);
422 kflags |= NOTE_ATTRIB;
425 if (error == 0 && ((vap->va_atime.tv_sec != VNOVAL &&
426 vap->va_atime.tv_nsec != VNOVAL) ||
427 (vap->va_mtime.tv_sec != VNOVAL &&
428 vap->va_mtime.tv_nsec != VNOVAL) )) {
429 error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime,
430 vap->va_vaflags, cred);
431 kflags |= NOTE_ATTRIB;
434 /* Update the node times. We give preference to the error codes
435 * generated by this function rather than the ones that may arise
436 * from tmpfs_update. */
438 tmpfs_knote(vp, kflags);
440 lwkt_reltoken(&vp->v_mount->mnt_token);
445 /* --------------------------------------------------------------------- */
448 * fsync is usually a NOP, but we must take action when unmounting or
452 tmpfs_fsync(struct vop_fsync_args *v)
454 struct tmpfs_node *node;
455 struct vnode *vp = v->a_vp;
457 lwkt_gettoken(&vp->v_mount->mnt_token);
458 node = VP_TO_TMPFS_NODE(vp);
461 if (vp->v_type == VREG) {
462 if (vp->v_flag & VRECLAIMED) {
463 if (node->tn_links == 0)
464 tmpfs_truncate(vp, 0);
466 vfsync(v->a_vp, v->a_waitfor, 1, NULL, NULL);
470 lwkt_reltoken(&vp->v_mount->mnt_token);
474 /* --------------------------------------------------------------------- */
477 tmpfs_read (struct vop_read_args *ap)
480 struct vnode *vp = ap->a_vp;
481 struct uio *uio = ap->a_uio;
482 struct tmpfs_node *node;
492 if (uio->uio_offset < 0)
494 if (vp->v_type != VREG)
498 * Extract node, try to shortcut the operation through
499 * the VM page cache, allowing us to avoid buffer cache
502 node = VP_TO_TMPFS_NODE(vp);
503 resid = uio->uio_resid;
504 error = vop_helper_read_shortcut(ap);
507 if (uio->uio_resid == 0) {
514 * Fall-through to our normal read code.
516 while (uio->uio_resid > 0 && uio->uio_offset < node->tn_size) {
518 * Use buffer cache I/O (via tmpfs_strategy)
520 offset = (size_t)uio->uio_offset & BMASK;
521 base_offset = (off_t)uio->uio_offset - offset;
522 bp = getcacheblk(vp, base_offset, BSIZE, 0);
524 lwkt_gettoken(&vp->v_mount->mnt_token);
525 error = bread(vp, base_offset, BSIZE, &bp);
528 lwkt_reltoken(&vp->v_mount->mnt_token);
529 kprintf("tmpfs_read bread error %d\n", error);
532 lwkt_reltoken(&vp->v_mount->mnt_token);
535 * tmpfs pretty much fiddles directly with the VM
536 * system, don't let it exhaust it or we won't play
537 * nice with other processes.
539 * Only do this if the VOP is coming from a normal
540 * read/write. The VM system handles the case for
543 if (uio->uio_segflg != UIO_NOCOPY)
548 * Figure out how many bytes we can actually copy this loop.
550 len = BSIZE - offset;
551 if (len > uio->uio_resid)
552 len = uio->uio_resid;
553 if (len > node->tn_size - uio->uio_offset)
554 len = (size_t)(node->tn_size - uio->uio_offset);
556 error = uiomovebp(bp, (char *)bp->b_data + offset, len, uio);
559 kprintf("tmpfs_read uiomove error %d\n", error);
565 TMPFS_NODE_LOCK(node);
566 node->tn_status |= TMPFS_NODE_ACCESSED;
567 TMPFS_NODE_UNLOCK(node);
573 tmpfs_write (struct vop_write_args *ap)
576 struct vnode *vp = ap->a_vp;
577 struct uio *uio = ap->a_uio;
578 struct thread *td = uio->uio_td;
579 struct tmpfs_node *node;
591 if (uio->uio_resid == 0) {
595 node = VP_TO_TMPFS_NODE(vp);
597 if (vp->v_type != VREG)
600 lwkt_gettoken(&vp->v_mount->mnt_token);
602 oldsize = node->tn_size;
603 if (ap->a_ioflag & IO_APPEND)
604 uio->uio_offset = node->tn_size;
607 * Check for illegal write offsets.
609 if (uio->uio_offset + uio->uio_resid >
610 VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize) {
611 lwkt_reltoken(&vp->v_mount->mnt_token);
616 * NOTE: Ignore if UIO does not come from a user thread (e.g. VN).
618 if (vp->v_type == VREG && td != NULL && td->td_lwp != NULL) {
619 error = kern_getrlimit(RLIMIT_FSIZE, &limit);
621 lwkt_reltoken(&vp->v_mount->mnt_token);
624 if (uio->uio_offset + uio->uio_resid > limit.rlim_cur) {
625 ksignal(td->td_proc, SIGXFSZ);
626 lwkt_reltoken(&vp->v_mount->mnt_token);
633 * Extend the file's size if necessary
635 extended = ((uio->uio_offset + uio->uio_resid) > node->tn_size);
637 while (uio->uio_resid > 0) {
639 * Use buffer cache I/O (via tmpfs_strategy)
641 offset = (size_t)uio->uio_offset & BMASK;
642 base_offset = (off_t)uio->uio_offset - offset;
643 len = BSIZE - offset;
644 if (len > uio->uio_resid)
645 len = uio->uio_resid;
647 if ((uio->uio_offset + len) > node->tn_size) {
648 trivial = (uio->uio_offset <= node->tn_size);
649 error = tmpfs_reg_resize(vp, uio->uio_offset + len, trivial);
655 * Read to fill in any gaps. Theoretically we could
656 * optimize this if the write covers the entire buffer
657 * and is not a UIO_NOCOPY write, however this can lead
658 * to a security violation exposing random kernel memory
659 * (whatever junk was in the backing VM pages before).
661 * So just use bread() to do the right thing.
663 error = bread(vp, base_offset, BSIZE, &bp);
664 error = uiomovebp(bp, (char *)bp->b_data + offset, len, uio);
666 kprintf("tmpfs_write uiomove error %d\n", error);
671 if (uio->uio_offset > node->tn_size) {
672 node->tn_size = uio->uio_offset;
673 kflags |= NOTE_EXTEND;
675 kflags |= NOTE_WRITE;
678 * Always try to flush the page in the UIO_NOCOPY case. This
679 * can come from the pageout daemon or during vnode eviction.
680 * It is not necessarily going to be marked IO_ASYNC/IO_SYNC.
682 * For the normal case we buwrite(), dirtying the underlying
683 * VM pages instead of dirtying the buffer and releasing the
684 * buffer as a clean buffer. This allows tmpfs to use
685 * essentially all available memory to cache file data.
686 * If we used bdwrite() the buffer cache would wind up
687 * flushing the data to swap too quickly.
689 * tmpfs pretty much fiddles directly with the VM
690 * system, don't let it exhaust it or we won't play
691 * nice with other processes. Only do this if the
692 * VOP is coming from a normal read/write. The VM system
693 * handles the case for UIO_NOCOPY.
695 bp->b_flags |= B_AGE;
696 if (uio->uio_segflg == UIO_NOCOPY) {
704 kprintf("tmpfs_write bwrite error %d\n", bp->b_error);
711 (void)tmpfs_reg_resize(vp, oldsize, trivial);
712 kflags &= ~NOTE_EXTEND;
718 * Currently we don't set the mtime on files modified via mmap()
719 * because we can't tell the difference between those modifications
720 * and an attempt by the pageout daemon to flush tmpfs pages to
723 * This is because in order to defer flushes as long as possible
724 * buwrite() works by marking the underlying VM pages dirty in
725 * order to be able to dispose of the buffer cache buffer without
728 TMPFS_NODE_LOCK(node);
729 if (uio->uio_segflg != UIO_NOCOPY)
730 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED;
732 node->tn_status |= TMPFS_NODE_CHANGED;
734 if (node->tn_mode & (S_ISUID | S_ISGID)) {
735 if (priv_check_cred(ap->a_cred, PRIV_VFS_RETAINSUGID, 0))
736 node->tn_mode &= ~(S_ISUID | S_ISGID);
738 TMPFS_NODE_UNLOCK(node);
741 tmpfs_knote(vp, kflags);
743 lwkt_reltoken(&vp->v_mount->mnt_token);
748 tmpfs_advlock (struct vop_advlock_args *ap)
750 struct tmpfs_node *node;
751 struct vnode *vp = ap->a_vp;
754 lwkt_gettoken(&vp->v_mount->mnt_token);
755 node = VP_TO_TMPFS_NODE(vp);
757 error = (lf_advlock(ap, &node->tn_advlock, node->tn_size));
758 lwkt_reltoken(&vp->v_mount->mnt_token);
764 * The strategy function is typically only called when memory pressure
765 * forces the system to attempt to pageout pages. It can also be called
766 * by [n]vtruncbuf() when a truncation cuts a page in half. Normal write
770 tmpfs_strategy(struct vop_strategy_args *ap)
772 struct bio *bio = ap->a_bio;
774 struct buf *bp = bio->bio_buf;
775 struct vnode *vp = ap->a_vp;
776 struct tmpfs_node *node;
781 if (vp->v_type != VREG) {
782 bp->b_resid = bp->b_bcount;
783 bp->b_flags |= B_ERROR | B_INVAL;
784 bp->b_error = EINVAL;
789 lwkt_gettoken(&vp->v_mount->mnt_token);
790 node = VP_TO_TMPFS_NODE(vp);
792 uobj = node->tn_reg.tn_aobj;
795 * Don't bother flushing to swap if there is no swap, just
796 * ensure that the pages are marked as needing a commit (still).
798 if (bp->b_cmd == BUF_CMD_WRITE && vm_swap_size == 0) {
799 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
800 m = bp->b_xio.xio_pages[i];
801 vm_page_need_commit(m);
807 nbio = push_bio(bio);
808 nbio->bio_done = tmpfs_strategy_done;
809 nbio->bio_offset = bio->bio_offset;
810 swap_pager_strategy(uobj, nbio);
813 lwkt_reltoken(&vp->v_mount->mnt_token);
818 * If we were unable to commit the pages to swap make sure they are marked
819 * as needing a commit (again). If we were, clear the flag to allow the
823 tmpfs_strategy_done(struct bio *bio)
831 if (bp->b_flags & B_ERROR) {
832 bp->b_flags &= ~B_ERROR;
835 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
836 m = bp->b_xio.xio_pages[i];
837 vm_page_need_commit(m);
840 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
841 m = bp->b_xio.xio_pages[i];
842 vm_page_clear_commit(m);
850 tmpfs_bmap(struct vop_bmap_args *ap)
852 if (ap->a_doffsetp != NULL)
853 *ap->a_doffsetp = ap->a_loffset;
854 if (ap->a_runp != NULL)
856 if (ap->a_runb != NULL)
862 /* --------------------------------------------------------------------- */
865 tmpfs_nremove(struct vop_nremove_args *v)
867 struct vnode *dvp = v->a_dvp;
868 struct namecache *ncp = v->a_nch->ncp;
871 struct tmpfs_dirent *de;
872 struct tmpfs_mount *tmp;
873 struct tmpfs_node *dnode;
874 struct tmpfs_node *node;
879 lwkt_gettoken(&mp->mnt_token);
882 * We have to acquire the vp from v->a_nch because we will likely
883 * unresolve the namecache entry, and a vrele/vput is needed to
884 * trigger the tmpfs_inactive/tmpfs_reclaim sequence.
886 * We have to use vget to clear any inactive state on the vnode,
887 * otherwise the vnode may remain inactive and thus tmpfs_inactive
888 * will not get called when we release it.
890 error = cache_vget(v->a_nch, v->a_cred, LK_SHARED, &vp);
891 KKASSERT(vp->v_mount == dvp->v_mount);
892 KKASSERT(error == 0);
895 if (vp->v_type == VDIR) {
900 dnode = VP_TO_TMPFS_DIR(dvp);
901 node = VP_TO_TMPFS_NODE(vp);
902 tmp = VFS_TO_TMPFS(vp->v_mount);
903 de = tmpfs_dir_lookup(dnode, node, ncp);
909 /* Files marked as immutable or append-only cannot be deleted. */
910 if ((node->tn_flags & (IMMUTABLE | APPEND | NOUNLINK)) ||
911 (dnode->tn_flags & APPEND)) {
916 /* Remove the entry from the directory; as it is a file, we do not
917 * have to change the number of hard links of the directory. */
918 tmpfs_dir_detach(dnode, de);
920 /* Free the directory entry we just deleted. Note that the node
921 * referred by it will not be removed until the vnode is really
923 tmpfs_free_dirent(tmp, de);
925 if (node->tn_links > 0) {
926 TMPFS_NODE_LOCK(node);
927 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
929 TMPFS_NODE_UNLOCK(node);
932 cache_unlink(v->a_nch);
933 tmpfs_knote(vp, NOTE_DELETE);
934 tmpfs_knote(dvp, NOTE_WRITE);
939 lwkt_reltoken(&mp->mnt_token);
944 /* --------------------------------------------------------------------- */
947 tmpfs_nlink(struct vop_nlink_args *v)
949 struct vnode *dvp = v->a_dvp;
950 struct vnode *vp = v->a_vp;
951 struct namecache *ncp = v->a_nch->ncp;
952 struct tmpfs_dirent *de;
953 struct tmpfs_node *node;
954 struct tmpfs_node *dnode;
958 if (dvp->v_mount != vp->v_mount)
962 lwkt_gettoken(&mp->mnt_token);
963 KKASSERT(dvp != vp); /* XXX When can this be false? */
965 node = VP_TO_TMPFS_NODE(vp);
966 dnode = VP_TO_TMPFS_NODE(dvp);
968 /* XXX: Why aren't the following two tests done by the caller? */
970 /* Hard links of directories are forbidden. */
971 if (vp->v_type == VDIR) {
976 /* Cannot create cross-device links. */
977 if (dvp->v_mount != vp->v_mount) {
982 /* Ensure that we do not overflow the maximum number of links imposed
984 KKASSERT(node->tn_links <= LINK_MAX);
985 if (node->tn_links == LINK_MAX) {
990 /* We cannot create links of files marked immutable or append-only. */
991 if (node->tn_flags & (IMMUTABLE | APPEND)) {
996 /* Allocate a new directory entry to represent the node. */
997 error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount), node,
998 ncp->nc_name, ncp->nc_nlen, &de);
1002 /* Insert the new directory entry into the appropriate directory. */
1003 tmpfs_dir_attach(dnode, de);
1005 /* vp link count has changed, so update node times. */
1007 TMPFS_NODE_LOCK(node);
1008 node->tn_status |= TMPFS_NODE_CHANGED;
1009 TMPFS_NODE_UNLOCK(node);
1012 tmpfs_knote(vp, NOTE_LINK);
1013 cache_setunresolved(v->a_nch);
1014 cache_setvp(v->a_nch, vp);
1015 tmpfs_knote(dvp, NOTE_WRITE);
1019 lwkt_reltoken(&mp->mnt_token);
1023 /* --------------------------------------------------------------------- */
1026 tmpfs_nrename(struct vop_nrename_args *v)
1028 struct vnode *fdvp = v->a_fdvp;
1029 struct namecache *fncp = v->a_fnch->ncp;
1030 struct vnode *fvp = fncp->nc_vp;
1031 struct vnode *tdvp = v->a_tdvp;
1032 struct namecache *tncp = v->a_tnch->ncp;
1034 struct tmpfs_dirent *de, *tde;
1035 struct tmpfs_mount *tmp;
1036 struct tmpfs_node *fdnode;
1037 struct tmpfs_node *fnode;
1038 struct tmpfs_node *tnode;
1039 struct tmpfs_node *tdnode;
1046 KKASSERT(fdvp->v_mount == fvp->v_mount);
1048 lwkt_gettoken(&mp->mnt_token);
1050 * Because tvp can get overwritten we have to vget it instead of
1051 * just vref or use it, otherwise it's VINACTIVE flag may not get
1052 * cleared and the node won't get destroyed.
1054 error = cache_vget(v->a_tnch, v->a_cred, LK_SHARED, &tvp);
1056 tnode = VP_TO_TMPFS_NODE(tvp);
1062 /* Disallow cross-device renames.
1063 * XXX Why isn't this done by the caller? */
1064 if (fvp->v_mount != tdvp->v_mount ||
1065 (tvp != NULL && fvp->v_mount != tvp->v_mount)) {
1070 tmp = VFS_TO_TMPFS(tdvp->v_mount);
1071 tdnode = VP_TO_TMPFS_DIR(tdvp);
1073 /* If source and target are the same file, there is nothing to do. */
1079 fdnode = VP_TO_TMPFS_DIR(fdvp);
1080 fnode = VP_TO_TMPFS_NODE(fvp);
1081 de = tmpfs_dir_lookup(fdnode, fnode, fncp);
1083 /* Avoid manipulating '.' and '..' entries. */
1088 KKASSERT(de->td_node == fnode);
1091 * If replacing an entry in the target directory and that entry
1092 * is a directory, it must be empty.
1094 * Kern_rename gurantees the destination to be a directory
1095 * if the source is one (it does?).
1098 KKASSERT(tnode != NULL);
1100 if ((tnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1101 (tdnode->tn_flags & (APPEND | IMMUTABLE))) {
1106 if (fnode->tn_type == VDIR && tnode->tn_type == VDIR) {
1107 if (tnode->tn_size > 0) {
1111 } else if (fnode->tn_type == VDIR && tnode->tn_type != VDIR) {
1114 } else if (fnode->tn_type != VDIR && tnode->tn_type == VDIR) {
1118 KKASSERT(fnode->tn_type != VDIR &&
1119 tnode->tn_type != VDIR);
1123 if ((fnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1124 (fdnode->tn_flags & (APPEND | IMMUTABLE))) {
1130 * Ensure that we have enough memory to hold the new name, if it
1131 * has to be changed.
1133 if (fncp->nc_nlen != tncp->nc_nlen ||
1134 bcmp(fncp->nc_name, tncp->nc_name, fncp->nc_nlen) != 0) {
1135 newname = kmalloc(tncp->nc_nlen + 1, tmp->tm_name_zone,
1136 M_WAITOK | M_NULLOK);
1137 if (newname == NULL) {
1141 bcopy(tncp->nc_name, newname, tncp->nc_nlen);
1142 newname[tncp->nc_nlen] = '\0';
1148 * Unlink entry from source directory. Note that the kernel has
1149 * already checked for illegal recursion cases (renaming a directory
1150 * into a subdirectory of itself).
1152 if (fdnode != tdnode) {
1153 tmpfs_dir_detach(fdnode, de);
1155 RB_REMOVE(tmpfs_dirtree, &fdnode->tn_dir.tn_dirtree, de);
1159 * Handle any name change. Swap with newname, we will
1160 * deallocate it at the end.
1162 if (newname != NULL) {
1164 TMPFS_NODE_LOCK(fnode);
1165 fnode->tn_status |= TMPFS_NODE_CHANGED;
1166 TMPFS_NODE_UNLOCK(fnode);
1168 oldname = de->td_name;
1169 de->td_name = newname;
1170 de->td_namelen = (uint16_t)tncp->nc_nlen;
1175 * If we are overwriting an entry, we have to remove the old one
1176 * from the target directory.
1179 /* Remove the old entry from the target directory. */
1180 tde = tmpfs_dir_lookup(tdnode, tnode, tncp);
1181 tmpfs_dir_detach(tdnode, tde);
1182 tmpfs_knote(tdnode->tn_vnode, NOTE_DELETE);
1185 * Free the directory entry we just deleted. Note that the
1186 * node referred by it will not be removed until the vnode is
1189 tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), tde);
1190 /*cache_inval_vp(tvp, CINV_DESTROY);*/
1194 * Link entry to target directory. If the entry
1195 * represents a directory move the parent linkage
1198 if (fdnode != tdnode) {
1199 if (de->td_node->tn_type == VDIR) {
1200 TMPFS_VALIDATE_DIR(fnode);
1202 tmpfs_dir_attach(tdnode, de);
1204 TMPFS_NODE_LOCK(tdnode);
1205 tdnode->tn_status |= TMPFS_NODE_MODIFIED;
1206 RB_INSERT(tmpfs_dirtree, &tdnode->tn_dir.tn_dirtree, de);
1207 TMPFS_NODE_UNLOCK(tdnode);
1214 kfree(newname, tmp->tm_name_zone);
1217 cache_rename(v->a_fnch, v->a_tnch);
1218 tmpfs_knote(v->a_fdvp, NOTE_WRITE);
1219 tmpfs_knote(v->a_tdvp, NOTE_WRITE);
1220 if (fnode->tn_vnode)
1221 tmpfs_knote(fnode->tn_vnode, NOTE_RENAME);
1231 lwkt_reltoken(&mp->mnt_token);
1236 /* --------------------------------------------------------------------- */
1239 tmpfs_nmkdir(struct vop_nmkdir_args *v)
1241 struct vnode *dvp = v->a_dvp;
1242 struct vnode **vpp = v->a_vpp;
1243 struct namecache *ncp = v->a_nch->ncp;
1244 struct vattr *vap = v->a_vap;
1245 struct ucred *cred = v->a_cred;
1251 lwkt_gettoken(&mp->mnt_token);
1252 KKASSERT(vap->va_type == VDIR);
1254 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
1256 cache_setunresolved(v->a_nch);
1257 cache_setvp(v->a_nch, *vpp);
1258 tmpfs_knote(dvp, NOTE_WRITE | NOTE_LINK);
1261 lwkt_reltoken(&mp->mnt_token);
1266 /* --------------------------------------------------------------------- */
1269 tmpfs_nrmdir(struct vop_nrmdir_args *v)
1271 struct vnode *dvp = v->a_dvp;
1272 struct namecache *ncp = v->a_nch->ncp;
1274 struct tmpfs_dirent *de;
1275 struct tmpfs_mount *tmp;
1276 struct tmpfs_node *dnode;
1277 struct tmpfs_node *node;
1282 lwkt_gettoken(&mp->mnt_token);
1285 * We have to acquire the vp from v->a_nch because we will likely
1286 * unresolve the namecache entry, and a vrele/vput is needed to
1287 * trigger the tmpfs_inactive/tmpfs_reclaim sequence.
1289 * We have to use vget to clear any inactive state on the vnode,
1290 * otherwise the vnode may remain inactive and thus tmpfs_inactive
1291 * will not get called when we release it.
1293 error = cache_vget(v->a_nch, v->a_cred, LK_SHARED, &vp);
1294 KKASSERT(error == 0);
1298 * Prevalidate so we don't hit an assertion later
1300 if (vp->v_type != VDIR) {
1305 tmp = VFS_TO_TMPFS(dvp->v_mount);
1306 dnode = VP_TO_TMPFS_DIR(dvp);
1307 node = VP_TO_TMPFS_DIR(vp);
1309 /* Directories with more than two entries ('.' and '..') cannot be
1311 if (node->tn_size > 0) {
1316 if ((dnode->tn_flags & APPEND)
1317 || (node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
1322 /* This invariant holds only if we are not trying to remove "..".
1323 * We checked for that above so this is safe now. */
1324 KKASSERT(node->tn_dir.tn_parent == dnode);
1326 /* Get the directory entry associated with node (vp). This was
1327 * filled by tmpfs_lookup while looking up the entry. */
1328 de = tmpfs_dir_lookup(dnode, node, ncp);
1329 KKASSERT(TMPFS_DIRENT_MATCHES(de,
1333 /* Check flags to see if we are allowed to remove the directory. */
1334 if ((dnode->tn_flags & APPEND) ||
1335 node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) {
1341 /* Detach the directory entry from the directory (dnode). */
1342 tmpfs_dir_detach(dnode, de);
1344 /* No vnode should be allocated for this entry from this point */
1345 TMPFS_NODE_LOCK(node);
1346 TMPFS_ASSERT_ELOCKED(node);
1347 TMPFS_NODE_LOCK(dnode);
1348 TMPFS_ASSERT_ELOCKED(dnode);
1351 * Must set parent linkage to NULL (tested by ncreate to disallow
1352 * the creation of new files/dirs in a deleted directory)
1354 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
1355 TMPFS_NODE_MODIFIED;
1357 dnode->tn_status |= TMPFS_NODE_ACCESSED | \
1358 TMPFS_NODE_CHANGED | TMPFS_NODE_MODIFIED;
1360 TMPFS_NODE_UNLOCK(dnode);
1361 TMPFS_NODE_UNLOCK(node);
1363 /* Free the directory entry we just deleted. Note that the node
1364 * referred by it will not be removed until the vnode is really
1366 tmpfs_free_dirent(tmp, de);
1368 /* Release the deleted vnode (will destroy the node, notify
1369 * interested parties and clean it from the cache). */
1371 TMPFS_NODE_LOCK(dnode);
1372 dnode->tn_status |= TMPFS_NODE_CHANGED;
1373 TMPFS_NODE_UNLOCK(dnode);
1376 cache_unlink(v->a_nch);
1377 tmpfs_knote(dvp, NOTE_WRITE | NOTE_LINK);
1383 lwkt_reltoken(&mp->mnt_token);
1388 /* --------------------------------------------------------------------- */
1391 tmpfs_nsymlink(struct vop_nsymlink_args *v)
1393 struct vnode *dvp = v->a_dvp;
1394 struct vnode **vpp = v->a_vpp;
1395 struct namecache *ncp = v->a_nch->ncp;
1396 struct vattr *vap = v->a_vap;
1397 struct ucred *cred = v->a_cred;
1398 char *target = v->a_target;
1399 struct mount *mp = dvp->v_mount;
1402 lwkt_gettoken(&mp->mnt_token);
1403 vap->va_type = VLNK;
1404 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, target);
1406 tmpfs_knote(*vpp, NOTE_WRITE);
1407 cache_setunresolved(v->a_nch);
1408 cache_setvp(v->a_nch, *vpp);
1411 lwkt_reltoken(&mp->mnt_token);
1416 /* --------------------------------------------------------------------- */
1419 tmpfs_readdir(struct vop_readdir_args *v)
1421 struct vnode *vp = v->a_vp;
1422 struct uio *uio = v->a_uio;
1423 int *eofflag = v->a_eofflag;
1424 off_t **cookies = v->a_cookies;
1425 int *ncookies = v->a_ncookies;
1426 struct tmpfs_mount *tmp;
1430 struct tmpfs_node *node;
1431 struct mount *mp = vp->v_mount;
1433 lwkt_gettoken(&mp->mnt_token);
1435 /* This operation only makes sense on directory nodes. */
1436 if (vp->v_type != VDIR) {
1437 lwkt_reltoken(&mp->mnt_token);
1441 tmp = VFS_TO_TMPFS(vp->v_mount);
1442 node = VP_TO_TMPFS_DIR(vp);
1443 startoff = uio->uio_offset;
1445 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) {
1446 error = tmpfs_dir_getdotdent(node, uio);
1452 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT) {
1453 error = tmpfs_dir_getdotdotdent(tmp, node, uio);
1459 error = tmpfs_dir_getdents(node, uio, &cnt);
1462 KKASSERT(error >= -1);
1467 if (eofflag != NULL)
1469 (error == 0 && uio->uio_offset == TMPFS_DIRCOOKIE_EOF);
1471 /* Update NFS-related variables. */
1472 if (error == 0 && cookies != NULL && ncookies != NULL) {
1474 off_t off = startoff;
1475 struct tmpfs_dirent *de = NULL;
1478 *cookies = kmalloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK);
1480 for (i = 0; i < cnt; i++) {
1481 KKASSERT(off != TMPFS_DIRCOOKIE_EOF);
1482 if (off == TMPFS_DIRCOOKIE_DOT) {
1483 off = TMPFS_DIRCOOKIE_DOTDOT;
1485 if (off == TMPFS_DIRCOOKIE_DOTDOT) {
1486 de = RB_MIN(tmpfs_dirtree, &node->tn_dir.tn_dirtree);
1487 } else if (de != NULL) {
1488 de = RB_NEXT(tmpfs_dirtree, &node->tn_dir.tn_dirtree, de);
1490 de = tmpfs_dir_lookupbycookie(node,
1492 KKASSERT(de != NULL);
1493 de = RB_NEXT(tmpfs_dirtree, &node->tn_dir.tn_dirtree, de);
1496 off = TMPFS_DIRCOOKIE_EOF;
1498 off = tmpfs_dircookie(de);
1501 (*cookies)[i] = off;
1503 KKASSERT(uio->uio_offset == off);
1506 lwkt_reltoken(&mp->mnt_token);
1511 /* --------------------------------------------------------------------- */
1514 tmpfs_readlink(struct vop_readlink_args *v)
1516 struct vnode *vp = v->a_vp;
1517 struct uio *uio = v->a_uio;
1518 struct mount *mp = vp->v_mount;
1520 struct tmpfs_node *node;
1522 lwkt_gettoken(&mp->mnt_token);
1524 KKASSERT(uio->uio_offset == 0);
1525 KKASSERT(vp->v_type == VLNK);
1527 node = VP_TO_TMPFS_NODE(vp);
1529 error = uiomove(node->tn_link, MIN(node->tn_size, uio->uio_resid),
1531 TMPFS_NODE_LOCK(node);
1532 node->tn_status |= TMPFS_NODE_ACCESSED;
1533 TMPFS_NODE_UNLOCK(node);
1535 lwkt_reltoken(&mp->mnt_token);
1540 /* --------------------------------------------------------------------- */
1543 tmpfs_inactive(struct vop_inactive_args *v)
1545 struct vnode *vp = v->a_vp;
1546 struct tmpfs_node *node;
1550 lwkt_gettoken(&mp->mnt_token);
1551 node = VP_TO_TMPFS_NODE(vp);
1558 lwkt_reltoken(&mp->mnt_token);
1563 * Get rid of unreferenced deleted vnodes sooner rather than
1564 * later so the data memory can be recovered immediately.
1566 * We must truncate the vnode to prevent the normal reclamation
1567 * path from flushing the data for the removed file to disk.
1569 TMPFS_NODE_LOCK(node);
1570 if ((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0 &&
1571 node->tn_links == 0)
1573 node->tn_vpstate = TMPFS_VNODE_DOOMED;
1574 TMPFS_NODE_UNLOCK(node);
1575 if (node->tn_type == VREG)
1576 tmpfs_truncate(vp, 0);
1579 TMPFS_NODE_UNLOCK(node);
1581 lwkt_reltoken(&mp->mnt_token);
1586 /* --------------------------------------------------------------------- */
1589 tmpfs_reclaim(struct vop_reclaim_args *v)
1591 struct vnode *vp = v->a_vp;
1592 struct tmpfs_mount *tmp;
1593 struct tmpfs_node *node;
1597 lwkt_gettoken(&mp->mnt_token);
1599 node = VP_TO_TMPFS_NODE(vp);
1600 tmp = VFS_TO_TMPFS(vp->v_mount);
1601 KKASSERT(mp == tmp->tm_mount);
1606 * If the node referenced by this vnode was deleted by the
1607 * user, we must free its associated data structures now that
1608 * the vnode is being reclaimed.
1610 * Directories have an extra link ref.
1612 TMPFS_NODE_LOCK(node);
1613 if ((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0 &&
1614 node->tn_links == 0) {
1615 node->tn_vpstate = TMPFS_VNODE_DOOMED;
1616 tmpfs_free_node(tmp, node);
1619 TMPFS_NODE_UNLOCK(node);
1621 lwkt_reltoken(&mp->mnt_token);
1623 KKASSERT(vp->v_data == NULL);
1627 /* --------------------------------------------------------------------- */
1630 tmpfs_mountctl(struct vop_mountctl_args *ap)
1632 struct tmpfs_mount *tmp;
1636 mp = ap->a_head.a_ops->head.vv_mount;
1637 lwkt_gettoken(&mp->mnt_token);
1640 case (MOUNTCTL_SET_EXPORT):
1641 tmp = (struct tmpfs_mount *) mp->mnt_data;
1643 if (ap->a_ctllen != sizeof(struct export_args))
1646 rc = vfs_export(mp, &tmp->tm_export,
1647 (const struct export_args *) ap->a_ctl);
1650 rc = vop_stdmountctl(ap);
1654 lwkt_reltoken(&mp->mnt_token);
1658 /* --------------------------------------------------------------------- */
1661 tmpfs_print(struct vop_print_args *v)
1663 struct vnode *vp = v->a_vp;
1665 struct tmpfs_node *node;
1667 node = VP_TO_TMPFS_NODE(vp);
1669 kprintf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n",
1670 node, node->tn_flags, node->tn_links);
1671 kprintf("\tmode 0%o, owner %d, group %d, size %ju, status 0x%x\n",
1672 node->tn_mode, node->tn_uid, node->tn_gid,
1673 (uintmax_t)node->tn_size, node->tn_status);
1675 if (vp->v_type == VFIFO)
1683 /* --------------------------------------------------------------------- */
1686 tmpfs_pathconf(struct vop_pathconf_args *v)
1688 int name = v->a_name;
1689 register_t *retval = v->a_retval;
1712 case _PC_CHOWN_RESTRICTED:
1724 case _PC_FILESIZEBITS:
1725 *retval = 0; /* XXX Don't know which value should I return. */
1735 /************************************************************************
1737 ************************************************************************/
1739 static void filt_tmpfsdetach(struct knote *kn);
1740 static int filt_tmpfsread(struct knote *kn, long hint);
1741 static int filt_tmpfswrite(struct knote *kn, long hint);
1742 static int filt_tmpfsvnode(struct knote *kn, long hint);
1744 static struct filterops tmpfsread_filtops =
1745 { FILTEROP_ISFD, NULL, filt_tmpfsdetach, filt_tmpfsread };
1746 static struct filterops tmpfswrite_filtops =
1747 { FILTEROP_ISFD, NULL, filt_tmpfsdetach, filt_tmpfswrite };
1748 static struct filterops tmpfsvnode_filtops =
1749 { FILTEROP_ISFD, NULL, filt_tmpfsdetach, filt_tmpfsvnode };
1752 tmpfs_kqfilter (struct vop_kqfilter_args *ap)
1754 struct vnode *vp = ap->a_vp;
1755 struct knote *kn = ap->a_kn;
1757 switch (kn->kn_filter) {
1759 kn->kn_fop = &tmpfsread_filtops;
1762 kn->kn_fop = &tmpfswrite_filtops;
1765 kn->kn_fop = &tmpfsvnode_filtops;
1768 return (EOPNOTSUPP);
1771 kn->kn_hook = (caddr_t)vp;
1773 knote_insert(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn);
1779 filt_tmpfsdetach(struct knote *kn)
1781 struct vnode *vp = (void *)kn->kn_hook;
1783 knote_remove(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn);
1787 filt_tmpfsread(struct knote *kn, long hint)
1789 struct vnode *vp = (void *)kn->kn_hook;
1790 struct tmpfs_node *node = VP_TO_TMPFS_NODE(vp);
1793 if (hint == NOTE_REVOKE) {
1794 kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT);
1799 * Interlock against MP races when performing this function.
1801 lwkt_gettoken(&vp->v_mount->mnt_token);
1802 off = node->tn_size - kn->kn_fp->f_offset;
1803 kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX;
1804 if (kn->kn_sfflags & NOTE_OLDAPI) {
1805 lwkt_reltoken(&vp->v_mount->mnt_token);
1809 if (kn->kn_data == 0) {
1810 kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX;
1812 lwkt_reltoken(&vp->v_mount->mnt_token);
1813 return (kn->kn_data != 0);
1817 filt_tmpfswrite(struct knote *kn, long hint)
1819 if (hint == NOTE_REVOKE)
1820 kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT);
1826 filt_tmpfsvnode(struct knote *kn, long hint)
1828 if (kn->kn_sfflags & hint)
1829 kn->kn_fflags |= hint;
1830 if (hint == NOTE_REVOKE) {
1831 kn->kn_flags |= (EV_EOF | EV_NODATA);
1834 return (kn->kn_fflags != 0);
1838 /* --------------------------------------------------------------------- */
1841 * vnode operations vector used for files stored in a tmpfs file system.
1843 struct vop_ops tmpfs_vnode_vops = {
1844 .vop_default = vop_defaultop,
1845 .vop_getpages = vop_stdgetpages,
1846 .vop_putpages = vop_stdputpages,
1847 .vop_ncreate = tmpfs_ncreate,
1848 .vop_nresolve = tmpfs_nresolve,
1849 .vop_nlookupdotdot = tmpfs_nlookupdotdot,
1850 .vop_nmknod = tmpfs_nmknod,
1851 .vop_open = tmpfs_open,
1852 .vop_close = tmpfs_close,
1853 .vop_access = tmpfs_access,
1854 .vop_getattr = tmpfs_getattr,
1855 .vop_setattr = tmpfs_setattr,
1856 .vop_read = tmpfs_read,
1857 .vop_write = tmpfs_write,
1858 .vop_fsync = tmpfs_fsync,
1859 .vop_mountctl = tmpfs_mountctl,
1860 .vop_nremove = tmpfs_nremove,
1861 .vop_nlink = tmpfs_nlink,
1862 .vop_nrename = tmpfs_nrename,
1863 .vop_nmkdir = tmpfs_nmkdir,
1864 .vop_nrmdir = tmpfs_nrmdir,
1865 .vop_nsymlink = tmpfs_nsymlink,
1866 .vop_readdir = tmpfs_readdir,
1867 .vop_readlink = tmpfs_readlink,
1868 .vop_inactive = tmpfs_inactive,
1869 .vop_reclaim = tmpfs_reclaim,
1870 .vop_print = tmpfs_print,
1871 .vop_pathconf = tmpfs_pathconf,
1872 .vop_bmap = tmpfs_bmap,
1873 .vop_strategy = tmpfs_strategy,
1874 .vop_advlock = tmpfs_advlock,
1875 .vop_kqfilter = tmpfs_kqfilter