xref: /dflybsd-src/sys/vfs/tmpfs/tmpfs_fifoops.c (revision ba25006aff79f1bc0cbde07db4c22c42143a65e1)
17a2de9a4SMatthew Dillon /*	$NetBSD: tmpfs_fifoops.c,v 1.5 2005/12/11 12:24:29 christos Exp $	*/
27a2de9a4SMatthew Dillon 
37a2de9a4SMatthew Dillon /*-
47a2de9a4SMatthew Dillon  * Copyright (c) 2005 The NetBSD Foundation, Inc.
57a2de9a4SMatthew Dillon  * All rights reserved.
67a2de9a4SMatthew Dillon  *
77a2de9a4SMatthew Dillon  * This code is derived from software contributed to The NetBSD Foundation
87a2de9a4SMatthew Dillon  * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
97a2de9a4SMatthew Dillon  * 2005 program.
107a2de9a4SMatthew Dillon  *
117a2de9a4SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
127a2de9a4SMatthew Dillon  * modification, are permitted provided that the following conditions
137a2de9a4SMatthew Dillon  * are met:
147a2de9a4SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
157a2de9a4SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
167a2de9a4SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
177a2de9a4SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
187a2de9a4SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
197a2de9a4SMatthew Dillon  *
207a2de9a4SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
217a2de9a4SMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
227a2de9a4SMatthew Dillon  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
237a2de9a4SMatthew Dillon  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
247a2de9a4SMatthew Dillon  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
257a2de9a4SMatthew Dillon  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
267a2de9a4SMatthew Dillon  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
277a2de9a4SMatthew Dillon  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
287a2de9a4SMatthew Dillon  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
297a2de9a4SMatthew Dillon  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
307a2de9a4SMatthew Dillon  * POSSIBILITY OF SUCH DAMAGE.
317a2de9a4SMatthew Dillon  */
327a2de9a4SMatthew Dillon 
337a2de9a4SMatthew Dillon /*
347a2de9a4SMatthew Dillon  * tmpfs vnode interface for named pipes.
357a2de9a4SMatthew Dillon  */
367a2de9a4SMatthew Dillon 
377a2de9a4SMatthew Dillon #include <sys/kernel.h>
387a2de9a4SMatthew Dillon #include <sys/param.h>
397a2de9a4SMatthew Dillon #include <sys/filedesc.h>
407a2de9a4SMatthew Dillon #include <sys/proc.h>
417a2de9a4SMatthew Dillon #include <sys/vnode.h>
427a2de9a4SMatthew Dillon 
437a2de9a4SMatthew Dillon #include <vm/vm.h>
447a2de9a4SMatthew Dillon #include <vm/vm_object.h>
457a2de9a4SMatthew Dillon 
467a2de9a4SMatthew Dillon #include <vfs/fifofs/fifo.h>
477a2de9a4SMatthew Dillon #include <vfs/tmpfs/tmpfs.h>
487a2de9a4SMatthew Dillon #include <vfs/tmpfs/tmpfs_vnops.h>
497a2de9a4SMatthew Dillon 
507a2de9a4SMatthew Dillon /* --------------------------------------------------------------------- */
517a2de9a4SMatthew Dillon 
527a2de9a4SMatthew Dillon static int
tmpfs_fifo_kqfilter(struct vop_kqfilter_args * ap)537a2de9a4SMatthew Dillon tmpfs_fifo_kqfilter(struct vop_kqfilter_args *ap)
547a2de9a4SMatthew Dillon {
557a2de9a4SMatthew Dillon 	struct vnode *vp;
567a2de9a4SMatthew Dillon 	struct tmpfs_node *node;
577a2de9a4SMatthew Dillon 
587a2de9a4SMatthew Dillon 	vp = ap->a_vp;
597a2de9a4SMatthew Dillon 	node = VP_TO_TMPFS_NODE(vp);
607a2de9a4SMatthew Dillon 
617a2de9a4SMatthew Dillon 	switch (ap->a_kn->kn_filter){
627a2de9a4SMatthew Dillon 	case EVFILT_READ:
637a2de9a4SMatthew Dillon 		node->tn_status |= TMPFS_NODE_ACCESSED;
647a2de9a4SMatthew Dillon 		break;
657a2de9a4SMatthew Dillon 	case EVFILT_WRITE:
667a2de9a4SMatthew Dillon 		node->tn_status |= TMPFS_NODE_MODIFIED;
677a2de9a4SMatthew Dillon 		break;
687a2de9a4SMatthew Dillon 	}
697a2de9a4SMatthew Dillon 
707a2de9a4SMatthew Dillon 	return fifo_vnode_vops.vop_kqfilter(ap);
717a2de9a4SMatthew Dillon }
727a2de9a4SMatthew Dillon 
737a2de9a4SMatthew Dillon /* --------------------------------------------------------------------- */
747a2de9a4SMatthew Dillon 
757a2de9a4SMatthew Dillon static int
tmpfs_fifo_close(struct vop_close_args * ap)76*ba25006aSSascha Wildner tmpfs_fifo_close(struct vop_close_args *ap)
777a2de9a4SMatthew Dillon {
787a2de9a4SMatthew Dillon 	struct tmpfs_node *node;
79*ba25006aSSascha Wildner 	node = VP_TO_TMPFS_NODE(ap->a_vp);
807a2de9a4SMatthew Dillon 	node->tn_status |= TMPFS_NODE_ACCESSED;
817a2de9a4SMatthew Dillon 
82*ba25006aSSascha Wildner 	tmpfs_update(ap->a_vp);
83*ba25006aSSascha Wildner 	return fifo_vnode_vops.vop_close(ap);
847a2de9a4SMatthew Dillon }
857a2de9a4SMatthew Dillon 
867a2de9a4SMatthew Dillon /*
877a2de9a4SMatthew Dillon  * vnode operations vector used for fifos stored in a tmpfs file system.
887a2de9a4SMatthew Dillon  */
897a2de9a4SMatthew Dillon struct vop_ops tmpfs_fifo_vops = {
907a2de9a4SMatthew Dillon 	.vop_default =			fifo_vnoperate,
917a2de9a4SMatthew Dillon 	.vop_close =			tmpfs_fifo_close,
927a2de9a4SMatthew Dillon 	.vop_reclaim =			tmpfs_reclaim,
937a2de9a4SMatthew Dillon 	.vop_access =			tmpfs_access,
947a2de9a4SMatthew Dillon 	.vop_getattr =			tmpfs_getattr,
957a2de9a4SMatthew Dillon 	.vop_setattr =			tmpfs_setattr,
967a2de9a4SMatthew Dillon 	.vop_kqfilter =			tmpfs_fifo_kqfilter,
977a2de9a4SMatthew Dillon };
98