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_pageout.h>
58 #include <vm/vm_pager.h>
59 #include <vm/swap_pager.h>
62 #include <vm/vm_page2.h>
64 #include <vfs/fifofs/fifo.h>
65 #include <vfs/tmpfs/tmpfs_vnops.h>
68 static void tmpfs_strategy_done(struct bio *bio);
72 tmpfs_knote(struct vnode *vp, int flags)
75 KNOTE(&vp->v_pollinfo.vpi_kqinfo.ki_note, flags);
79 /* --------------------------------------------------------------------- */
82 tmpfs_nresolve(struct vop_nresolve_args *v)
84 struct vnode *dvp = v->a_dvp;
85 struct vnode *vp = NULL;
86 struct namecache *ncp = v->a_nch->ncp;
87 struct tmpfs_node *tnode;
89 struct tmpfs_dirent *de;
90 struct tmpfs_node *dnode;
95 dnode = VP_TO_TMPFS_DIR(dvp);
97 TMPFS_NODE_LOCK_SH(dnode);
98 de = tmpfs_dir_lookup(dnode, NULL, ncp);
103 * Allocate a vnode for the node we found.
106 error = tmpfs_alloc_vp(dvp->v_mount, tnode,
107 LK_EXCLUSIVE | LK_RETRY, &vp);
111 TMPFS_NODE_UNLOCK(dnode);
113 TMPFS_NODE_LOCK(dnode);
114 dnode->tn_status |= TMPFS_NODE_ACCESSED;
115 TMPFS_NODE_UNLOCK(dnode);
118 * Store the result of this lookup in the cache. Avoid this if the
119 * request was for creation, as it does not improve timings on
124 cache_setvp(v->a_nch, vp);
126 } else if (error == ENOENT) {
127 cache_setvp(v->a_nch, NULL);
133 tmpfs_nlookupdotdot(struct vop_nlookupdotdot_args *v)
135 struct vnode *dvp = v->a_dvp;
136 struct vnode **vpp = v->a_vpp;
137 struct tmpfs_node *dnode = VP_TO_TMPFS_NODE(dvp);
138 struct ucred *cred = v->a_cred;
146 /* Check accessibility of requested node as a first step. */
147 error = VOP_ACCESS(dvp, VEXEC, cred);
151 if (dnode->tn_dir.tn_parent != NULL) {
152 /* Allocate a new vnode on the matching entry. */
153 error = tmpfs_alloc_vp(dvp->v_mount, dnode->tn_dir.tn_parent,
154 LK_EXCLUSIVE | LK_RETRY, vpp);
159 return (*vpp == NULL) ? ENOENT : 0;
162 /* --------------------------------------------------------------------- */
165 tmpfs_ncreate(struct vop_ncreate_args *v)
167 struct vnode *dvp = v->a_dvp;
168 struct vnode **vpp = v->a_vpp;
169 struct namecache *ncp = v->a_nch->ncp;
170 struct vattr *vap = v->a_vap;
171 struct ucred *cred = v->a_cred;
177 KKASSERT(vap->va_type == VREG || vap->va_type == VSOCK);
179 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
181 cache_setunresolved(v->a_nch);
182 cache_setvp(v->a_nch, *vpp);
183 tmpfs_knote(dvp, NOTE_WRITE);
187 /* --------------------------------------------------------------------- */
190 tmpfs_nmknod(struct vop_nmknod_args *v)
192 struct vnode *dvp = v->a_dvp;
193 struct vnode **vpp = v->a_vpp;
194 struct namecache *ncp = v->a_nch->ncp;
195 struct vattr *vap = v->a_vap;
196 struct ucred *cred = v->a_cred;
199 if (vap->va_type != VBLK && vap->va_type != VCHR &&
200 vap->va_type != VFIFO) {
204 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
206 cache_setunresolved(v->a_nch);
207 cache_setvp(v->a_nch, *vpp);
208 tmpfs_knote(dvp, NOTE_WRITE);
213 /* --------------------------------------------------------------------- */
216 tmpfs_open(struct vop_open_args *v)
218 struct vnode *vp = v->a_vp;
219 int mode = v->a_mode;
220 struct tmpfs_node *node;
223 node = VP_TO_TMPFS_NODE(vp);
226 /* The file is still active but all its names have been removed
227 * (e.g. by a "rmdir $(pwd)"). It cannot be opened any more as
228 * it is about to die. */
229 if (node->tn_links < 1)
233 /* If the file is marked append-only, deny write requests. */
234 if ((node->tn_flags & APPEND) &&
235 (mode & (FWRITE | O_APPEND)) == FWRITE) {
238 error = (vop_stdopen(v));
244 /* --------------------------------------------------------------------- */
247 tmpfs_close(struct vop_close_args *v)
249 struct vnode *vp = v->a_vp;
250 struct tmpfs_node *node;
253 node = VP_TO_TMPFS_NODE(vp);
255 if (node->tn_links > 0) {
257 * Update node times. No need to do it if the node has
258 * been deleted, because it will vanish after we return.
263 error = vop_stdclose(v);
268 /* --------------------------------------------------------------------- */
271 tmpfs_access(struct vop_access_args *v)
273 struct vnode *vp = v->a_vp;
275 struct tmpfs_node *node;
277 node = VP_TO_TMPFS_NODE(vp);
279 switch (vp->v_type) {
285 if ((v->a_mode & VWRITE) &&
286 (vp->v_mount->mnt_flag & MNT_RDONLY)) {
306 if ((v->a_mode & VWRITE) && (node->tn_flags & IMMUTABLE)) {
311 error = vop_helper_access(v, node->tn_uid, node->tn_gid,
317 /* --------------------------------------------------------------------- */
320 tmpfs_getattr(struct vop_getattr_args *v)
322 struct vnode *vp = v->a_vp;
323 struct vattr *vap = v->a_vap;
324 struct tmpfs_node *node;
326 node = VP_TO_TMPFS_NODE(vp);
330 TMPFS_NODE_LOCK_SH(node);
331 vap->va_type = vp->v_type;
332 vap->va_mode = node->tn_mode;
333 vap->va_nlink = node->tn_links;
334 vap->va_uid = node->tn_uid;
335 vap->va_gid = node->tn_gid;
336 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
337 vap->va_fileid = node->tn_id;
338 vap->va_size = node->tn_size;
339 vap->va_blocksize = PAGE_SIZE;
340 vap->va_atime.tv_sec = node->tn_atime;
341 vap->va_atime.tv_nsec = node->tn_atimensec;
342 vap->va_mtime.tv_sec = node->tn_mtime;
343 vap->va_mtime.tv_nsec = node->tn_mtimensec;
344 vap->va_ctime.tv_sec = node->tn_ctime;
345 vap->va_ctime.tv_nsec = node->tn_ctimensec;
346 vap->va_gen = node->tn_gen;
347 vap->va_flags = node->tn_flags;
348 if (vp->v_type == VBLK || vp->v_type == VCHR) {
349 vap->va_rmajor = umajor(node->tn_rdev);
350 vap->va_rminor = uminor(node->tn_rdev);
352 vap->va_bytes = round_page(node->tn_size);
354 TMPFS_NODE_UNLOCK(node);
359 /* --------------------------------------------------------------------- */
362 tmpfs_setattr(struct vop_setattr_args *v)
364 struct vnode *vp = v->a_vp;
365 struct vattr *vap = v->a_vap;
366 struct ucred *cred = v->a_cred;
367 struct tmpfs_node *node = VP_TO_TMPFS_NODE(vp);
371 TMPFS_NODE_LOCK(node);
372 if (error == 0 && (vap->va_flags != VNOVAL)) {
373 error = tmpfs_chflags(vp, vap->va_flags, cred);
374 kflags |= NOTE_ATTRIB;
377 if (error == 0 && (vap->va_size != VNOVAL)) {
378 if (vap->va_size > node->tn_size)
379 kflags |= NOTE_WRITE | NOTE_EXTEND;
381 kflags |= NOTE_WRITE;
382 error = tmpfs_chsize(vp, vap->va_size, cred);
385 if (error == 0 && (vap->va_uid != (uid_t)VNOVAL ||
386 vap->va_gid != (gid_t)VNOVAL)) {
387 error = tmpfs_chown(vp, vap->va_uid, vap->va_gid, cred);
388 kflags |= NOTE_ATTRIB;
391 if (error == 0 && (vap->va_mode != (mode_t)VNOVAL)) {
392 error = tmpfs_chmod(vp, vap->va_mode, cred);
393 kflags |= NOTE_ATTRIB;
396 if (error == 0 && ((vap->va_atime.tv_sec != VNOVAL &&
397 vap->va_atime.tv_nsec != VNOVAL) ||
398 (vap->va_mtime.tv_sec != VNOVAL &&
399 vap->va_mtime.tv_nsec != VNOVAL) )) {
400 error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime,
401 vap->va_vaflags, cred);
402 kflags |= NOTE_ATTRIB;
406 * Update the node times. We give preference to the error codes
407 * generated by this function rather than the ones that may arise
411 TMPFS_NODE_UNLOCK(node);
412 tmpfs_knote(vp, kflags);
417 /* --------------------------------------------------------------------- */
420 * fsync is usually a NOP, but we must take action when unmounting or
424 tmpfs_fsync(struct vop_fsync_args *v)
426 struct tmpfs_node *node;
427 struct vnode *vp = v->a_vp;
429 node = VP_TO_TMPFS_NODE(vp);
432 if (vp->v_type == VREG) {
433 if (vp->v_flag & VRECLAIMED) {
434 if (node->tn_links == 0)
435 tmpfs_truncate(vp, 0);
437 vfsync(v->a_vp, v->a_waitfor, 1, NULL, NULL);
443 /* --------------------------------------------------------------------- */
446 tmpfs_read (struct vop_read_args *ap)
449 struct vnode *vp = ap->a_vp;
450 struct uio *uio = ap->a_uio;
451 struct tmpfs_node *node;
461 if (uio->uio_offset < 0)
463 if (vp->v_type != VREG)
467 * Extract node, try to shortcut the operation through
468 * the VM page cache, allowing us to avoid buffer cache
471 node = VP_TO_TMPFS_NODE(vp);
472 resid = uio->uio_resid;
473 error = vop_helper_read_shortcut(ap);
476 if (uio->uio_resid == 0) {
483 * Fall-through to our normal read code.
485 while (uio->uio_resid > 0 && uio->uio_offset < node->tn_size) {
487 * Use buffer cache I/O (via tmpfs_strategy)
489 offset = (size_t)uio->uio_offset & TMPFS_BLKMASK64;
490 base_offset = (off_t)uio->uio_offset - offset;
491 bp = getcacheblk(vp, base_offset, TMPFS_BLKSIZE, 0);
493 error = bread(vp, base_offset, TMPFS_BLKSIZE, &bp);
496 kprintf("tmpfs_read bread error %d\n", error);
501 * tmpfs pretty much fiddles directly with the VM
502 * system, don't let it exhaust it or we won't play
503 * nice with other processes.
505 * Only do this if the VOP is coming from a normal
506 * read/write. The VM system handles the case for
509 if (uio->uio_segflg != UIO_NOCOPY)
512 bp->b_flags |= B_CLUSTEROK;
515 * Figure out how many bytes we can actually copy this loop.
517 len = TMPFS_BLKSIZE - offset;
518 if (len > uio->uio_resid)
519 len = uio->uio_resid;
520 if (len > node->tn_size - uio->uio_offset)
521 len = (size_t)(node->tn_size - uio->uio_offset);
523 error = uiomovebp(bp, (char *)bp->b_data + offset, len, uio);
526 kprintf("tmpfs_read uiomove error %d\n", error);
532 TMPFS_NODE_LOCK(node);
533 node->tn_status |= TMPFS_NODE_ACCESSED;
534 TMPFS_NODE_UNLOCK(node);
539 tmpfs_write (struct vop_write_args *ap)
542 struct vnode *vp = ap->a_vp;
543 struct uio *uio = ap->a_uio;
544 struct thread *td = uio->uio_td;
545 struct tmpfs_node *node;
558 if (uio->uio_resid == 0) {
562 node = VP_TO_TMPFS_NODE(vp);
564 if (vp->v_type != VREG)
566 seqcount = ap->a_ioflag >> 16;
568 oldsize = node->tn_size;
569 if (ap->a_ioflag & IO_APPEND)
570 uio->uio_offset = node->tn_size;
573 * Check for illegal write offsets.
575 if (uio->uio_offset + uio->uio_resid >
576 VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize) {
581 * NOTE: Ignore if UIO does not come from a user thread (e.g. VN).
583 if (vp->v_type == VREG && td != NULL && td->td_lwp != NULL) {
584 error = kern_getrlimit(RLIMIT_FSIZE, &limit);
588 if (uio->uio_offset + uio->uio_resid > limit.rlim_cur) {
589 ksignal(td->td_proc, SIGXFSZ);
596 * Extend the file's size if necessary
598 extended = ((uio->uio_offset + uio->uio_resid) > node->tn_size);
600 while (uio->uio_resid > 0) {
602 * Don't completely blow out running buffer I/O
603 * when being hit from the pageout daemon.
605 if (uio->uio_segflg == UIO_NOCOPY &&
606 (ap->a_ioflag & IO_RECURSE) == 0) {
607 bwillwrite(TMPFS_BLKSIZE);
611 * Use buffer cache I/O (via tmpfs_strategy)
613 offset = (size_t)uio->uio_offset & TMPFS_BLKMASK64;
614 base_offset = (off_t)uio->uio_offset - offset;
615 len = TMPFS_BLKSIZE - offset;
616 if (len > uio->uio_resid)
617 len = uio->uio_resid;
619 if ((uio->uio_offset + len) > node->tn_size) {
620 trivial = (uio->uio_offset <= node->tn_size);
621 error = tmpfs_reg_resize(vp, uio->uio_offset + len, trivial);
627 * Read to fill in any gaps. Theoretically we could
628 * optimize this if the write covers the entire buffer
629 * and is not a UIO_NOCOPY write, however this can lead
630 * to a security violation exposing random kernel memory
631 * (whatever junk was in the backing VM pages before).
633 * So just use bread() to do the right thing.
635 error = bread(vp, base_offset, TMPFS_BLKSIZE, &bp);
636 error = uiomovebp(bp, (char *)bp->b_data + offset, len, uio);
638 kprintf("tmpfs_write uiomove error %d\n", error);
643 if (uio->uio_offset > node->tn_size) {
644 node->tn_size = uio->uio_offset;
645 kflags |= NOTE_EXTEND;
647 kflags |= NOTE_WRITE;
650 * Always try to flush the page in the UIO_NOCOPY case. This
651 * can come from the pageout daemon or during vnode eviction.
652 * It is not necessarily going to be marked IO_ASYNC/IO_SYNC.
654 * For the normal case we buwrite(), dirtying the underlying
655 * VM pages instead of dirtying the buffer and releasing the
656 * buffer as a clean buffer. This allows tmpfs to use
657 * essentially all available memory to cache file data.
658 * If we used bdwrite() the buffer cache would wind up
659 * flushing the data to swap too quickly.
661 * But because tmpfs can seriously load the VM system we
662 * fall-back to using bdwrite() when free memory starts
663 * to get low. This shifts the load away from the VM system
664 * and makes tmpfs act more like a normal filesystem with
665 * regards to disk activity.
667 * tmpfs pretty much fiddles directly with the VM
668 * system, don't let it exhaust it or we won't play
669 * nice with other processes. Only do this if the
670 * VOP is coming from a normal read/write. The VM system
671 * handles the case for UIO_NOCOPY.
673 bp->b_flags |= B_CLUSTEROK;
674 if (uio->uio_segflg == UIO_NOCOPY) {
676 * Flush from the pageout daemon, deal with
677 * potentially very heavy tmpfs write activity
678 * causing long stalls in the pageout daemon
679 * before pages get to free/cache.
681 * (a) Under severe pressure setting B_DIRECT will
682 * cause a buffer release to try to free the
685 * (b) Under modest memory pressure the B_RELBUF
686 * alone is sufficient to get the pages moved
687 * to the cache. We could also force this by
688 * setting B_NOTMETA but that might have other
689 * unintended side-effects (e.g. setting
690 * PG_NOTMETA on the VM page).
692 * Hopefully this will unblock the VM system more
693 * quickly under extreme tmpfs write load.
695 if (vm_page_count_min(vm_page_free_hysteresis))
696 bp->b_flags |= B_DIRECT;
697 bp->b_flags |= B_AGE | B_RELBUF;
698 bp->b_act_count = 0; /* buffer->deactivate pgs */
700 } else if (vm_page_count_target()) {
702 * Normal (userland) write but we are low on memory,
703 * run the buffer the buffer cache.
705 bp->b_act_count = 0; /* buffer->deactivate pgs */
709 * Otherwise run the buffer directly through to the
713 /*vm_wait_nominal();*/
717 kprintf("tmpfs_write bwrite error %d\n", bp->b_error);
724 (void)tmpfs_reg_resize(vp, oldsize, trivial);
725 kflags &= ~NOTE_EXTEND;
731 * Currently we don't set the mtime on files modified via mmap()
732 * because we can't tell the difference between those modifications
733 * and an attempt by the pageout daemon to flush tmpfs pages to
736 * This is because in order to defer flushes as long as possible
737 * buwrite() works by marking the underlying VM pages dirty in
738 * order to be able to dispose of the buffer cache buffer without
741 TMPFS_NODE_LOCK(node);
742 if (uio->uio_segflg != UIO_NOCOPY)
743 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED;
745 node->tn_status |= TMPFS_NODE_CHANGED;
747 if (node->tn_mode & (S_ISUID | S_ISGID)) {
748 if (priv_check_cred(ap->a_cred, PRIV_VFS_RETAINSUGID, 0))
749 node->tn_mode &= ~(S_ISUID | S_ISGID);
751 TMPFS_NODE_UNLOCK(node);
753 tmpfs_knote(vp, kflags);
759 tmpfs_advlock (struct vop_advlock_args *ap)
761 struct tmpfs_node *node;
762 struct vnode *vp = ap->a_vp;
765 node = VP_TO_TMPFS_NODE(vp);
766 error = (lf_advlock(ap, &node->tn_advlock, node->tn_size));
772 * The strategy function is typically only called when memory pressure
773 * forces the system to attempt to pageout pages. It can also be called
774 * by [n]vtruncbuf() when a truncation cuts a page in half. Normal write
778 tmpfs_strategy(struct vop_strategy_args *ap)
780 struct bio *bio = ap->a_bio;
782 struct buf *bp = bio->bio_buf;
783 struct vnode *vp = ap->a_vp;
784 struct tmpfs_node *node;
789 if (vp->v_type != VREG) {
790 bp->b_resid = bp->b_bcount;
791 bp->b_flags |= B_ERROR | B_INVAL;
792 bp->b_error = EINVAL;
797 node = VP_TO_TMPFS_NODE(vp);
799 uobj = node->tn_reg.tn_aobj;
802 * Don't bother flushing to swap if there is no swap, just
803 * ensure that the pages are marked as needing a commit (still).
805 if (bp->b_cmd == BUF_CMD_WRITE && vm_swap_size == 0) {
806 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
807 m = bp->b_xio.xio_pages[i];
808 vm_page_need_commit(m);
814 nbio = push_bio(bio);
815 nbio->bio_done = tmpfs_strategy_done;
816 nbio->bio_offset = bio->bio_offset;
817 swap_pager_strategy(uobj, nbio);
823 * If we were unable to commit the pages to swap make sure they are marked
824 * as needing a commit (again). If we were, clear the flag to allow the
828 tmpfs_strategy_done(struct bio *bio)
836 if (bp->b_flags & B_ERROR) {
837 bp->b_flags &= ~B_ERROR;
840 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
841 m = bp->b_xio.xio_pages[i];
842 vm_page_need_commit(m);
845 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
846 m = bp->b_xio.xio_pages[i];
847 vm_page_clear_commit(m);
855 tmpfs_bmap(struct vop_bmap_args *ap)
857 if (ap->a_doffsetp != NULL)
858 *ap->a_doffsetp = ap->a_loffset;
859 if (ap->a_runp != NULL)
861 if (ap->a_runb != NULL)
867 /* --------------------------------------------------------------------- */
870 tmpfs_nremove(struct vop_nremove_args *v)
872 struct vnode *dvp = v->a_dvp;
873 struct namecache *ncp = v->a_nch->ncp;
876 struct tmpfs_dirent *de;
877 struct tmpfs_mount *tmp;
878 struct tmpfs_node *dnode;
879 struct tmpfs_node *node;
885 * We have to acquire the vp from v->a_nch because we will likely
886 * unresolve the namecache entry, and a vrele/vput is needed to
887 * trigger the tmpfs_inactive/tmpfs_reclaim sequence.
889 * We have to use vget to clear any inactive state on the vnode,
890 * otherwise the vnode may remain inactive and thus tmpfs_inactive
891 * will not get called when we release it.
893 error = cache_vget(v->a_nch, v->a_cred, LK_SHARED, &vp);
894 KKASSERT(vp->v_mount == dvp->v_mount);
895 KKASSERT(error == 0);
898 if (vp->v_type == VDIR) {
903 dnode = VP_TO_TMPFS_DIR(dvp);
904 node = VP_TO_TMPFS_NODE(vp);
905 tmp = VFS_TO_TMPFS(vp->v_mount);
907 TMPFS_NODE_LOCK(dnode);
908 de = tmpfs_dir_lookup(dnode, node, ncp);
914 /* Files marked as immutable or append-only cannot be deleted. */
915 if ((node->tn_flags & (IMMUTABLE | APPEND | NOUNLINK)) ||
916 (dnode->tn_flags & APPEND)) {
921 /* Remove the entry from the directory; as it is a file, we do not
922 * have to change the number of hard links of the directory. */
923 tmpfs_dir_detach(dnode, de);
925 /* Free the directory entry we just deleted. Note that the node
926 * referred by it will not be removed until the vnode is really
928 tmpfs_free_dirent(tmp, de);
930 if (node->tn_links > 0) {
931 TMPFS_NODE_LOCK(node);
932 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
934 TMPFS_NODE_UNLOCK(node);
937 cache_unlink(v->a_nch);
938 tmpfs_knote(vp, NOTE_DELETE);
942 TMPFS_NODE_UNLOCK(dnode);
944 tmpfs_knote(dvp, NOTE_WRITE);
951 /* --------------------------------------------------------------------- */
954 tmpfs_nlink(struct vop_nlink_args *v)
956 struct vnode *dvp = v->a_dvp;
957 struct vnode *vp = v->a_vp;
958 struct namecache *ncp = v->a_nch->ncp;
959 struct tmpfs_dirent *de;
960 struct tmpfs_node *node;
961 struct tmpfs_node *dnode;
965 if (dvp->v_mount != vp->v_mount)
969 KKASSERT(dvp != vp); /* XXX When can this be false? */
971 node = VP_TO_TMPFS_NODE(vp);
972 dnode = VP_TO_TMPFS_NODE(dvp);
973 TMPFS_NODE_LOCK(dnode);
975 /* XXX: Why aren't the following two tests done by the caller? */
977 /* Hard links of directories are forbidden. */
978 if (vp->v_type == VDIR) {
983 /* Cannot create cross-device links. */
984 if (dvp->v_mount != vp->v_mount) {
989 /* Ensure that we do not overflow the maximum number of links imposed
991 KKASSERT(node->tn_links <= LINK_MAX);
992 if (node->tn_links >= LINK_MAX) {
997 /* We cannot create links of files marked immutable or append-only. */
998 if (node->tn_flags & (IMMUTABLE | APPEND)) {
1003 /* Allocate a new directory entry to represent the node. */
1004 error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount), node,
1005 ncp->nc_name, ncp->nc_nlen, &de);
1009 /* Insert the new directory entry into the appropriate directory. */
1010 tmpfs_dir_attach(dnode, de);
1012 /* vp link count has changed, so update node times. */
1014 TMPFS_NODE_LOCK(node);
1015 node->tn_status |= TMPFS_NODE_CHANGED;
1016 TMPFS_NODE_UNLOCK(node);
1019 tmpfs_knote(vp, NOTE_LINK);
1020 cache_setunresolved(v->a_nch);
1021 cache_setvp(v->a_nch, vp);
1025 TMPFS_NODE_UNLOCK(dnode);
1027 tmpfs_knote(dvp, NOTE_WRITE);
1031 /* --------------------------------------------------------------------- */
1034 tmpfs_nrename(struct vop_nrename_args *v)
1036 struct vnode *fdvp = v->a_fdvp;
1037 struct namecache *fncp = v->a_fnch->ncp;
1038 struct vnode *fvp = fncp->nc_vp;
1039 struct vnode *tdvp = v->a_tdvp;
1040 struct namecache *tncp = v->a_tnch->ncp;
1042 struct tmpfs_dirent *de, *tde;
1043 struct tmpfs_mount *tmp;
1044 struct tmpfs_node *fdnode;
1045 struct tmpfs_node *fnode;
1046 struct tmpfs_node *tnode;
1047 struct tmpfs_node *tdnode;
1054 KKASSERT(fdvp->v_mount == fvp->v_mount);
1057 * Because tvp can get overwritten we have to vget it instead of
1058 * just vref or use it, otherwise it's VINACTIVE flag may not get
1059 * cleared and the node won't get destroyed.
1061 error = cache_vget(v->a_tnch, v->a_cred, LK_SHARED, &tvp);
1063 tnode = VP_TO_TMPFS_NODE(tvp);
1069 /* Disallow cross-device renames.
1070 * XXX Why isn't this done by the caller? */
1071 if (fvp->v_mount != tdvp->v_mount ||
1072 (tvp != NULL && fvp->v_mount != tvp->v_mount)) {
1077 tmp = VFS_TO_TMPFS(tdvp->v_mount);
1078 tdnode = VP_TO_TMPFS_DIR(tdvp);
1080 /* If source and target are the same file, there is nothing to do. */
1086 fdnode = VP_TO_TMPFS_DIR(fdvp);
1087 fnode = VP_TO_TMPFS_NODE(fvp);
1088 TMPFS_NODE_LOCK(fdnode);
1089 de = tmpfs_dir_lookup(fdnode, fnode, fncp);
1090 TMPFS_NODE_UNLOCK(fdnode); /* XXX depend on namecache lock */
1092 /* Avoid manipulating '.' and '..' entries. */
1097 KKASSERT(de->td_node == fnode);
1100 * If replacing an entry in the target directory and that entry
1101 * is a directory, it must be empty.
1103 * Kern_rename gurantees the destination to be a directory
1104 * if the source is one (it does?).
1107 KKASSERT(tnode != NULL);
1109 if ((tnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1110 (tdnode->tn_flags & (APPEND | IMMUTABLE))) {
1115 if (fnode->tn_type == VDIR && tnode->tn_type == VDIR) {
1116 if (tnode->tn_size > 0) {
1120 } else if (fnode->tn_type == VDIR && tnode->tn_type != VDIR) {
1123 } else if (fnode->tn_type != VDIR && tnode->tn_type == VDIR) {
1127 KKASSERT(fnode->tn_type != VDIR &&
1128 tnode->tn_type != VDIR);
1132 if ((fnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1133 (fdnode->tn_flags & (APPEND | IMMUTABLE))) {
1139 * Ensure that we have enough memory to hold the new name, if it
1140 * has to be changed.
1142 if (fncp->nc_nlen != tncp->nc_nlen ||
1143 bcmp(fncp->nc_name, tncp->nc_name, fncp->nc_nlen) != 0) {
1144 newname = kmalloc(tncp->nc_nlen + 1, tmp->tm_name_zone,
1145 M_WAITOK | M_NULLOK);
1146 if (newname == NULL) {
1150 bcopy(tncp->nc_name, newname, tncp->nc_nlen);
1151 newname[tncp->nc_nlen] = '\0';
1157 * Unlink entry from source directory. Note that the kernel has
1158 * already checked for illegal recursion cases (renaming a directory
1159 * into a subdirectory of itself).
1161 if (fdnode != tdnode) {
1162 tmpfs_dir_detach(fdnode, de);
1164 /* XXX depend on namecache lock */
1165 TMPFS_NODE_LOCK(fdnode);
1166 KKASSERT(de == tmpfs_dir_lookup(fdnode, fnode, fncp));
1167 RB_REMOVE(tmpfs_dirtree, &fdnode->tn_dir.tn_dirtree, de);
1168 RB_REMOVE(tmpfs_dirtree_cookie,
1169 &fdnode->tn_dir.tn_cookietree, de);
1170 TMPFS_NODE_UNLOCK(fdnode);
1174 * Handle any name change. Swap with newname, we will
1175 * deallocate it at the end.
1177 if (newname != NULL) {
1179 TMPFS_NODE_LOCK(fnode);
1180 fnode->tn_status |= TMPFS_NODE_CHANGED;
1181 TMPFS_NODE_UNLOCK(fnode);
1183 oldname = de->td_name;
1184 de->td_name = newname;
1185 de->td_namelen = (uint16_t)tncp->nc_nlen;
1190 * If we are overwriting an entry, we have to remove the old one
1191 * from the target directory.
1194 /* Remove the old entry from the target directory. */
1195 TMPFS_NODE_LOCK(tdnode);
1196 tde = tmpfs_dir_lookup(tdnode, tnode, tncp);
1197 tmpfs_dir_detach(tdnode, tde);
1198 TMPFS_NODE_UNLOCK(tdnode);
1199 tmpfs_knote(tdnode->tn_vnode, NOTE_DELETE);
1202 * Free the directory entry we just deleted. Note that the
1203 * node referred by it will not be removed until the vnode is
1206 tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), tde);
1207 /*cache_inval_vp(tvp, CINV_DESTROY);*/
1211 * Link entry to target directory. If the entry
1212 * represents a directory move the parent linkage
1215 if (fdnode != tdnode) {
1216 if (de->td_node->tn_type == VDIR) {
1217 TMPFS_VALIDATE_DIR(fnode);
1219 tmpfs_dir_attach(tdnode, de);
1221 TMPFS_NODE_LOCK(tdnode);
1222 tdnode->tn_status |= TMPFS_NODE_MODIFIED;
1223 RB_INSERT(tmpfs_dirtree, &tdnode->tn_dir.tn_dirtree, de);
1224 RB_INSERT(tmpfs_dirtree_cookie,
1225 &tdnode->tn_dir.tn_cookietree, de);
1226 TMPFS_NODE_UNLOCK(tdnode);
1233 kfree(newname, tmp->tm_name_zone);
1236 cache_rename(v->a_fnch, v->a_tnch);
1237 tmpfs_knote(v->a_fdvp, NOTE_WRITE);
1238 tmpfs_knote(v->a_tdvp, NOTE_WRITE);
1239 if (fnode->tn_vnode)
1240 tmpfs_knote(fnode->tn_vnode, NOTE_RENAME);
1251 /* --------------------------------------------------------------------- */
1254 tmpfs_nmkdir(struct vop_nmkdir_args *v)
1256 struct vnode *dvp = v->a_dvp;
1257 struct vnode **vpp = v->a_vpp;
1258 struct namecache *ncp = v->a_nch->ncp;
1259 struct vattr *vap = v->a_vap;
1260 struct ucred *cred = v->a_cred;
1266 KKASSERT(vap->va_type == VDIR);
1268 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
1270 cache_setunresolved(v->a_nch);
1271 cache_setvp(v->a_nch, *vpp);
1272 tmpfs_knote(dvp, NOTE_WRITE | NOTE_LINK);
1277 /* --------------------------------------------------------------------- */
1280 tmpfs_nrmdir(struct vop_nrmdir_args *v)
1282 struct vnode *dvp = v->a_dvp;
1283 struct namecache *ncp = v->a_nch->ncp;
1285 struct tmpfs_dirent *de;
1286 struct tmpfs_mount *tmp;
1287 struct tmpfs_node *dnode;
1288 struct tmpfs_node *node;
1295 * We have to acquire the vp from v->a_nch because we will likely
1296 * unresolve the namecache entry, and a vrele/vput is needed to
1297 * trigger the tmpfs_inactive/tmpfs_reclaim sequence.
1299 * We have to use vget to clear any inactive state on the vnode,
1300 * otherwise the vnode may remain inactive and thus tmpfs_inactive
1301 * will not get called when we release it.
1303 error = cache_vget(v->a_nch, v->a_cred, LK_SHARED, &vp);
1304 KKASSERT(error == 0);
1308 * Prevalidate so we don't hit an assertion later
1310 if (vp->v_type != VDIR) {
1315 tmp = VFS_TO_TMPFS(dvp->v_mount);
1316 dnode = VP_TO_TMPFS_DIR(dvp);
1317 node = VP_TO_TMPFS_DIR(vp);
1320 * Directories with more than two entries ('.' and '..') cannot
1323 if (node->tn_size > 0) {
1328 if ((dnode->tn_flags & APPEND)
1329 || (node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
1335 * This invariant holds only if we are not trying to
1336 * remove "..". We checked for that above so this is safe now.
1338 KKASSERT(node->tn_dir.tn_parent == dnode);
1341 * Get the directory entry associated with node (vp). This
1342 * was filled by tmpfs_lookup while looking up the entry.
1344 TMPFS_NODE_LOCK(dnode);
1345 de = tmpfs_dir_lookup(dnode, node, ncp);
1346 KKASSERT(TMPFS_DIRENT_MATCHES(de, ncp->nc_name, ncp->nc_nlen));
1348 /* Check flags to see if we are allowed to remove the directory. */
1349 if ((dnode->tn_flags & APPEND) ||
1350 node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) {
1352 TMPFS_NODE_UNLOCK(dnode);
1356 /* Detach the directory entry from the directory (dnode). */
1357 tmpfs_dir_detach(dnode, de);
1358 TMPFS_NODE_UNLOCK(dnode);
1360 /* No vnode should be allocated for this entry from this point */
1361 TMPFS_NODE_LOCK(dnode);
1362 TMPFS_ASSERT_ELOCKED(dnode);
1363 TMPFS_NODE_LOCK(node);
1364 TMPFS_ASSERT_ELOCKED(node);
1367 * Must set parent linkage to NULL (tested by ncreate to disallow
1368 * the creation of new files/dirs in a deleted directory)
1370 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED |
1371 TMPFS_NODE_MODIFIED;
1373 dnode->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED |
1374 TMPFS_NODE_MODIFIED;
1376 TMPFS_NODE_UNLOCK(node);
1377 TMPFS_NODE_UNLOCK(dnode);
1379 /* Free the directory entry we just deleted. Note that the node
1380 * referred by it will not be removed until the vnode is really
1382 tmpfs_free_dirent(tmp, de);
1384 /* Release the deleted vnode (will destroy the node, notify
1385 * interested parties and clean it from the cache). */
1387 TMPFS_NODE_LOCK(dnode);
1388 dnode->tn_status |= TMPFS_NODE_CHANGED;
1389 TMPFS_NODE_UNLOCK(dnode);
1392 cache_unlink(v->a_nch);
1393 tmpfs_knote(dvp, NOTE_WRITE | NOTE_LINK);
1402 /* --------------------------------------------------------------------- */
1405 tmpfs_nsymlink(struct vop_nsymlink_args *v)
1407 struct vnode *dvp = v->a_dvp;
1408 struct vnode **vpp = v->a_vpp;
1409 struct namecache *ncp = v->a_nch->ncp;
1410 struct vattr *vap = v->a_vap;
1411 struct ucred *cred = v->a_cred;
1412 char *target = v->a_target;
1415 vap->va_type = VLNK;
1416 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, target);
1418 tmpfs_knote(*vpp, NOTE_WRITE);
1419 cache_setunresolved(v->a_nch);
1420 cache_setvp(v->a_nch, *vpp);
1425 /* --------------------------------------------------------------------- */
1428 tmpfs_readdir(struct vop_readdir_args *v)
1430 struct vnode *vp = v->a_vp;
1431 struct uio *uio = v->a_uio;
1432 int *eofflag = v->a_eofflag;
1433 off_t **cookies = v->a_cookies;
1434 int *ncookies = v->a_ncookies;
1435 struct tmpfs_mount *tmp;
1439 struct tmpfs_node *node;
1441 /* This operation only makes sense on directory nodes. */
1442 if (vp->v_type != VDIR) {
1446 tmp = VFS_TO_TMPFS(vp->v_mount);
1447 node = VP_TO_TMPFS_DIR(vp);
1448 startoff = uio->uio_offset;
1450 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) {
1451 error = tmpfs_dir_getdotdent(node, uio);
1453 TMPFS_NODE_LOCK_SH(node);
1459 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT) {
1460 /* may lock parent, cannot hold node lock */
1461 error = tmpfs_dir_getdotdotdent(tmp, node, uio);
1463 TMPFS_NODE_LOCK_SH(node);
1469 TMPFS_NODE_LOCK_SH(node);
1470 error = tmpfs_dir_getdents(node, uio, &cnt);
1473 KKASSERT(error >= -1);
1478 if (eofflag != NULL)
1480 (error == 0 && uio->uio_offset == TMPFS_DIRCOOKIE_EOF);
1482 /* Update NFS-related variables. */
1483 if (error == 0 && cookies != NULL && ncookies != NULL) {
1485 off_t off = startoff;
1486 struct tmpfs_dirent *de = NULL;
1489 *cookies = kmalloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK);
1491 for (i = 0; i < cnt; i++) {
1492 KKASSERT(off != TMPFS_DIRCOOKIE_EOF);
1493 if (off == TMPFS_DIRCOOKIE_DOT) {
1494 off = TMPFS_DIRCOOKIE_DOTDOT;
1496 if (off == TMPFS_DIRCOOKIE_DOTDOT) {
1497 de = RB_MIN(tmpfs_dirtree_cookie,
1498 &node->tn_dir.tn_cookietree);
1499 } else if (de != NULL) {
1500 de = RB_NEXT(tmpfs_dirtree_cookie,
1501 &node->tn_dir.tn_cookietree, de);
1503 de = tmpfs_dir_lookupbycookie(node,
1505 KKASSERT(de != NULL);
1506 de = RB_NEXT(tmpfs_dirtree_cookie,
1507 &node->tn_dir.tn_cookietree, de);
1510 off = TMPFS_DIRCOOKIE_EOF;
1512 off = tmpfs_dircookie(de);
1514 (*cookies)[i] = off;
1516 KKASSERT(uio->uio_offset == off);
1518 TMPFS_NODE_UNLOCK(node);
1520 TMPFS_NODE_LOCK(node);
1521 node->tn_status |= TMPFS_NODE_ACCESSED;
1522 TMPFS_NODE_UNLOCK(node);
1526 /* --------------------------------------------------------------------- */
1529 tmpfs_readlink(struct vop_readlink_args *v)
1531 struct vnode *vp = v->a_vp;
1532 struct uio *uio = v->a_uio;
1534 struct tmpfs_node *node;
1536 KKASSERT(uio->uio_offset == 0);
1537 KKASSERT(vp->v_type == VLNK);
1539 node = VP_TO_TMPFS_NODE(vp);
1540 TMPFS_NODE_LOCK_SH(node);
1541 error = uiomove(node->tn_link,
1542 MIN(node->tn_size, uio->uio_resid), uio);
1543 TMPFS_NODE_UNLOCK(node);
1544 TMPFS_NODE_LOCK(node);
1545 node->tn_status |= TMPFS_NODE_ACCESSED;
1546 TMPFS_NODE_UNLOCK(node);
1550 /* --------------------------------------------------------------------- */
1553 tmpfs_inactive(struct vop_inactive_args *v)
1555 struct vnode *vp = v->a_vp;
1556 struct tmpfs_node *node;
1560 lwkt_gettoken(&mp->mnt_token);
1561 node = VP_TO_TMPFS_NODE(vp);
1568 lwkt_reltoken(&mp->mnt_token);
1573 * Get rid of unreferenced deleted vnodes sooner rather than
1574 * later so the data memory can be recovered immediately.
1576 * We must truncate the vnode to prevent the normal reclamation
1577 * path from flushing the data for the removed file to disk.
1579 TMPFS_NODE_LOCK(node);
1580 if ((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0 &&
1581 node->tn_links == 0)
1583 node->tn_vpstate = TMPFS_VNODE_DOOMED;
1584 TMPFS_NODE_UNLOCK(node);
1585 if (node->tn_type == VREG)
1586 tmpfs_truncate(vp, 0);
1589 TMPFS_NODE_UNLOCK(node);
1591 lwkt_reltoken(&mp->mnt_token);
1596 /* --------------------------------------------------------------------- */
1599 tmpfs_reclaim(struct vop_reclaim_args *v)
1601 struct vnode *vp = v->a_vp;
1602 struct tmpfs_mount *tmp;
1603 struct tmpfs_node *node;
1607 lwkt_gettoken(&mp->mnt_token);
1609 node = VP_TO_TMPFS_NODE(vp);
1610 tmp = VFS_TO_TMPFS(vp->v_mount);
1611 KKASSERT(mp == tmp->tm_mount);
1616 * If the node referenced by this vnode was deleted by the
1617 * user, we must free its associated data structures now that
1618 * the vnode is being reclaimed.
1620 * Directories have an extra link ref.
1622 TMPFS_NODE_LOCK(node);
1623 if ((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0 &&
1624 node->tn_links == 0) {
1625 node->tn_vpstate = TMPFS_VNODE_DOOMED;
1626 tmpfs_free_node(tmp, node);
1629 TMPFS_NODE_UNLOCK(node);
1631 lwkt_reltoken(&mp->mnt_token);
1633 KKASSERT(vp->v_data == NULL);
1637 /* --------------------------------------------------------------------- */
1640 tmpfs_mountctl(struct vop_mountctl_args *ap)
1642 struct tmpfs_mount *tmp;
1646 mp = ap->a_head.a_ops->head.vv_mount;
1647 lwkt_gettoken(&mp->mnt_token);
1650 case (MOUNTCTL_SET_EXPORT):
1651 tmp = (struct tmpfs_mount *) mp->mnt_data;
1653 if (ap->a_ctllen != sizeof(struct export_args))
1656 rc = vfs_export(mp, &tmp->tm_export,
1657 (const struct export_args *) ap->a_ctl);
1660 rc = vop_stdmountctl(ap);
1664 lwkt_reltoken(&mp->mnt_token);
1668 /* --------------------------------------------------------------------- */
1671 tmpfs_print(struct vop_print_args *v)
1673 struct vnode *vp = v->a_vp;
1675 struct tmpfs_node *node;
1677 node = VP_TO_TMPFS_NODE(vp);
1679 kprintf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n",
1680 node, node->tn_flags, node->tn_links);
1681 kprintf("\tmode 0%o, owner %d, group %d, size %ju, status 0x%x\n",
1682 node->tn_mode, node->tn_uid, node->tn_gid,
1683 (uintmax_t)node->tn_size, node->tn_status);
1685 if (vp->v_type == VFIFO)
1693 /* --------------------------------------------------------------------- */
1696 tmpfs_pathconf(struct vop_pathconf_args *v)
1698 int name = v->a_name;
1699 register_t *retval = v->a_retval;
1722 case _PC_CHOWN_RESTRICTED:
1734 case _PC_FILESIZEBITS:
1735 *retval = 0; /* XXX Don't know which value should I return. */
1745 /************************************************************************
1747 ************************************************************************/
1749 static void filt_tmpfsdetach(struct knote *kn);
1750 static int filt_tmpfsread(struct knote *kn, long hint);
1751 static int filt_tmpfswrite(struct knote *kn, long hint);
1752 static int filt_tmpfsvnode(struct knote *kn, long hint);
1754 static struct filterops tmpfsread_filtops =
1755 { FILTEROP_ISFD | FILTEROP_MPSAFE,
1756 NULL, filt_tmpfsdetach, filt_tmpfsread };
1757 static struct filterops tmpfswrite_filtops =
1758 { FILTEROP_ISFD | FILTEROP_MPSAFE,
1759 NULL, filt_tmpfsdetach, filt_tmpfswrite };
1760 static struct filterops tmpfsvnode_filtops =
1761 { FILTEROP_ISFD | FILTEROP_MPSAFE,
1762 NULL, filt_tmpfsdetach, filt_tmpfsvnode };
1765 tmpfs_kqfilter (struct vop_kqfilter_args *ap)
1767 struct vnode *vp = ap->a_vp;
1768 struct knote *kn = ap->a_kn;
1770 switch (kn->kn_filter) {
1772 kn->kn_fop = &tmpfsread_filtops;
1775 kn->kn_fop = &tmpfswrite_filtops;
1778 kn->kn_fop = &tmpfsvnode_filtops;
1781 return (EOPNOTSUPP);
1784 kn->kn_hook = (caddr_t)vp;
1786 knote_insert(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn);
1792 filt_tmpfsdetach(struct knote *kn)
1794 struct vnode *vp = (void *)kn->kn_hook;
1796 knote_remove(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn);
1800 filt_tmpfsread(struct knote *kn, long hint)
1802 struct vnode *vp = (void *)kn->kn_hook;
1803 struct tmpfs_node *node = VP_TO_TMPFS_NODE(vp);
1806 if (hint == NOTE_REVOKE) {
1807 kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT);
1812 * Interlock against MP races when performing this function.
1814 TMPFS_NODE_LOCK_SH(node);
1815 off = node->tn_size - kn->kn_fp->f_offset;
1816 kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX;
1817 if (kn->kn_sfflags & NOTE_OLDAPI) {
1818 TMPFS_NODE_UNLOCK(node);
1821 if (kn->kn_data == 0) {
1822 kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX;
1824 TMPFS_NODE_UNLOCK(node);
1825 return (kn->kn_data != 0);
1829 filt_tmpfswrite(struct knote *kn, long hint)
1831 if (hint == NOTE_REVOKE)
1832 kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT);
1838 filt_tmpfsvnode(struct knote *kn, long hint)
1840 if (kn->kn_sfflags & hint)
1841 kn->kn_fflags |= hint;
1842 if (hint == NOTE_REVOKE) {
1843 kn->kn_flags |= (EV_EOF | EV_NODATA);
1846 return (kn->kn_fflags != 0);
1850 /* --------------------------------------------------------------------- */
1853 * vnode operations vector used for files stored in a tmpfs file system.
1855 struct vop_ops tmpfs_vnode_vops = {
1856 .vop_default = vop_defaultop,
1857 .vop_getpages = vop_stdgetpages,
1858 .vop_putpages = vop_stdputpages,
1859 .vop_ncreate = tmpfs_ncreate,
1860 .vop_nresolve = tmpfs_nresolve,
1861 .vop_nlookupdotdot = tmpfs_nlookupdotdot,
1862 .vop_nmknod = tmpfs_nmknod,
1863 .vop_open = tmpfs_open,
1864 .vop_close = tmpfs_close,
1865 .vop_access = tmpfs_access,
1866 .vop_getattr = tmpfs_getattr,
1867 .vop_setattr = tmpfs_setattr,
1868 .vop_read = tmpfs_read,
1869 .vop_write = tmpfs_write,
1870 .vop_fsync = tmpfs_fsync,
1871 .vop_mountctl = tmpfs_mountctl,
1872 .vop_nremove = tmpfs_nremove,
1873 .vop_nlink = tmpfs_nlink,
1874 .vop_nrename = tmpfs_nrename,
1875 .vop_nmkdir = tmpfs_nmkdir,
1876 .vop_nrmdir = tmpfs_nrmdir,
1877 .vop_nsymlink = tmpfs_nsymlink,
1878 .vop_readdir = tmpfs_readdir,
1879 .vop_readlink = tmpfs_readlink,
1880 .vop_inactive = tmpfs_inactive,
1881 .vop_reclaim = tmpfs_reclaim,
1882 .vop_print = tmpfs_print,
1883 .vop_pathconf = tmpfs_pathconf,
1884 .vop_bmap = tmpfs_bmap,
1885 .vop_strategy = tmpfs_strategy,
1886 .vop_advlock = tmpfs_advlock,
1887 .vop_kqfilter = tmpfs_kqfilter