Home | History | Annotate | Line # | Download | only in fifofs
fifo_vnops.c revision 1.26
      1  1.26    kleink /*	$NetBSD: fifo_vnops.c,v 1.26 1998/08/03 14:19:59 kleink Exp $	*/
      2   1.9       cgd 
      3   1.1       cgd /*
      4  1.25      fvdl  * Copyright (c) 1990, 1993, 1995
      5   1.8   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  *
     35  1.25      fvdl  *	@(#)fifo_vnops.c	8.10 (Berkeley) 5/27/95
     36   1.1       cgd  */
     37   1.1       cgd 
     38   1.6   mycroft #include <sys/param.h>
     39  1.25      fvdl #include <sys/systm.h>
     40   1.8   mycroft #include <sys/proc.h>
     41   1.6   mycroft #include <sys/time.h>
     42   1.6   mycroft #include <sys/namei.h>
     43   1.6   mycroft #include <sys/vnode.h>
     44   1.6   mycroft #include <sys/socket.h>
     45   1.6   mycroft #include <sys/socketvar.h>
     46   1.6   mycroft #include <sys/stat.h>
     47   1.6   mycroft #include <sys/ioctl.h>
     48   1.6   mycroft #include <sys/file.h>
     49   1.6   mycroft #include <sys/errno.h>
     50   1.6   mycroft #include <sys/malloc.h>
     51  1.17  christos #include <sys/un.h>
     52  1.20   mycroft #include <sys/poll.h>
     53  1.19   mycroft 
     54   1.6   mycroft #include <miscfs/fifofs/fifo.h>
     55  1.19   mycroft #include <miscfs/genfs/genfs.h>
     56   1.1       cgd 
     57   1.1       cgd /*
     58   1.1       cgd  * This structure is associated with the FIFO vnode and stores
     59   1.1       cgd  * the state associated with the FIFO.
     60   1.1       cgd  */
     61   1.1       cgd struct fifoinfo {
     62   1.1       cgd 	struct socket	*fi_readsock;
     63   1.1       cgd 	struct socket	*fi_writesock;
     64   1.1       cgd 	long		fi_readers;
     65   1.1       cgd 	long		fi_writers;
     66   1.1       cgd };
     67   1.1       cgd 
     68  1.17  christos int (**fifo_vnodeop_p) __P((void *));
     69   1.8   mycroft struct vnodeopv_entry_desc fifo_vnodeop_entries[] = {
     70   1.8   mycroft 	{ &vop_default_desc, vn_default_error },
     71   1.8   mycroft 	{ &vop_lookup_desc, fifo_lookup },		/* lookup */
     72   1.8   mycroft 	{ &vop_create_desc, fifo_create },		/* create */
     73   1.8   mycroft 	{ &vop_mknod_desc, fifo_mknod },		/* mknod */
     74   1.8   mycroft 	{ &vop_open_desc, fifo_open },			/* open */
     75   1.8   mycroft 	{ &vop_close_desc, fifo_close },		/* close */
     76   1.8   mycroft 	{ &vop_access_desc, fifo_access },		/* access */
     77   1.8   mycroft 	{ &vop_getattr_desc, fifo_getattr },		/* getattr */
     78   1.8   mycroft 	{ &vop_setattr_desc, fifo_setattr },		/* setattr */
     79   1.8   mycroft 	{ &vop_read_desc, fifo_read },			/* read */
     80   1.8   mycroft 	{ &vop_write_desc, fifo_write },		/* write */
     81  1.13   mycroft 	{ &vop_lease_desc, fifo_lease_check },		/* lease */
     82   1.8   mycroft 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
     83  1.20   mycroft 	{ &vop_poll_desc, fifo_poll },			/* poll */
     84  1.25      fvdl 	{ &vop_revoke_desc, fifo_revoke },		/* revoke */
     85   1.8   mycroft 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
     86   1.8   mycroft 	{ &vop_fsync_desc, fifo_fsync },		/* fsync */
     87   1.8   mycroft 	{ &vop_seek_desc, fifo_seek },			/* seek */
     88   1.8   mycroft 	{ &vop_remove_desc, fifo_remove },		/* remove */
     89   1.8   mycroft 	{ &vop_link_desc, fifo_link },			/* link */
     90   1.8   mycroft 	{ &vop_rename_desc, fifo_rename },		/* rename */
     91   1.8   mycroft 	{ &vop_mkdir_desc, fifo_mkdir },		/* mkdir */
     92   1.8   mycroft 	{ &vop_rmdir_desc, fifo_rmdir },		/* rmdir */
     93   1.8   mycroft 	{ &vop_symlink_desc, fifo_symlink },		/* symlink */
     94   1.8   mycroft 	{ &vop_readdir_desc, fifo_readdir },		/* readdir */
     95   1.8   mycroft 	{ &vop_readlink_desc, fifo_readlink },		/* readlink */
     96   1.8   mycroft 	{ &vop_abortop_desc, fifo_abortop },		/* abortop */
     97   1.8   mycroft 	{ &vop_inactive_desc, fifo_inactive },		/* inactive */
     98   1.8   mycroft 	{ &vop_reclaim_desc, fifo_reclaim },		/* reclaim */
     99   1.8   mycroft 	{ &vop_lock_desc, fifo_lock },			/* lock */
    100   1.8   mycroft 	{ &vop_unlock_desc, fifo_unlock },		/* unlock */
    101   1.8   mycroft 	{ &vop_bmap_desc, fifo_bmap },			/* bmap */
    102   1.8   mycroft 	{ &vop_strategy_desc, fifo_strategy },		/* strategy */
    103   1.8   mycroft 	{ &vop_print_desc, fifo_print },		/* print */
    104   1.8   mycroft 	{ &vop_islocked_desc, fifo_islocked },		/* islocked */
    105   1.8   mycroft 	{ &vop_pathconf_desc, fifo_pathconf },		/* pathconf */
    106   1.8   mycroft 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
    107   1.8   mycroft 	{ &vop_blkatoff_desc, fifo_blkatoff },		/* blkatoff */
    108   1.8   mycroft 	{ &vop_valloc_desc, fifo_valloc },		/* valloc */
    109   1.8   mycroft 	{ &vop_vfree_desc, fifo_vfree },		/* vfree */
    110   1.8   mycroft 	{ &vop_truncate_desc, fifo_truncate },		/* truncate */
    111   1.8   mycroft 	{ &vop_update_desc, fifo_update },		/* update */
    112   1.8   mycroft 	{ &vop_bwrite_desc, fifo_bwrite },		/* bwrite */
    113  1.17  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    114   1.1       cgd };
    115   1.8   mycroft struct vnodeopv_desc fifo_vnodeop_opv_desc =
    116   1.8   mycroft 	{ &fifo_vnodeop_p, fifo_vnodeop_entries };
    117   1.1       cgd 
    118   1.1       cgd /*
    119   1.1       cgd  * Trivial lookup routine that always fails.
    120   1.1       cgd  */
    121   1.1       cgd /* ARGSUSED */
    122  1.17  christos int
    123  1.17  christos fifo_lookup(v)
    124  1.17  christos 	void *v;
    125  1.17  christos {
    126   1.8   mycroft 	struct vop_lookup_args /* {
    127   1.8   mycroft 		struct vnode * a_dvp;
    128   1.8   mycroft 		struct vnode ** a_vpp;
    129   1.8   mycroft 		struct componentname * a_cnp;
    130  1.17  christos 	} */ *ap = v;
    131   1.8   mycroft 
    132   1.8   mycroft 	*ap->a_vpp = NULL;
    133   1.1       cgd 	return (ENOTDIR);
    134   1.1       cgd }
    135   1.1       cgd 
    136   1.1       cgd /*
    137   1.1       cgd  * Open called to set up a new instance of a fifo or
    138   1.1       cgd  * to find an active instance of a fifo.
    139   1.1       cgd  */
    140   1.1       cgd /* ARGSUSED */
    141  1.17  christos int
    142  1.17  christos fifo_open(v)
    143  1.17  christos 	void *v;
    144  1.17  christos {
    145   1.8   mycroft 	struct vop_open_args /* {
    146   1.8   mycroft 		struct vnode *a_vp;
    147   1.8   mycroft 		int  a_mode;
    148   1.8   mycroft 		struct ucred *a_cred;
    149   1.8   mycroft 		struct proc *a_p;
    150  1.17  christos 	} */ *ap = v;
    151  1.25      fvdl 	struct vnode *vp = ap->a_vp;
    152  1.25      fvdl 	struct fifoinfo *fip;
    153  1.25      fvdl 	struct proc *p = ap->a_p;
    154   1.1       cgd 	struct socket *rso, *wso;
    155   1.1       cgd 	int error;
    156  1.24   mycroft 	static const char openstr[] = "fifo";
    157   1.1       cgd 
    158   1.1       cgd 	if ((fip = vp->v_fifoinfo) == NULL) {
    159   1.1       cgd 		MALLOC(fip, struct fifoinfo *, sizeof(*fip), M_VNODE, M_WAITOK);
    160   1.1       cgd 		vp->v_fifoinfo = fip;
    161  1.17  christos 		if ((error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0)) != 0) {
    162   1.1       cgd 			free(fip, M_VNODE);
    163   1.1       cgd 			vp->v_fifoinfo = NULL;
    164   1.1       cgd 			return (error);
    165   1.1       cgd 		}
    166   1.1       cgd 		fip->fi_readsock = rso;
    167  1.17  christos 		if ((error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0)) != 0) {
    168   1.1       cgd 			(void)soclose(rso);
    169   1.1       cgd 			free(fip, M_VNODE);
    170   1.1       cgd 			vp->v_fifoinfo = NULL;
    171   1.1       cgd 			return (error);
    172   1.1       cgd 		}
    173   1.1       cgd 		fip->fi_writesock = wso;
    174  1.17  christos 		if ((error = unp_connect2(wso, rso)) != 0) {
    175   1.1       cgd 			(void)soclose(wso);
    176   1.1       cgd 			(void)soclose(rso);
    177   1.1       cgd 			free(fip, M_VNODE);
    178   1.1       cgd 			vp->v_fifoinfo = NULL;
    179   1.1       cgd 			return (error);
    180   1.1       cgd 		}
    181   1.8   mycroft 		fip->fi_readers = fip->fi_writers = 0;
    182   1.1       cgd 		wso->so_state |= SS_CANTRCVMORE;
    183   1.1       cgd 		rso->so_state |= SS_CANTSENDMORE;
    184   1.1       cgd 	}
    185   1.8   mycroft 	if (ap->a_mode & FREAD) {
    186  1.16   mycroft 		if (fip->fi_readers++ == 0) {
    187   1.1       cgd 			fip->fi_writesock->so_state &= ~SS_CANTSENDMORE;
    188   1.1       cgd 			if (fip->fi_writers > 0)
    189   1.1       cgd 				wakeup((caddr_t)&fip->fi_writers);
    190   1.1       cgd 		}
    191  1.16   mycroft 	}
    192  1.16   mycroft 	if (ap->a_mode & FWRITE) {
    193  1.16   mycroft 		if (fip->fi_writers++ == 0) {
    194  1.16   mycroft 			fip->fi_readsock->so_state &= ~SS_CANTRCVMORE;
    195  1.16   mycroft 			if (fip->fi_readers > 0)
    196  1.16   mycroft 				wakeup((caddr_t)&fip->fi_readers);
    197   1.2       cgd 		}
    198  1.16   mycroft 	}
    199  1.16   mycroft 	if (ap->a_mode & FREAD) {
    200  1.16   mycroft 		if (ap->a_mode & O_NONBLOCK) {
    201   1.1       cgd 		} else {
    202  1.16   mycroft 			while (fip->fi_writers == 0) {
    203  1.25      fvdl 				VOP_UNLOCK(vp, 0);
    204  1.16   mycroft 				error = tsleep((caddr_t)&fip->fi_readers,
    205  1.16   mycroft 				    PCATCH | PSOCK, openstr, 0);
    206  1.25      fvdl 				vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    207  1.16   mycroft 				if (error)
    208  1.16   mycroft 					goto bad;
    209   1.1       cgd 			}
    210  1.16   mycroft 		}
    211  1.16   mycroft 	}
    212  1.16   mycroft 	if (ap->a_mode & FWRITE) {
    213  1.16   mycroft 		if (ap->a_mode & O_NONBLOCK) {
    214  1.16   mycroft 			if (fip->fi_readers == 0) {
    215  1.16   mycroft 				error = ENXIO;
    216  1.16   mycroft 				goto bad;
    217  1.16   mycroft 			}
    218  1.16   mycroft 		} else {
    219   1.2       cgd 			while (fip->fi_readers == 0) {
    220  1.25      fvdl 				VOP_UNLOCK(vp, 0);
    221   1.2       cgd 				error = tsleep((caddr_t)&fip->fi_writers,
    222   1.8   mycroft 				    PCATCH | PSOCK, openstr, 0);
    223  1.25      fvdl 				vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    224   1.8   mycroft 				if (error)
    225  1.16   mycroft 					goto bad;
    226   1.2       cgd 			}
    227   1.1       cgd 		}
    228   1.1       cgd 	}
    229  1.16   mycroft 	return (0);
    230  1.16   mycroft bad:
    231  1.25      fvdl 	VOP_CLOSE(vp, ap->a_mode, ap->a_cred, p);
    232   1.1       cgd 	return (error);
    233   1.1       cgd }
    234   1.1       cgd 
    235   1.1       cgd /*
    236   1.1       cgd  * Vnode op for read
    237   1.1       cgd  */
    238   1.1       cgd /* ARGSUSED */
    239  1.17  christos int
    240  1.17  christos fifo_read(v)
    241  1.17  christos 	void *v;
    242  1.17  christos {
    243   1.8   mycroft 	struct vop_read_args /* {
    244   1.8   mycroft 		struct vnode *a_vp;
    245   1.8   mycroft 		struct uio *a_uio;
    246   1.8   mycroft 		int  a_ioflag;
    247   1.8   mycroft 		struct ucred *a_cred;
    248  1.17  christos 	} */ *ap = v;
    249  1.25      fvdl 	struct uio *uio = ap->a_uio;
    250  1.25      fvdl 	struct socket *rso = ap->a_vp->v_fifoinfo->fi_readsock;
    251   1.1       cgd 	int error, startresid;
    252   1.1       cgd 
    253   1.1       cgd #ifdef DIAGNOSTIC
    254   1.1       cgd 	if (uio->uio_rw != UIO_READ)
    255   1.1       cgd 		panic("fifo_read mode");
    256   1.1       cgd #endif
    257   1.1       cgd 	if (uio->uio_resid == 0)
    258   1.1       cgd 		return (0);
    259   1.8   mycroft 	if (ap->a_ioflag & IO_NDELAY)
    260   1.1       cgd 		rso->so_state |= SS_NBIO;
    261   1.1       cgd 	startresid = uio->uio_resid;
    262  1.25      fvdl 	VOP_UNLOCK(ap->a_vp, 0);
    263  1.13   mycroft 	error = soreceive(rso, (struct mbuf **)0, uio, (struct mbuf **)0,
    264  1.13   mycroft 	    (struct mbuf **)0, (int *)0);
    265  1.25      fvdl 	vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
    266   1.1       cgd 	/*
    267   1.1       cgd 	 * Clear EOF indication after first such return.
    268   1.1       cgd 	 */
    269   1.1       cgd 	if (uio->uio_resid == startresid)
    270   1.1       cgd 		rso->so_state &= ~SS_CANTRCVMORE;
    271  1.23    kleink 	if (ap->a_ioflag & IO_NDELAY) {
    272   1.1       cgd 		rso->so_state &= ~SS_NBIO;
    273  1.23    kleink 		if (error == EWOULDBLOCK &&
    274  1.23    kleink 		    ap->a_vp->v_fifoinfo->fi_writers == 0)
    275  1.23    kleink 			error = 0;
    276  1.23    kleink 	}
    277   1.1       cgd 	return (error);
    278   1.1       cgd }
    279   1.1       cgd 
    280   1.1       cgd /*
    281   1.1       cgd  * Vnode op for write
    282   1.1       cgd  */
    283   1.1       cgd /* ARGSUSED */
    284  1.17  christos int
    285  1.17  christos fifo_write(v)
    286  1.17  christos 	void *v;
    287  1.17  christos {
    288   1.8   mycroft 	struct vop_write_args /* {
    289   1.8   mycroft 		struct vnode *a_vp;
    290   1.8   mycroft 		struct uio *a_uio;
    291   1.8   mycroft 		int  a_ioflag;
    292   1.8   mycroft 		struct ucred *a_cred;
    293  1.17  christos 	} */ *ap = v;
    294   1.8   mycroft 	struct socket *wso = ap->a_vp->v_fifoinfo->fi_writesock;
    295   1.1       cgd 	int error;
    296   1.1       cgd 
    297   1.1       cgd #ifdef DIAGNOSTIC
    298   1.8   mycroft 	if (ap->a_uio->uio_rw != UIO_WRITE)
    299   1.1       cgd 		panic("fifo_write mode");
    300   1.1       cgd #endif
    301   1.8   mycroft 	if (ap->a_ioflag & IO_NDELAY)
    302   1.1       cgd 		wso->so_state |= SS_NBIO;
    303  1.25      fvdl 	VOP_UNLOCK(ap->a_vp, 0);
    304   1.8   mycroft 	error = sosend(wso, (struct mbuf *)0, ap->a_uio, 0, (struct mbuf *)0, 0);
    305  1.25      fvdl 	vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
    306   1.8   mycroft 	if (ap->a_ioflag & IO_NDELAY)
    307   1.1       cgd 		wso->so_state &= ~SS_NBIO;
    308   1.1       cgd 	return (error);
    309   1.1       cgd }
    310   1.1       cgd 
    311   1.1       cgd /*
    312   1.1       cgd  * Device ioctl operation.
    313   1.1       cgd  */
    314   1.1       cgd /* ARGSUSED */
    315  1.17  christos int
    316  1.17  christos fifo_ioctl(v)
    317  1.17  christos 	void *v;
    318  1.17  christos {
    319   1.8   mycroft 	struct vop_ioctl_args /* {
    320   1.8   mycroft 		struct vnode *a_vp;
    321  1.11       cgd 		u_long a_command;
    322   1.8   mycroft 		caddr_t  a_data;
    323   1.8   mycroft 		int  a_fflag;
    324   1.8   mycroft 		struct ucred *a_cred;
    325   1.8   mycroft 		struct proc *a_p;
    326  1.17  christos 	} */ *ap = v;
    327   1.1       cgd 	struct file filetmp;
    328  1.16   mycroft 	int error;
    329   1.1       cgd 
    330   1.8   mycroft 	if (ap->a_command == FIONBIO)
    331   1.1       cgd 		return (0);
    332  1.16   mycroft 	if (ap->a_fflag & FREAD) {
    333   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
    334  1.16   mycroft 		error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_p);
    335  1.16   mycroft 		if (error)
    336  1.16   mycroft 			return (error);
    337  1.16   mycroft 	}
    338  1.16   mycroft 	if (ap->a_fflag & FWRITE) {
    339   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;
    340  1.16   mycroft 		error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_p);
    341  1.16   mycroft 		if (error)
    342  1.16   mycroft 			return (error);
    343  1.16   mycroft 	}
    344  1.16   mycroft 	return (0);
    345   1.1       cgd }
    346   1.1       cgd 
    347   1.1       cgd /* ARGSUSED */
    348  1.17  christos int
    349  1.20   mycroft fifo_poll(v)
    350  1.17  christos 	void *v;
    351  1.17  christos {
    352  1.20   mycroft 	struct vop_poll_args /* {
    353   1.8   mycroft 		struct vnode *a_vp;
    354  1.20   mycroft 		int a_events;
    355   1.8   mycroft 		struct proc *a_p;
    356  1.17  christos 	} */ *ap = v;
    357   1.1       cgd 	struct file filetmp;
    358  1.20   mycroft 	int revents = 0;
    359   1.1       cgd 
    360  1.20   mycroft 	if (ap->a_events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) {
    361   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
    362  1.20   mycroft 		if (filetmp.f_data)
    363  1.20   mycroft 			revents |= soo_poll(&filetmp, ap->a_events, ap->a_p);
    364  1.16   mycroft 	}
    365  1.20   mycroft 	if (ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND)) {
    366   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;
    367  1.20   mycroft 		if (filetmp.f_data)
    368  1.20   mycroft 			revents |= soo_poll(&filetmp, ap->a_events, ap->a_p);
    369  1.16   mycroft 	}
    370  1.20   mycroft 
    371  1.20   mycroft 	return (revents);
    372   1.1       cgd }
    373   1.1       cgd 
    374  1.25      fvdl int
    375  1.25      fvdl fifo_inactive(v)
    376  1.25      fvdl 	void *v;
    377  1.25      fvdl {
    378  1.25      fvdl 	struct vop_inactive_args /* {
    379  1.25      fvdl 		struct vnode *a_vp;
    380  1.25      fvdl 		struct proc *a_p;
    381  1.25      fvdl 	} */ *ap = v;
    382  1.25      fvdl 
    383  1.25      fvdl 	VOP_UNLOCK(ap->a_vp, 0);
    384  1.25      fvdl 	return (0);
    385  1.25      fvdl }
    386  1.25      fvdl 
    387   1.1       cgd /*
    388   1.1       cgd  * This is a noop, simply returning what one has been given.
    389   1.1       cgd  */
    390  1.17  christos int
    391  1.17  christos fifo_bmap(v)
    392  1.17  christos 	void *v;
    393  1.17  christos {
    394   1.8   mycroft 	struct vop_bmap_args /* {
    395   1.8   mycroft 		struct vnode *a_vp;
    396   1.8   mycroft 		daddr_t  a_bn;
    397   1.8   mycroft 		struct vnode **a_vpp;
    398   1.8   mycroft 		daddr_t *a_bnp;
    399  1.25      fvdl 		int *a_runp;
    400  1.17  christos 	} */ *ap = v;
    401   1.1       cgd 
    402   1.8   mycroft 	if (ap->a_vpp != NULL)
    403   1.8   mycroft 		*ap->a_vpp = ap->a_vp;
    404   1.8   mycroft 	if (ap->a_bnp != NULL)
    405   1.8   mycroft 		*ap->a_bnp = ap->a_bn;
    406  1.25      fvdl 	if (ap->a_runp != NULL)
    407  1.25      fvdl 		*ap->a_runp = 0;
    408   1.1       cgd 	return (0);
    409   1.1       cgd }
    410   1.1       cgd 
    411   1.1       cgd /*
    412   1.1       cgd  * Device close routine
    413   1.1       cgd  */
    414   1.1       cgd /* ARGSUSED */
    415  1.17  christos int
    416  1.17  christos fifo_close(v)
    417  1.17  christos 	void *v;
    418  1.17  christos {
    419   1.8   mycroft 	struct vop_close_args /* {
    420   1.8   mycroft 		struct vnode *a_vp;
    421   1.8   mycroft 		int  a_fflag;
    422   1.8   mycroft 		struct ucred *a_cred;
    423   1.8   mycroft 		struct proc *a_p;
    424  1.17  christos 	} */ *ap = v;
    425   1.8   mycroft 	register struct vnode *vp = ap->a_vp;
    426   1.1       cgd 	register struct fifoinfo *fip = vp->v_fifoinfo;
    427   1.1       cgd 	int error1, error2;
    428   1.1       cgd 
    429  1.16   mycroft 	if (ap->a_fflag & FREAD) {
    430  1.16   mycroft 		if (--fip->fi_readers == 0)
    431  1.16   mycroft 			socantsendmore(fip->fi_writesock);
    432  1.16   mycroft 	}
    433   1.8   mycroft 	if (ap->a_fflag & FWRITE) {
    434  1.16   mycroft 		if (--fip->fi_writers == 0)
    435   1.1       cgd 			socantrcvmore(fip->fi_readsock);
    436   1.1       cgd 	}
    437   1.1       cgd 	if (vp->v_usecount > 1)
    438   1.1       cgd 		return (0);
    439   1.1       cgd 	error1 = soclose(fip->fi_readsock);
    440   1.1       cgd 	error2 = soclose(fip->fi_writesock);
    441   1.1       cgd 	FREE(fip, M_VNODE);
    442   1.1       cgd 	vp->v_fifoinfo = NULL;
    443   1.1       cgd 	if (error1)
    444   1.1       cgd 		return (error1);
    445   1.1       cgd 	return (error2);
    446   1.1       cgd }
    447   1.1       cgd 
    448   1.1       cgd /*
    449   1.1       cgd  * Print out the contents of a fifo vnode.
    450   1.1       cgd  */
    451  1.17  christos int
    452  1.17  christos fifo_print(v)
    453  1.17  christos 	void *v;
    454  1.17  christos {
    455   1.8   mycroft 	struct vop_print_args /* {
    456   1.8   mycroft 		struct vnode *a_vp;
    457  1.17  christos 	} */ *ap = v;
    458   1.1       cgd 
    459  1.22  christos 	printf("tag VT_NON");
    460   1.8   mycroft 	fifo_printinfo(ap->a_vp);
    461  1.22  christos 	printf("\n");
    462  1.17  christos 	return 0;
    463   1.1       cgd }
    464   1.1       cgd 
    465   1.1       cgd /*
    466   1.1       cgd  * Print out internal contents of a fifo vnode.
    467   1.1       cgd  */
    468  1.17  christos void
    469   1.1       cgd fifo_printinfo(vp)
    470   1.1       cgd 	struct vnode *vp;
    471   1.1       cgd {
    472   1.1       cgd 	register struct fifoinfo *fip = vp->v_fifoinfo;
    473   1.1       cgd 
    474  1.22  christos 	printf(", fifo with %ld readers and %ld writers",
    475  1.21  christos 	    fip->fi_readers, fip->fi_writers);
    476   1.1       cgd }
    477   1.1       cgd 
    478   1.1       cgd /*
    479   1.8   mycroft  * Return POSIX pathconf information applicable to fifo's.
    480   1.8   mycroft  */
    481  1.17  christos int
    482  1.17  christos fifo_pathconf(v)
    483  1.17  christos 	void *v;
    484  1.17  christos {
    485   1.8   mycroft 	struct vop_pathconf_args /* {
    486   1.8   mycroft 		struct vnode *a_vp;
    487   1.8   mycroft 		int a_name;
    488  1.10       cgd 		register_t *a_retval;
    489  1.17  christos 	} */ *ap = v;
    490   1.8   mycroft 
    491   1.8   mycroft 	switch (ap->a_name) {
    492   1.8   mycroft 	case _PC_LINK_MAX:
    493   1.8   mycroft 		*ap->a_retval = LINK_MAX;
    494   1.8   mycroft 		return (0);
    495   1.8   mycroft 	case _PC_PIPE_BUF:
    496   1.8   mycroft 		*ap->a_retval = PIPE_BUF;
    497   1.8   mycroft 		return (0);
    498   1.8   mycroft 	case _PC_CHOWN_RESTRICTED:
    499  1.26    kleink 		*ap->a_retval = 1;
    500  1.26    kleink 		return (0);
    501  1.26    kleink 	case _PC_SYNC_IO:
    502   1.8   mycroft 		*ap->a_retval = 1;
    503   1.8   mycroft 		return (0);
    504   1.8   mycroft 	default:
    505   1.8   mycroft 		return (EINVAL);
    506   1.8   mycroft 	}
    507   1.1       cgd 	/* NOTREACHED */
    508   1.1       cgd }
    509