3 #include <sys/kernel.h>
15 * Last reference to a vnode is going away but it is still cached.
18 hammer2_inactive(struct vop_inactive_args *ap)
21 struct hammer2_inode *ip;
22 struct hammer2_mount *hmp;
24 kprintf("hammer2_inactive\n");
34 * Reclaim a vnode so that it can be reused; after the inode is
35 * disassociated, the filesystem must manage it alone.
38 hammer2_reclaim(struct vop_reclaim_args *ap)
41 struct hammer2_inode *ip;
42 struct hammer2_mount *hmp;
44 kprintf("hammer2_reclaim\n");
46 /* Is the vnode locked? Must it be on exit? */
60 hammer2_fsync(struct vop_fsync_args *ap)
62 kprintf("hammer2_fsync\n");
67 hammer2_access(struct vop_access_args *ap)
69 kprintf("hammer2_access\n");
74 hammer2_getattr(struct vop_getattr_args *ap)
78 struct hammer2_inode *ip;
83 kprintf("hammer2_getattr\n");
86 hammer2_inode_lock_sh(ip);
88 vap->va_type = vp->v_type;
94 vap->va_blocksize = PAGE_SIZE;
97 hammer2_inode_unlock_sh(ip);
103 hammer2_readdir(struct vop_readdir_args *ap)
105 kprintf("hammer2_readdir\n");
110 hammer2_read(struct vop_read_args *ap)
116 hammer2_nresolve(struct vop_nresolve_args *ap)
118 kprintf("hammer2_nresolve\n");
123 hammer2_bmap(struct vop_bmap_args *ap)
125 kprintf("hammer2_bmap\n");
130 hammer2_open(struct vop_open_args *ap)
132 kprintf("hammer2_open\n");
133 return vop_stdopen(ap);
137 hammer2_strategy(struct vop_strategy_args *ap)
142 struct hammer2_inode *ip;
152 case (BUF_CMD_WRITE):
154 bp->b_error = error = EINVAL;
155 bp->b_flags |= B_ERROR;
163 struct vop_ops hammer2_vnode_vops = {
164 .vop_default = vop_defaultop,
165 .vop_fsync = hammer2_fsync,
166 .vop_getpages = vop_stdgetpages,
167 .vop_putpages = vop_stdputpages,
168 .vop_access = hammer2_access,
169 .vop_getattr = hammer2_getattr,
170 //// .vop_readdir = hammer2_readdir,
171 // .vop_read = hammer2_read,
172 // .vop_write = hammer2_write,
173 .vop_open = hammer2_open,
174 .vop_inactive = hammer2_inactive,
175 .vop_reclaim = hammer2_reclaim,
176 .vop_nresolve = hammer2_nresolve,
178 // .vop_bmap = hammer2_bmap,
179 // .vop_strategy = hammer2_strategy,
182 struct vop_ops hammer2_spec_vops = {
186 struct vop_ops hammer2_fifo_vops = {
190 * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
191 * All rights reserved.
193 * This code is derived from software contributed to The NetBSD Foundation
194 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
197 * Redistribution and use in source and binary forms, with or without
198 * modification, are permitted provided that the following conditions
200 * 1. Redistributions of source code must retain the above copyright
201 * notice, this list of conditions and the following disclaimer.
202 * 2. Redistributions in binary form must reproduce the above copyright
203 * notice, this list of conditions and the following disclaimer in the
204 * documentation and/or other materials provided with the distribution.
206 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
207 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
208 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
209 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
210 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
212 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
213 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
214 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
215 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
216 * POSSIBILITY OF SUCH DAMAGE.
218 * $NetBSD: tmpfs_vnops.c,v 1.39 2007/07/23 15:41:01 jmmv Exp $
222 * tmpfs vnode interface.
225 #include <sys/kernel.h>
226 #include <sys/kern_syscall.h>
227 #include <sys/param.h>
228 #include <sys/fcntl.h>
229 #include <sys/lockf.h>
230 #include <sys/priv.h>
231 #include <sys/proc.h>
232 #include <sys/resourcevar.h>
233 #include <sys/sched.h>
234 #include <sys/stat.h>
235 #include <sys/systm.h>
236 #include <sys/unistd.h>
237 #include <sys/vfsops.h>
238 #include <sys/vnode.h>
241 #include <vm/vm_object.h>
242 #include <vm/vm_page.h>
243 #include <vm/vm_pager.h>
244 #include <vm/swap_pager.h>
246 #include <sys/buf2.h>
248 #include <vfs/fifofs/fifo.h>
251 MALLOC_DECLARE(M_TMPFS);
253 static void tmpfs_strategy_done(struct bio *bio);
257 tmpfs_knote(struct vnode *vp, int flags)
260 KNOTE(&vp->v_pollinfo.vpi_kqinfo.ki_note, flags);
264 /* --------------------------------------------------------------------- */
267 tmpfs_nresolve(struct vop_nresolve_args *v)
269 struct vnode *dvp = v->a_dvp;
270 struct vnode *vp = NULL;
271 struct namecache *ncp = v->a_nch->ncp;
272 struct tmpfs_node *tnode;
275 struct tmpfs_dirent *de;
276 struct tmpfs_node *dnode;
278 dnode = VP_TO_TMPFS_DIR(dvp);
280 de = tmpfs_dir_lookup(dnode, NULL, ncp);
285 * Allocate a vnode for the node we found.
288 error = tmpfs_alloc_vp(dvp->v_mount, tnode,
289 LK_EXCLUSIVE | LK_RETRY, &vp);
297 * Store the result of this lookup in the cache. Avoid this if the
298 * request was for creation, as it does not improve timings on
303 cache_setvp(v->a_nch, vp);
305 } else if (error == ENOENT) {
306 cache_setvp(v->a_nch, NULL);
312 tmpfs_nlookupdotdot(struct vop_nlookupdotdot_args *v)
314 struct vnode *dvp = v->a_dvp;
315 struct vnode **vpp = v->a_vpp;
316 struct tmpfs_node *dnode = VP_TO_TMPFS_NODE(dvp);
317 struct ucred *cred = v->a_cred;
321 /* Check accessibility of requested node as a first step. */
322 error = VOP_ACCESS(dvp, VEXEC, cred);
326 if (dnode->tn_dir.tn_parent != NULL) {
327 /* Allocate a new vnode on the matching entry. */
328 error = tmpfs_alloc_vp(dvp->v_mount, dnode->tn_dir.tn_parent,
329 LK_EXCLUSIVE | LK_RETRY, vpp);
335 return (*vpp == NULL) ? ENOENT : 0;
338 /* --------------------------------------------------------------------- */
341 tmpfs_ncreate(struct vop_ncreate_args *v)
343 struct vnode *dvp = v->a_dvp;
344 struct vnode **vpp = v->a_vpp;
345 struct namecache *ncp = v->a_nch->ncp;
346 struct vattr *vap = v->a_vap;
347 struct ucred *cred = v->a_cred;
350 KKASSERT(vap->va_type == VREG || vap->va_type == VSOCK);
352 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
354 cache_setunresolved(v->a_nch);
355 cache_setvp(v->a_nch, *vpp);
356 tmpfs_knote(dvp, NOTE_WRITE);
361 /* --------------------------------------------------------------------- */
364 tmpfs_nmknod(struct vop_nmknod_args *v)
366 struct vnode *dvp = v->a_dvp;
367 struct vnode **vpp = v->a_vpp;
368 struct namecache *ncp = v->a_nch->ncp;
369 struct vattr *vap = v->a_vap;
370 struct ucred *cred = v->a_cred;
373 if (vap->va_type != VBLK && vap->va_type != VCHR &&
374 vap->va_type != VFIFO)
377 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
379 cache_setunresolved(v->a_nch);
380 cache_setvp(v->a_nch, *vpp);
381 tmpfs_knote(dvp, NOTE_WRITE);
387 /* --------------------------------------------------------------------- */
390 tmpfs_open(struct vop_open_args *v)
392 struct vnode *vp = v->a_vp;
393 int mode = v->a_mode;
396 struct tmpfs_node *node;
398 node = VP_TO_TMPFS_NODE(vp);
400 /* The file is still active but all its names have been removed
401 * (e.g. by a "rmdir $(pwd)"). It cannot be opened any more as
402 * it is about to die. */
403 if (node->tn_links < 1)
406 /* If the file is marked append-only, deny write requests. */
407 if ((node->tn_flags & APPEND) &&
408 (mode & (FWRITE | O_APPEND)) == FWRITE) {
411 return (vop_stdopen(v));
416 /* --------------------------------------------------------------------- */
419 tmpfs_close(struct vop_close_args *v)
421 struct vnode *vp = v->a_vp;
422 struct tmpfs_node *node;
424 node = VP_TO_TMPFS_NODE(vp);
426 if (node->tn_links > 0) {
427 /* Update node times. No need to do it if the node has
428 * been deleted, because it will vanish after we return. */
432 return vop_stdclose(v);
435 /* --------------------------------------------------------------------- */
438 tmpfs_access(struct vop_access_args *v)
440 struct vnode *vp = v->a_vp;
442 struct tmpfs_node *node;
444 node = VP_TO_TMPFS_NODE(vp);
446 switch (vp->v_type) {
452 if ((v->a_mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
472 if ((v->a_mode & VWRITE) && (node->tn_flags & IMMUTABLE)) {
477 error = vop_helper_access(v, node->tn_uid, node->tn_gid, node->tn_mode, 0);
484 /* --------------------------------------------------------------------- */
487 tmpfs_getattr(struct vop_getattr_args *v)
489 struct vnode *vp = v->a_vp;
490 struct vattr *vap = v->a_vap;
491 struct tmpfs_node *node;
493 node = VP_TO_TMPFS_NODE(vp);
495 lwkt_gettoken(&vp->v_mount->mnt_token);
498 vap->va_type = vp->v_type;
499 vap->va_mode = node->tn_mode;
500 vap->va_nlink = node->tn_links;
501 vap->va_uid = node->tn_uid;
502 vap->va_gid = node->tn_gid;
503 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
504 vap->va_fileid = node->tn_id;
505 vap->va_size = node->tn_size;
506 vap->va_blocksize = PAGE_SIZE;
507 vap->va_atime.tv_sec = node->tn_atime;
508 vap->va_atime.tv_nsec = node->tn_atimensec;
509 vap->va_mtime.tv_sec = node->tn_mtime;
510 vap->va_mtime.tv_nsec = node->tn_mtimensec;
511 vap->va_ctime.tv_sec = node->tn_ctime;
512 vap->va_ctime.tv_nsec = node->tn_ctimensec;
513 vap->va_gen = node->tn_gen;
514 vap->va_flags = node->tn_flags;
515 if (vp->v_type == VBLK || vp->v_type == VCHR)
517 vap->va_rmajor = umajor(node->tn_rdev);
518 vap->va_rminor = uminor(node->tn_rdev);
520 vap->va_bytes = round_page(node->tn_size);
523 lwkt_reltoken(&vp->v_mount->mnt_token);
528 /* --------------------------------------------------------------------- */
531 tmpfs_setattr(struct vop_setattr_args *v)
533 struct vnode *vp = v->a_vp;
534 struct vattr *vap = v->a_vap;
535 struct ucred *cred = v->a_cred;
536 struct tmpfs_node *node = VP_TO_TMPFS_NODE(vp);
540 if (error == 0 && (vap->va_flags != VNOVAL)) {
541 error = tmpfs_chflags(vp, vap->va_flags, cred);
542 kflags |= NOTE_ATTRIB;
545 if (error == 0 && (vap->va_size != VNOVAL)) {
546 if (vap->va_size > node->tn_size)
547 kflags |= NOTE_WRITE | NOTE_EXTEND;
549 kflags |= NOTE_WRITE;
550 error = tmpfs_chsize(vp, vap->va_size, cred);
553 if (error == 0 && (vap->va_uid != (uid_t)VNOVAL ||
554 vap->va_gid != (gid_t)VNOVAL)) {
555 error = tmpfs_chown(vp, vap->va_uid, vap->va_gid, cred);
556 kflags |= NOTE_ATTRIB;
559 if (error == 0 && (vap->va_mode != (mode_t)VNOVAL)) {
560 error = tmpfs_chmod(vp, vap->va_mode, cred);
561 kflags |= NOTE_ATTRIB;
564 if (error == 0 && ((vap->va_atime.tv_sec != VNOVAL &&
565 vap->va_atime.tv_nsec != VNOVAL) ||
566 (vap->va_mtime.tv_sec != VNOVAL &&
567 vap->va_mtime.tv_nsec != VNOVAL) )) {
568 error = tmpfs_chtimes(vp, &vap->va_atime, &vap->va_mtime,
569 vap->va_vaflags, cred);
570 kflags |= NOTE_ATTRIB;
573 /* Update the node times. We give preference to the error codes
574 * generated by this function rather than the ones that may arise
575 * from tmpfs_update. */
577 tmpfs_knote(vp, kflags);
582 /* --------------------------------------------------------------------- */
585 * fsync is usually a NOP, but we must take action when unmounting or
589 tmpfs_fsync(struct vop_fsync_args *v)
591 struct hammer2_mount *tmp;
592 struct tmpfs_node *node;
593 struct vnode *vp = v->a_vp;
595 tmp = VFS_TO_TMPFS(vp->v_mount);
596 node = VP_TO_TMPFS_NODE(vp);
599 if (vp->v_type == VREG) {
600 if (vp->v_flag & VRECLAIMED) {
601 if (node->tn_links == 0)
602 tmpfs_truncate(vp, 0);
604 vfsync(v->a_vp, v->a_waitfor, 1, NULL, NULL);
610 /* --------------------------------------------------------------------- */
613 tmpfs_read (struct vop_read_args *ap)
616 struct vnode *vp = ap->a_vp;
617 struct uio *uio = ap->a_uio;
618 struct tmpfs_node *node;
625 if (uio->uio_resid == 0) {
629 node = VP_TO_TMPFS_NODE(vp);
631 if (uio->uio_offset < 0)
633 if (vp->v_type != VREG)
636 while (uio->uio_resid > 0 && uio->uio_offset < node->tn_size) {
638 * Use buffer cache I/O (via tmpfs_strategy)
640 offset = (size_t)uio->uio_offset & BMASK;
641 base_offset = (off_t)uio->uio_offset - offset;
642 bp = getcacheblk(vp, base_offset, BSIZE);
645 lwkt_gettoken(&vp->v_mount->mnt_token);
646 error = bread(vp, base_offset, BSIZE, &bp);
649 lwkt_reltoken(&vp->v_mount->mnt_token);
650 kprintf("tmpfs_read bread error %d\n", error);
653 lwkt_reltoken(&vp->v_mount->mnt_token);
657 * Figure out how many bytes we can actually copy this loop.
659 len = BSIZE - offset;
660 if (len > uio->uio_resid)
661 len = uio->uio_resid;
662 if (len > node->tn_size - uio->uio_offset)
663 len = (size_t)(node->tn_size - uio->uio_offset);
665 error = uiomove((char *)bp->b_data + offset, len, uio);
668 kprintf("tmpfs_read uiomove error %d\n", error);
673 TMPFS_NODE_LOCK(node);
674 node->tn_status |= TMPFS_NODE_ACCESSED;
675 TMPFS_NODE_UNLOCK(node);
681 hammer2_write(struct vop_write_args *ap)
683 struct vnode *vp = ap->a_vp;
684 struct uio *uio = ap->a_uio;
692 tmpfs_write (struct vop_write_args *ap)
695 struct vnode *vp = ap->a_vp;
696 struct uio *uio = ap->a_uio;
697 struct thread *td = uio->uio_td;
698 struct tmpfs_node *node;
710 if (uio->uio_resid == 0) {
714 node = VP_TO_TMPFS_NODE(vp);
716 if (vp->v_type != VREG)
719 lwkt_gettoken(&vp->v_mount->mnt_token);
721 oldsize = node->tn_size;
722 if (ap->a_ioflag & IO_APPEND)
723 uio->uio_offset = node->tn_size;
726 * Check for illegal write offsets.
728 if (uio->uio_offset + uio->uio_resid >
729 VFS_TO_TMPFS(vp->v_mount)->tm_maxfilesize) {
730 lwkt_reltoken(&vp->v_mount->mnt_token);
734 if (vp->v_type == VREG && td != NULL) {
735 error = kern_getrlimit(RLIMIT_FSIZE, &limit);
737 lwkt_reltoken(&vp->v_mount->mnt_token);
740 if (uio->uio_offset + uio->uio_resid > limit.rlim_cur) {
741 ksignal(td->td_proc, SIGXFSZ);
742 lwkt_reltoken(&vp->v_mount->mnt_token);
749 * Extend the file's size if necessary
751 extended = ((uio->uio_offset + uio->uio_resid) > node->tn_size);
753 while (uio->uio_resid > 0) {
755 * Use buffer cache I/O (via tmpfs_strategy)
757 offset = (size_t)uio->uio_offset & BMASK;
758 base_offset = (off_t)uio->uio_offset - offset;
759 len = BSIZE - offset;
760 if (len > uio->uio_resid)
761 len = uio->uio_resid;
763 if ((uio->uio_offset + len) > node->tn_size) {
764 trivial = (uio->uio_offset <= node->tn_size);
765 error = tmpfs_reg_resize(vp, uio->uio_offset + len, trivial);
771 * Read to fill in any gaps. Theoretically we could
772 * optimize this if the write covers the entire buffer
773 * and is not a UIO_NOCOPY write, however this can lead
774 * to a security violation exposing random kernel memory
775 * (whatever junk was in the backing VM pages before).
777 * So just use bread() to do the right thing.
779 error = bread(vp, base_offset, BSIZE, &bp);
780 error = uiomove((char *)bp->b_data + offset, len, uio);
782 kprintf("tmpfs_write uiomove error %d\n", error);
787 if (uio->uio_offset > node->tn_size) {
788 node->tn_size = uio->uio_offset;
789 kflags |= NOTE_EXTEND;
791 kflags |= NOTE_WRITE;
794 * The data has been loaded into the buffer, write it out.
796 * We want tmpfs to be able to use all available ram, not
797 * just the buffer cache, so if not explicitly paging we
798 * use buwrite() to leave the buffer clean but mark all the
799 * VM pages valid+dirty.
801 * When the kernel is paging, either via normal pageout
802 * operation or when cleaning the object during a recycle,
803 * the underlying VM pages are going to get thrown away
804 * so we MUST write them to swap.
806 * XXX unfortunately this catches msync() system calls too
809 if (vm_swap_size == 0) {
811 * if swap isn't configured yet, force a buwrite() to
812 * avoid problems further down the line, due to flushing
817 if (ap->a_ioflag & IO_SYNC) {
819 } else if ((ap->a_ioflag & IO_ASYNC) ||
820 (uio->uio_segflg == UIO_NOCOPY)) {
828 kprintf("tmpfs_write bwrite error %d\n", bp->b_error);
835 (void)tmpfs_reg_resize(vp, oldsize, trivial);
836 kflags &= ~NOTE_EXTEND;
841 TMPFS_NODE_LOCK(node);
842 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED |
843 (extended? TMPFS_NODE_CHANGED : 0);
845 if (node->tn_mode & (S_ISUID | S_ISGID)) {
846 if (priv_check_cred(ap->a_cred, PRIV_VFS_RETAINSUGID, 0))
847 node->tn_mode &= ~(S_ISUID | S_ISGID);
849 TMPFS_NODE_UNLOCK(node);
852 tmpfs_knote(vp, kflags);
855 lwkt_reltoken(&vp->v_mount->mnt_token);
860 tmpfs_advlock (struct vop_advlock_args *ap)
862 struct tmpfs_node *node;
863 struct vnode *vp = ap->a_vp;
865 node = VP_TO_TMPFS_NODE(vp);
867 return (lf_advlock(ap, &node->tn_advlock, node->tn_size));
871 tmpfs_strategy(struct vop_strategy_args *ap)
873 struct bio *bio = ap->a_bio;
875 struct buf *bp = bio->bio_buf;
876 struct vnode *vp = ap->a_vp;
877 struct tmpfs_node *node;
882 if (vp->v_type != VREG) {
883 bp->b_resid = bp->b_bcount;
884 bp->b_flags |= B_ERROR | B_INVAL;
885 bp->b_error = EINVAL;
890 lwkt_gettoken(&vp->v_mount->mnt_token);
891 node = VP_TO_TMPFS_NODE(vp);
893 uobj = node->tn_reg.tn_aobj;
896 * Certain operations such as nvtruncbuf() can result in a
897 * bdwrite() of one or more buffers related to the file,
898 * leading to the possibility of our strategy function
899 * being called for writing even when there is no swap space.
901 * When this case occurs we mark the underlying pages as valid
902 * and dirty and complete the I/O manually.
904 * Otherwise just call swap_pager_strategy to read or write,
905 * potentially assigning swap on write. We push a BIO to catch
906 * any swap allocation errors.
908 if (bp->b_cmd == BUF_CMD_WRITE && vm_swap_size == 0) {
909 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
910 m = bp->b_xio.xio_pages[i];
911 vm_page_set_validdirty(m, 0, PAGE_SIZE);
917 nbio = push_bio(bio);
918 nbio->bio_done = tmpfs_strategy_done;
919 nbio->bio_offset = bio->bio_offset;
920 swap_pager_strategy(uobj, nbio);
923 lwkt_reltoken(&vp->v_mount->mnt_token);
928 * bio finished. If we ran out of sap just mark the pages valid
929 * and dirty and make it appear that the I/O has completed successfully.
932 tmpfs_strategy_done(struct bio *bio)
940 if ((bp->b_flags & B_ERROR) && bp->b_error == ENOMEM) {
941 bp->b_flags &= ~B_ERROR;
944 for (i = 0; i < bp->b_xio.xio_npages; ++i) {
945 m = bp->b_xio.xio_pages[i];
946 vm_page_set_validdirty(m, 0, PAGE_SIZE);
954 tmpfs_bmap(struct vop_bmap_args *ap)
956 if (ap->a_doffsetp != NULL)
957 *ap->a_doffsetp = ap->a_loffset;
958 if (ap->a_runp != NULL)
960 if (ap->a_runb != NULL)
966 /* --------------------------------------------------------------------- */
969 tmpfs_nremove(struct vop_nremove_args *v)
971 struct vnode *dvp = v->a_dvp;
972 struct namecache *ncp = v->a_nch->ncp;
975 struct tmpfs_dirent *de;
976 struct hammer2_mount *tmp;
977 struct tmpfs_node *dnode;
978 struct tmpfs_node *node;
981 * We have to acquire the vp from v->a_nch because we will likely
982 * unresolve the namecache entry, and a vrele/vput is needed to
983 * trigger the tmpfs_inactive/tmpfs_reclaim sequence.
985 * We have to use vget to clear any inactive state on the vnode,
986 * otherwise the vnode may remain inactive and thus tmpfs_inactive
987 * will not get called when we release it.
989 error = cache_vget(v->a_nch, v->a_cred, LK_SHARED, &vp);
990 KKASSERT(error == 0);
993 if (vp->v_type == VDIR) {
998 dnode = VP_TO_TMPFS_DIR(dvp);
999 node = VP_TO_TMPFS_NODE(vp);
1000 tmp = VFS_TO_TMPFS(vp->v_mount);
1001 de = tmpfs_dir_lookup(dnode, node, ncp);
1007 /* Files marked as immutable or append-only cannot be deleted. */
1008 if ((node->tn_flags & (IMMUTABLE | APPEND | NOUNLINK)) ||
1009 (dnode->tn_flags & APPEND)) {
1014 /* Remove the entry from the directory; as it is a file, we do not
1015 * have to change the number of hard links of the directory. */
1016 tmpfs_dir_detach(dnode, de);
1018 /* Free the directory entry we just deleted. Note that the node
1019 * referred by it will not be removed until the vnode is really
1021 tmpfs_free_dirent(tmp, de);
1023 if (node->tn_links > 0) {
1024 TMPFS_NODE_LOCK(node);
1025 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
1026 TMPFS_NODE_MODIFIED;
1027 TMPFS_NODE_UNLOCK(node);
1030 cache_setunresolved(v->a_nch);
1031 cache_setvp(v->a_nch, NULL);
1032 tmpfs_knote(vp, NOTE_DELETE);
1033 /*cache_inval_vp(vp, CINV_DESTROY);*/
1034 tmpfs_knote(dvp, NOTE_WRITE);
1043 /* --------------------------------------------------------------------- */
1046 tmpfs_nlink(struct vop_nlink_args *v)
1048 struct vnode *dvp = v->a_dvp;
1049 struct vnode *vp = v->a_vp;
1050 struct namecache *ncp = v->a_nch->ncp;
1051 struct tmpfs_dirent *de;
1052 struct tmpfs_node *node;
1053 struct tmpfs_node *dnode;
1056 KKASSERT(dvp != vp); /* XXX When can this be false? */
1058 node = VP_TO_TMPFS_NODE(vp);
1059 dnode = VP_TO_TMPFS_NODE(dvp);
1061 /* XXX: Why aren't the following two tests done by the caller? */
1063 /* Hard links of directories are forbidden. */
1064 if (vp->v_type == VDIR) {
1069 /* Cannot create cross-device links. */
1070 if (dvp->v_mount != vp->v_mount) {
1075 /* Ensure that we do not overflow the maximum number of links imposed
1077 KKASSERT(node->tn_links <= LINK_MAX);
1078 if (node->tn_links == LINK_MAX) {
1083 /* We cannot create links of files marked immutable or append-only. */
1084 if (node->tn_flags & (IMMUTABLE | APPEND)) {
1089 /* Allocate a new directory entry to represent the node. */
1090 error = tmpfs_alloc_dirent(VFS_TO_TMPFS(vp->v_mount), node,
1091 ncp->nc_name, ncp->nc_nlen, &de);
1095 /* Insert the new directory entry into the appropriate directory. */
1096 tmpfs_dir_attach(dnode, de);
1098 /* vp link count has changed, so update node times. */
1100 TMPFS_NODE_LOCK(node);
1101 node->tn_status |= TMPFS_NODE_CHANGED;
1102 TMPFS_NODE_UNLOCK(node);
1105 tmpfs_knote(vp, NOTE_LINK);
1106 cache_setunresolved(v->a_nch);
1107 cache_setvp(v->a_nch, vp);
1108 tmpfs_knote(dvp, NOTE_WRITE);
1115 /* --------------------------------------------------------------------- */
1118 tmpfs_nrename(struct vop_nrename_args *v)
1120 struct vnode *fdvp = v->a_fdvp;
1121 struct namecache *fncp = v->a_fnch->ncp;
1122 struct vnode *fvp = fncp->nc_vp;
1123 struct vnode *tdvp = v->a_tdvp;
1124 struct namecache *tncp = v->a_tnch->ncp;
1126 struct tmpfs_dirent *de;
1127 struct hammer2_mount *tmp;
1128 struct tmpfs_node *fdnode;
1129 struct tmpfs_node *fnode;
1130 struct tmpfs_node *tnode;
1131 struct tmpfs_node *tdnode;
1137 * Because tvp can get overwritten we have to vget it instead of
1138 * just vref or use it, otherwise it's VINACTIVE flag may not get
1139 * cleared and the node won't get destroyed.
1141 error = cache_vget(v->a_tnch, v->a_cred, LK_SHARED, &tvp);
1143 tnode = VP_TO_TMPFS_NODE(tvp);
1149 /* Disallow cross-device renames.
1150 * XXX Why isn't this done by the caller? */
1151 if (fvp->v_mount != tdvp->v_mount ||
1152 (tvp != NULL && fvp->v_mount != tvp->v_mount)) {
1157 tmp = VFS_TO_TMPFS(tdvp->v_mount);
1158 tdnode = VP_TO_TMPFS_DIR(tdvp);
1160 /* If source and target are the same file, there is nothing to do. */
1166 fdnode = VP_TO_TMPFS_DIR(fdvp);
1167 fnode = VP_TO_TMPFS_NODE(fvp);
1168 de = tmpfs_dir_lookup(fdnode, fnode, fncp);
1170 /* Avoid manipulating '.' and '..' entries. */
1175 KKASSERT(de->td_node == fnode);
1178 * If replacing an entry in the target directory and that entry
1179 * is a directory, it must be empty.
1181 * Kern_rename gurantees the destination to be a directory
1182 * if the source is one (it does?).
1185 KKASSERT(tnode != NULL);
1187 if ((tnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1188 (tdnode->tn_flags & (APPEND | IMMUTABLE))) {
1193 if (fnode->tn_type == VDIR && tnode->tn_type == VDIR) {
1194 if (tnode->tn_size > 0) {
1198 } else if (fnode->tn_type == VDIR && tnode->tn_type != VDIR) {
1201 } else if (fnode->tn_type != VDIR && tnode->tn_type == VDIR) {
1205 KKASSERT(fnode->tn_type != VDIR &&
1206 tnode->tn_type != VDIR);
1210 if ((fnode->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) ||
1211 (fdnode->tn_flags & (APPEND | IMMUTABLE))) {
1217 * Ensure that we have enough memory to hold the new name, if it
1218 * has to be changed.
1220 if (fncp->nc_nlen != tncp->nc_nlen ||
1221 bcmp(fncp->nc_name, tncp->nc_name, fncp->nc_nlen) != 0) {
1222 newname = kmalloc(tncp->nc_nlen + 1, tmp->tm_name_zone,
1223 M_WAITOK | M_NULLOK);
1224 if (newname == NULL) {
1228 bcopy(tncp->nc_name, newname, tncp->nc_nlen);
1229 newname[tncp->nc_nlen] = '\0';
1235 * Unlink entry from source directory. Note that the kernel has
1236 * already checked for illegal recursion cases (renaming a directory
1237 * into a subdirectory of itself).
1239 if (fdnode != tdnode)
1240 tmpfs_dir_detach(fdnode, de);
1243 * Handle any name change. Swap with newname, we will
1244 * deallocate it at the end.
1246 if (newname != NULL) {
1248 TMPFS_NODE_LOCK(fnode);
1249 fnode->tn_status |= TMPFS_NODE_CHANGED;
1250 TMPFS_NODE_UNLOCK(fnode);
1252 oldname = de->td_name;
1253 de->td_name = newname;
1254 de->td_namelen = (uint16_t)tncp->nc_nlen;
1259 * Link entry to target directory. If the entry
1260 * represents a directory move the parent linkage
1263 if (fdnode != tdnode) {
1264 if (de->td_node->tn_type == VDIR) {
1265 TMPFS_VALIDATE_DIR(fnode);
1267 TMPFS_NODE_LOCK(tdnode);
1269 tdnode->tn_status |= TMPFS_NODE_MODIFIED;
1270 TMPFS_NODE_UNLOCK(tdnode);
1272 TMPFS_NODE_LOCK(fnode);
1273 fnode->tn_dir.tn_parent = tdnode;
1274 fnode->tn_status |= TMPFS_NODE_CHANGED;
1275 TMPFS_NODE_UNLOCK(fnode);
1277 TMPFS_NODE_LOCK(fdnode);
1279 fdnode->tn_status |= TMPFS_NODE_MODIFIED;
1280 TMPFS_NODE_UNLOCK(fdnode);
1282 tmpfs_dir_attach(tdnode, de);
1284 TMPFS_NODE_LOCK(tdnode);
1285 tdnode->tn_status |= TMPFS_NODE_MODIFIED;
1286 TMPFS_NODE_UNLOCK(tdnode);
1290 * If we are overwriting an entry, we have to remove the old one
1291 * from the target directory.
1294 /* Remove the old entry from the target directory. */
1295 de = tmpfs_dir_lookup(tdnode, tnode, tncp);
1296 tmpfs_dir_detach(tdnode, de);
1297 tmpfs_knote(tdnode->tn_vnode, NOTE_DELETE);
1300 * Free the directory entry we just deleted. Note that the
1301 * node referred by it will not be removed until the vnode is
1304 tmpfs_free_dirent(VFS_TO_TMPFS(tvp->v_mount), de);
1305 /*cache_inval_vp(tvp, CINV_DESTROY);*/
1312 kfree(newname, tmp->tm_name_zone);
1315 cache_rename(v->a_fnch, v->a_tnch);
1316 tmpfs_knote(v->a_fdvp, NOTE_WRITE);
1317 tmpfs_knote(v->a_tdvp, NOTE_WRITE);
1318 if (fnode->tn_vnode)
1319 tmpfs_knote(fnode->tn_vnode, NOTE_RENAME);
1332 /* --------------------------------------------------------------------- */
1335 tmpfs_nmkdir(struct vop_nmkdir_args *v)
1337 struct vnode *dvp = v->a_dvp;
1338 struct vnode **vpp = v->a_vpp;
1339 struct namecache *ncp = v->a_nch->ncp;
1340 struct vattr *vap = v->a_vap;
1341 struct ucred *cred = v->a_cred;
1344 KKASSERT(vap->va_type == VDIR);
1346 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, NULL);
1348 cache_setunresolved(v->a_nch);
1349 cache_setvp(v->a_nch, *vpp);
1350 tmpfs_knote(dvp, NOTE_WRITE | NOTE_LINK);
1356 /* --------------------------------------------------------------------- */
1359 tmpfs_nrmdir(struct vop_nrmdir_args *v)
1361 struct vnode *dvp = v->a_dvp;
1362 struct namecache *ncp = v->a_nch->ncp;
1364 struct tmpfs_dirent *de;
1365 struct hammer2_mount *tmp;
1366 struct tmpfs_node *dnode;
1367 struct tmpfs_node *node;
1371 * We have to acquire the vp from v->a_nch because we will likely
1372 * unresolve the namecache entry, and a vrele/vput is needed to
1373 * trigger the tmpfs_inactive/tmpfs_reclaim sequence.
1375 * We have to use vget to clear any inactive state on the vnode,
1376 * otherwise the vnode may remain inactive and thus tmpfs_inactive
1377 * will not get called when we release it.
1379 error = cache_vget(v->a_nch, v->a_cred, LK_SHARED, &vp);
1380 KKASSERT(error == 0);
1384 * Prevalidate so we don't hit an assertion later
1386 if (vp->v_type != VDIR) {
1391 tmp = VFS_TO_TMPFS(dvp->v_mount);
1392 dnode = VP_TO_TMPFS_DIR(dvp);
1393 node = VP_TO_TMPFS_DIR(vp);
1395 /* Directories with more than two entries ('.' and '..') cannot be
1397 if (node->tn_size > 0) {
1402 if ((dnode->tn_flags & APPEND)
1403 || (node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND))) {
1408 /* This invariant holds only if we are not trying to remove "..".
1409 * We checked for that above so this is safe now. */
1410 KKASSERT(node->tn_dir.tn_parent == dnode);
1412 /* Get the directory entry associated with node (vp). This was
1413 * filled by tmpfs_lookup while looking up the entry. */
1414 de = tmpfs_dir_lookup(dnode, node, ncp);
1415 KKASSERT(TMPFS_DIRENT_MATCHES(de,
1419 /* Check flags to see if we are allowed to remove the directory. */
1420 if ((dnode->tn_flags & APPEND) ||
1421 node->tn_flags & (NOUNLINK | IMMUTABLE | APPEND)) {
1427 /* Detach the directory entry from the directory (dnode). */
1428 tmpfs_dir_detach(dnode, de);
1430 /* No vnode should be allocated for this entry from this point */
1431 TMPFS_NODE_LOCK(node);
1432 TMPFS_ASSERT_ELOCKED(node);
1433 TMPFS_NODE_LOCK(dnode);
1434 TMPFS_ASSERT_ELOCKED(dnode);
1437 /* handled by tmpfs_free_node */
1438 KKASSERT(node->tn_links > 0);
1440 node->tn_dir.tn_parent = NULL;
1442 node->tn_status |= TMPFS_NODE_ACCESSED | TMPFS_NODE_CHANGED | \
1443 TMPFS_NODE_MODIFIED;
1446 /* handled by tmpfs_free_node */
1447 KKASSERT(dnode->tn_links > 0);
1450 dnode->tn_status |= TMPFS_NODE_ACCESSED | \
1451 TMPFS_NODE_CHANGED | TMPFS_NODE_MODIFIED;
1453 TMPFS_NODE_UNLOCK(dnode);
1454 TMPFS_NODE_UNLOCK(node);
1456 /* Free the directory entry we just deleted. Note that the node
1457 * referred by it will not be removed until the vnode is really
1459 tmpfs_free_dirent(tmp, de);
1461 /* Release the deleted vnode (will destroy the node, notify
1462 * interested parties and clean it from the cache). */
1464 TMPFS_NODE_LOCK(dnode);
1465 dnode->tn_status |= TMPFS_NODE_CHANGED;
1466 TMPFS_NODE_UNLOCK(dnode);
1469 cache_setunresolved(v->a_nch);
1470 cache_setvp(v->a_nch, NULL);
1471 /*cache_inval_vp(vp, CINV_DESTROY);*/
1472 tmpfs_knote(dvp, NOTE_WRITE | NOTE_LINK);
1481 /* --------------------------------------------------------------------- */
1484 tmpfs_nsymlink(struct vop_nsymlink_args *v)
1486 struct vnode *dvp = v->a_dvp;
1487 struct vnode **vpp = v->a_vpp;
1488 struct namecache *ncp = v->a_nch->ncp;
1489 struct vattr *vap = v->a_vap;
1490 struct ucred *cred = v->a_cred;
1491 char *target = v->a_target;
1494 vap->va_type = VLNK;
1495 error = tmpfs_alloc_file(dvp, vpp, vap, ncp, cred, target);
1497 tmpfs_knote(*vpp, NOTE_WRITE);
1498 cache_setunresolved(v->a_nch);
1499 cache_setvp(v->a_nch, *vpp);
1505 /* --------------------------------------------------------------------- */
1508 tmpfs_readdir(struct vop_readdir_args *v)
1510 struct vnode *vp = v->a_vp;
1511 struct uio *uio = v->a_uio;
1512 int *eofflag = v->a_eofflag;
1513 off_t **cookies = v->a_cookies;
1514 int *ncookies = v->a_ncookies;
1515 struct hammer2_mount *tmp;
1519 struct tmpfs_node *node;
1521 /* This operation only makes sense on directory nodes. */
1522 if (vp->v_type != VDIR)
1525 tmp = VFS_TO_TMPFS(vp->v_mount);
1526 node = VP_TO_TMPFS_DIR(vp);
1527 startoff = uio->uio_offset;
1529 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOT) {
1530 error = tmpfs_dir_getdotdent(node, uio);
1536 if (uio->uio_offset == TMPFS_DIRCOOKIE_DOTDOT) {
1537 error = tmpfs_dir_getdotdotdent(tmp, node, uio);
1543 error = tmpfs_dir_getdents(node, uio, &cnt);
1546 KKASSERT(error >= -1);
1551 if (eofflag != NULL)
1553 (error == 0 && uio->uio_offset == TMPFS_DIRCOOKIE_EOF);
1555 /* Update NFS-related variables. */
1556 if (error == 0 && cookies != NULL && ncookies != NULL) {
1558 off_t off = startoff;
1559 struct tmpfs_dirent *de = NULL;
1562 *cookies = kmalloc(cnt * sizeof(off_t), M_TEMP, M_WAITOK);
1564 for (i = 0; i < cnt; i++) {
1565 KKASSERT(off != TMPFS_DIRCOOKIE_EOF);
1566 if (off == TMPFS_DIRCOOKIE_DOT) {
1567 off = TMPFS_DIRCOOKIE_DOTDOT;
1569 if (off == TMPFS_DIRCOOKIE_DOTDOT) {
1570 de = TAILQ_FIRST(&node->tn_dir.tn_dirhead);
1571 } else if (de != NULL) {
1572 de = TAILQ_NEXT(de, td_entries);
1574 de = tmpfs_dir_lookupbycookie(node,
1576 KKASSERT(de != NULL);
1577 de = TAILQ_NEXT(de, td_entries);
1580 off = TMPFS_DIRCOOKIE_EOF;
1582 off = tmpfs_dircookie(de);
1585 (*cookies)[i] = off;
1587 KKASSERT(uio->uio_offset == off);
1593 /* --------------------------------------------------------------------- */
1596 tmpfs_readlink(struct vop_readlink_args *v)
1598 struct vnode *vp = v->a_vp;
1599 struct uio *uio = v->a_uio;
1602 struct tmpfs_node *node;
1604 KKASSERT(uio->uio_offset == 0);
1605 KKASSERT(vp->v_type == VLNK);
1607 node = VP_TO_TMPFS_NODE(vp);
1609 error = uiomove(node->tn_link, MIN(node->tn_size, uio->uio_resid),
1611 TMPFS_NODE_LOCK(node);
1612 node->tn_status |= TMPFS_NODE_ACCESSED;
1613 TMPFS_NODE_UNLOCK(node);
1618 /* --------------------------------------------------------------------- */
1621 tmpfs_inactive(struct vop_inactive_args *v)
1623 struct vnode *vp = v->a_vp;
1624 struct tmpfs_node *node;
1626 node = VP_TO_TMPFS_NODE(vp);
1637 * Get rid of unreferenced deleted vnodes sooner rather than
1638 * later so the data memory can be recovered immediately.
1640 * We must truncate the vnode to prevent the normal reclamation
1641 * path from flushing the data for the removed file to disk.
1643 TMPFS_NODE_LOCK(node);
1644 if ((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0 &&
1645 (node->tn_links == 0 ||
1646 (node->tn_links == 1 && node->tn_type == VDIR &&
1647 node->tn_dir.tn_parent)))
1649 node->tn_vpstate = TMPFS_VNODE_DOOMED;
1650 TMPFS_NODE_UNLOCK(node);
1651 if (node->tn_type == VREG)
1652 tmpfs_truncate(vp, 0);
1655 TMPFS_NODE_UNLOCK(node);
1661 /* --------------------------------------------------------------------- */
1664 tmpfs_reclaim(struct vop_reclaim_args *v)
1666 struct vnode *vp = v->a_vp;
1667 struct hammer2_mount *tmp;
1668 struct tmpfs_node *node;
1670 node = VP_TO_TMPFS_NODE(vp);
1671 tmp = VFS_TO_TMPFS(vp->v_mount);
1676 * If the node referenced by this vnode was deleted by the
1677 * user, we must free its associated data structures now that
1678 * the vnode is being reclaimed.
1680 * Directories have an extra link ref.
1682 TMPFS_NODE_LOCK(node);
1683 if ((node->tn_vpstate & TMPFS_VNODE_ALLOCATING) == 0 &&
1684 (node->tn_links == 0 ||
1685 (node->tn_links == 1 && node->tn_type == VDIR &&
1686 node->tn_dir.tn_parent)))
1688 node->tn_vpstate = TMPFS_VNODE_DOOMED;
1689 tmpfs_free_node(tmp, node);
1692 TMPFS_NODE_UNLOCK(node);
1695 KKASSERT(vp->v_data == NULL);
1699 /* --------------------------------------------------------------------- */
1702 tmpfs_print(struct vop_print_args *v)
1704 struct vnode *vp = v->a_vp;
1706 struct tmpfs_node *node;
1708 node = VP_TO_TMPFS_NODE(vp);
1710 kprintf("tag VT_TMPFS, tmpfs_node %p, flags 0x%x, links %d\n",
1711 node, node->tn_flags, node->tn_links);
1712 kprintf("\tmode 0%o, owner %d, group %d, size %ju, status 0x%x\n",
1713 node->tn_mode, node->tn_uid, node->tn_gid,
1714 (uintmax_t)node->tn_size, node->tn_status);
1716 if (vp->v_type == VFIFO)
1724 /* --------------------------------------------------------------------- */
1727 tmpfs_pathconf(struct vop_pathconf_args *v)
1729 int name = v->a_name;
1730 register_t *retval = v->a_retval;
1753 case _PC_CHOWN_RESTRICTED:
1765 case _PC_FILESIZEBITS:
1766 *retval = 0; /* XXX Don't know which value should I return. */
1776 /************************************************************************
1778 ************************************************************************/
1780 static void filt_tmpfsdetach(struct knote *kn);
1781 static int filt_tmpfsread(struct knote *kn, long hint);
1782 static int filt_tmpfswrite(struct knote *kn, long hint);
1783 static int filt_tmpfsvnode(struct knote *kn, long hint);
1785 static struct filterops tmpfsread_filtops =
1786 { FILTEROP_ISFD, NULL, filt_tmpfsdetach, filt_tmpfsread };
1787 static struct filterops tmpfswrite_filtops =
1788 { FILTEROP_ISFD, NULL, filt_tmpfsdetach, filt_tmpfswrite };
1789 static struct filterops tmpfsvnode_filtops =
1790 { FILTEROP_ISFD, NULL, filt_tmpfsdetach, filt_tmpfsvnode };
1793 tmpfs_kqfilter (struct vop_kqfilter_args *ap)
1795 struct vnode *vp = ap->a_vp;
1796 struct knote *kn = ap->a_kn;
1798 switch (kn->kn_filter) {
1800 kn->kn_fop = &tmpfsread_filtops;
1803 kn->kn_fop = &tmpfswrite_filtops;
1806 kn->kn_fop = &tmpfsvnode_filtops;
1809 return (EOPNOTSUPP);
1812 kn->kn_hook = (caddr_t)vp;
1814 knote_insert(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn);
1820 filt_tmpfsdetach(struct knote *kn)
1822 struct vnode *vp = (void *)kn->kn_hook;
1824 knote_remove(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn);
1828 filt_tmpfsread(struct knote *kn, long hint)
1830 struct vnode *vp = (void *)kn->kn_hook;
1831 struct tmpfs_node *node = VP_TO_TMPFS_NODE(vp);
1834 if (hint == NOTE_REVOKE) {
1835 kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT);
1840 * Interlock against MP races when performing this function.
1842 lwkt_gettoken(&vp->v_mount->mnt_token);
1843 off = node->tn_size - kn->kn_fp->f_offset;
1844 kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX;
1845 if (kn->kn_sfflags & NOTE_OLDAPI) {
1846 lwkt_reltoken(&vp->v_mount->mnt_token);
1850 if (kn->kn_data == 0) {
1851 kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX;
1853 lwkt_reltoken(&vp->v_mount->mnt_token);
1854 return (kn->kn_data != 0);
1858 filt_tmpfswrite(struct knote *kn, long hint)
1860 if (hint == NOTE_REVOKE)
1861 kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT);
1867 filt_tmpfsvnode(struct knote *kn, long hint)
1869 if (kn->kn_sfflags & hint)
1870 kn->kn_fflags |= hint;
1871 if (hint == NOTE_REVOKE) {
1872 kn->kn_flags |= (EV_EOF | EV_NODATA);
1875 return (kn->kn_fflags != 0);
1879 /* --------------------------------------------------------------------- */
1882 * vnode operations vector used for files stored in a tmpfs file system.
1884 struct vop_ops tmpfs_vnode_vops = {
1885 .vop_default = vop_defaultop,
1886 .vop_getpages = vop_stdgetpages,
1887 .vop_putpages = vop_stdputpages,
1888 .vop_ncreate = tmpfs_ncreate,
1889 .vop_nresolve = tmpfs_nresolve,
1890 .vop_nlookupdotdot = tmpfs_nlookupdotdot,
1891 .vop_nmknod = tmpfs_nmknod,
1892 .vop_open = tmpfs_open,
1893 .vop_close = tmpfs_close,
1894 .vop_access = tmpfs_access,
1895 .vop_getattr = tmpfs_getattr,
1896 .vop_setattr = tmpfs_setattr,
1897 .vop_read = tmpfs_read,
1898 .vop_write = tmpfs_write,
1899 .vop_fsync = tmpfs_fsync,
1900 .vop_nremove = tmpfs_nremove,
1901 .vop_nlink = tmpfs_nlink,
1902 .vop_nrename = tmpfs_nrename,
1903 .vop_nmkdir = tmpfs_nmkdir,
1904 .vop_nrmdir = tmpfs_nrmdir,
1905 .vop_nsymlink = tmpfs_nsymlink,
1906 .vop_readdir = tmpfs_readdir,
1907 .vop_readlink = tmpfs_readlink,
1908 .vop_inactive = tmpfs_inactive,
1909 .vop_reclaim = tmpfs_reclaim,
1910 .vop_print = tmpfs_print,
1911 .vop_pathconf = tmpfs_pathconf,
1912 .vop_bmap = tmpfs_bmap,
1913 .vop_strategy = tmpfs_strategy,
1914 .vop_advlock = tmpfs_advlock,
1915 .vop_kqfilter = tmpfs_kqfilter
1917 /* $NetBSD: tmpfs_fifoops.c,v 1.5 2005/12/11 12:24:29 christos Exp $ */
1920 * Copyright (c) 2005 The NetBSD Foundation, Inc.
1921 * All rights reserved.
1923 * This code is derived from software contributed to The NetBSD Foundation
1924 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
1927 * Redistribution and use in source and binary forms, with or without
1928 * modification, are permitted provided that the following conditions
1930 * 1. Redistributions of source code must retain the above copyright
1931 * notice, this list of conditions and the following disclaimer.
1932 * 2. Redistributions in binary form must reproduce the above copyright
1933 * notice, this list of conditions and the following disclaimer in the
1934 * documentation and/or other materials provided with the distribution.
1936 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1937 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1938 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1939 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1940 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1941 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1942 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1943 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1944 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1945 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1946 * POSSIBILITY OF SUCH DAMAGE.
1950 * tmpfs vnode interface for named pipes.
1953 #include <sys/kernel.h>
1954 #include <sys/param.h>
1955 #include <sys/filedesc.h>
1956 #include <sys/proc.h>
1957 #include <sys/vnode.h>
1960 #include <vm/vm_object.h>
1962 #include <vfs/fifofs/fifo.h>
1963 #include "hammer2.h"
1965 /* --------------------------------------------------------------------- */
1968 tmpfs_fifo_kqfilter(struct vop_kqfilter_args *ap)
1971 struct tmpfs_node *node;
1974 node = VP_TO_TMPFS_NODE(vp);
1976 switch (ap->a_kn->kn_filter){
1978 node->tn_status |= TMPFS_NODE_ACCESSED;
1981 node->tn_status |= TMPFS_NODE_MODIFIED;
1985 return fifo_vnode_vops.vop_kqfilter(ap);
1988 /* --------------------------------------------------------------------- */
1991 tmpfs_fifo_close(struct vop_close_args *v)
1993 struct tmpfs_node *node;
1994 node = VP_TO_TMPFS_NODE(v->a_vp);
1995 node->tn_status |= TMPFS_NODE_ACCESSED;
1997 tmpfs_update(v->a_vp);
1998 return fifo_vnode_vops.vop_close(v);
2002 * vnode operations vector used for fifos stored in a tmpfs file system.
2004 struct vop_ops tmpfs_fifo_vops = {
2005 .vop_default = fifo_vnoperate,
2006 .vop_close = tmpfs_fifo_close,
2007 .vop_reclaim = tmpfs_reclaim,
2008 .vop_access = tmpfs_access,
2009 .vop_getattr = tmpfs_getattr,
2010 .vop_setattr = tmpfs_setattr,
2011 .vop_kqfilter = tmpfs_fifo_kqfilter,