Home | History | Annotate | Line # | Download | only in fifofs
fifo_vnops.c revision 1.17
      1  1.17  christos /*	$NetBSD: fifo_vnops.c,v 1.17 1996/02/09 22:40:16 christos Exp $	*/
      2   1.9       cgd 
      3   1.1       cgd /*
      4   1.8   mycroft  * Copyright (c) 1990, 1993
      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.13   mycroft  *	@(#)fifo_vnops.c	8.4 (Berkeley) 8/10/94
     36   1.1       cgd  */
     37   1.1       cgd 
     38   1.6   mycroft #include <sys/param.h>
     39   1.8   mycroft #include <sys/proc.h>
     40   1.6   mycroft #include <sys/time.h>
     41   1.6   mycroft #include <sys/namei.h>
     42   1.6   mycroft #include <sys/vnode.h>
     43   1.6   mycroft #include <sys/socket.h>
     44   1.6   mycroft #include <sys/socketvar.h>
     45   1.6   mycroft #include <sys/stat.h>
     46   1.6   mycroft #include <sys/systm.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.6   mycroft #include <miscfs/fifofs/fifo.h>
     53   1.1       cgd 
     54   1.1       cgd /*
     55   1.1       cgd  * This structure is associated with the FIFO vnode and stores
     56   1.1       cgd  * the state associated with the FIFO.
     57   1.1       cgd  */
     58   1.1       cgd struct fifoinfo {
     59   1.1       cgd 	struct socket	*fi_readsock;
     60   1.1       cgd 	struct socket	*fi_writesock;
     61   1.1       cgd 	long		fi_readers;
     62   1.1       cgd 	long		fi_writers;
     63   1.1       cgd };
     64   1.1       cgd 
     65  1.17  christos int (**fifo_vnodeop_p) __P((void *));
     66   1.8   mycroft struct vnodeopv_entry_desc fifo_vnodeop_entries[] = {
     67   1.8   mycroft 	{ &vop_default_desc, vn_default_error },
     68   1.8   mycroft 	{ &vop_lookup_desc, fifo_lookup },		/* lookup */
     69   1.8   mycroft 	{ &vop_create_desc, fifo_create },		/* create */
     70   1.8   mycroft 	{ &vop_mknod_desc, fifo_mknod },		/* mknod */
     71   1.8   mycroft 	{ &vop_open_desc, fifo_open },			/* open */
     72   1.8   mycroft 	{ &vop_close_desc, fifo_close },		/* close */
     73   1.8   mycroft 	{ &vop_access_desc, fifo_access },		/* access */
     74   1.8   mycroft 	{ &vop_getattr_desc, fifo_getattr },		/* getattr */
     75   1.8   mycroft 	{ &vop_setattr_desc, fifo_setattr },		/* setattr */
     76   1.8   mycroft 	{ &vop_read_desc, fifo_read },			/* read */
     77   1.8   mycroft 	{ &vop_write_desc, fifo_write },		/* write */
     78  1.13   mycroft 	{ &vop_lease_desc, fifo_lease_check },		/* lease */
     79   1.8   mycroft 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
     80   1.8   mycroft 	{ &vop_select_desc, fifo_select },		/* select */
     81   1.8   mycroft 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
     82   1.8   mycroft 	{ &vop_fsync_desc, fifo_fsync },		/* fsync */
     83   1.8   mycroft 	{ &vop_seek_desc, fifo_seek },			/* seek */
     84   1.8   mycroft 	{ &vop_remove_desc, fifo_remove },		/* remove */
     85   1.8   mycroft 	{ &vop_link_desc, fifo_link },			/* link */
     86   1.8   mycroft 	{ &vop_rename_desc, fifo_rename },		/* rename */
     87   1.8   mycroft 	{ &vop_mkdir_desc, fifo_mkdir },		/* mkdir */
     88   1.8   mycroft 	{ &vop_rmdir_desc, fifo_rmdir },		/* rmdir */
     89   1.8   mycroft 	{ &vop_symlink_desc, fifo_symlink },		/* symlink */
     90   1.8   mycroft 	{ &vop_readdir_desc, fifo_readdir },		/* readdir */
     91   1.8   mycroft 	{ &vop_readlink_desc, fifo_readlink },		/* readlink */
     92   1.8   mycroft 	{ &vop_abortop_desc, fifo_abortop },		/* abortop */
     93   1.8   mycroft 	{ &vop_inactive_desc, fifo_inactive },		/* inactive */
     94   1.8   mycroft 	{ &vop_reclaim_desc, fifo_reclaim },		/* reclaim */
     95   1.8   mycroft 	{ &vop_lock_desc, fifo_lock },			/* lock */
     96   1.8   mycroft 	{ &vop_unlock_desc, fifo_unlock },		/* unlock */
     97   1.8   mycroft 	{ &vop_bmap_desc, fifo_bmap },			/* bmap */
     98   1.8   mycroft 	{ &vop_strategy_desc, fifo_strategy },		/* strategy */
     99   1.8   mycroft 	{ &vop_print_desc, fifo_print },		/* print */
    100   1.8   mycroft 	{ &vop_islocked_desc, fifo_islocked },		/* islocked */
    101   1.8   mycroft 	{ &vop_pathconf_desc, fifo_pathconf },		/* pathconf */
    102   1.8   mycroft 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
    103   1.8   mycroft 	{ &vop_blkatoff_desc, fifo_blkatoff },		/* blkatoff */
    104   1.8   mycroft 	{ &vop_valloc_desc, fifo_valloc },		/* valloc */
    105   1.8   mycroft 	{ &vop_vfree_desc, fifo_vfree },		/* vfree */
    106   1.8   mycroft 	{ &vop_truncate_desc, fifo_truncate },		/* truncate */
    107   1.8   mycroft 	{ &vop_update_desc, fifo_update },		/* update */
    108   1.8   mycroft 	{ &vop_bwrite_desc, fifo_bwrite },		/* bwrite */
    109  1.17  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    110   1.1       cgd };
    111   1.8   mycroft struct vnodeopv_desc fifo_vnodeop_opv_desc =
    112   1.8   mycroft 	{ &fifo_vnodeop_p, fifo_vnodeop_entries };
    113   1.1       cgd 
    114   1.1       cgd /*
    115   1.1       cgd  * Trivial lookup routine that always fails.
    116   1.1       cgd  */
    117   1.1       cgd /* ARGSUSED */
    118  1.17  christos int
    119  1.17  christos fifo_lookup(v)
    120  1.17  christos 	void *v;
    121  1.17  christos {
    122   1.8   mycroft 	struct vop_lookup_args /* {
    123   1.8   mycroft 		struct vnode * a_dvp;
    124   1.8   mycroft 		struct vnode ** a_vpp;
    125   1.8   mycroft 		struct componentname * a_cnp;
    126  1.17  christos 	} */ *ap = v;
    127   1.8   mycroft 
    128   1.8   mycroft 	*ap->a_vpp = NULL;
    129   1.1       cgd 	return (ENOTDIR);
    130   1.1       cgd }
    131   1.1       cgd 
    132   1.1       cgd /*
    133   1.1       cgd  * Open called to set up a new instance of a fifo or
    134   1.1       cgd  * to find an active instance of a fifo.
    135   1.1       cgd  */
    136   1.1       cgd /* ARGSUSED */
    137  1.17  christos int
    138  1.17  christos fifo_open(v)
    139  1.17  christos 	void *v;
    140  1.17  christos {
    141   1.8   mycroft 	struct vop_open_args /* {
    142   1.8   mycroft 		struct vnode *a_vp;
    143   1.8   mycroft 		int  a_mode;
    144   1.8   mycroft 		struct ucred *a_cred;
    145   1.8   mycroft 		struct proc *a_p;
    146  1.17  christos 	} */ *ap = v;
    147   1.8   mycroft 	register struct vnode *vp = ap->a_vp;
    148   1.1       cgd 	register struct fifoinfo *fip;
    149   1.1       cgd 	struct socket *rso, *wso;
    150   1.1       cgd 	int error;
    151   1.1       cgd 	static char openstr[] = "fifo";
    152   1.1       cgd 
    153   1.1       cgd 	if ((fip = vp->v_fifoinfo) == NULL) {
    154   1.1       cgd 		MALLOC(fip, struct fifoinfo *, sizeof(*fip), M_VNODE, M_WAITOK);
    155   1.1       cgd 		vp->v_fifoinfo = fip;
    156  1.17  christos 		if ((error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0)) != 0) {
    157   1.1       cgd 			free(fip, M_VNODE);
    158   1.1       cgd 			vp->v_fifoinfo = NULL;
    159   1.1       cgd 			return (error);
    160   1.1       cgd 		}
    161   1.1       cgd 		fip->fi_readsock = rso;
    162  1.17  christos 		if ((error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0)) != 0) {
    163   1.1       cgd 			(void)soclose(rso);
    164   1.1       cgd 			free(fip, M_VNODE);
    165   1.1       cgd 			vp->v_fifoinfo = NULL;
    166   1.1       cgd 			return (error);
    167   1.1       cgd 		}
    168   1.1       cgd 		fip->fi_writesock = wso;
    169  1.17  christos 		if ((error = unp_connect2(wso, rso)) != 0) {
    170   1.1       cgd 			(void)soclose(wso);
    171   1.1       cgd 			(void)soclose(rso);
    172   1.1       cgd 			free(fip, M_VNODE);
    173   1.1       cgd 			vp->v_fifoinfo = NULL;
    174   1.1       cgd 			return (error);
    175   1.1       cgd 		}
    176   1.8   mycroft 		fip->fi_readers = fip->fi_writers = 0;
    177   1.1       cgd 		wso->so_state |= SS_CANTRCVMORE;
    178   1.1       cgd 		rso->so_state |= SS_CANTSENDMORE;
    179   1.1       cgd 	}
    180   1.8   mycroft 	if (ap->a_mode & FREAD) {
    181  1.16   mycroft 		if (fip->fi_readers++ == 0) {
    182   1.1       cgd 			fip->fi_writesock->so_state &= ~SS_CANTSENDMORE;
    183   1.1       cgd 			if (fip->fi_writers > 0)
    184   1.1       cgd 				wakeup((caddr_t)&fip->fi_writers);
    185   1.1       cgd 		}
    186  1.16   mycroft 	}
    187  1.16   mycroft 	if (ap->a_mode & FWRITE) {
    188  1.16   mycroft 		if (fip->fi_writers++ == 0) {
    189  1.16   mycroft 			fip->fi_readsock->so_state &= ~SS_CANTRCVMORE;
    190  1.16   mycroft 			if (fip->fi_readers > 0)
    191  1.16   mycroft 				wakeup((caddr_t)&fip->fi_readers);
    192   1.2       cgd 		}
    193  1.16   mycroft 	}
    194  1.16   mycroft 	if (ap->a_mode & FREAD) {
    195  1.16   mycroft 		if (ap->a_mode & O_NONBLOCK) {
    196   1.1       cgd 		} else {
    197  1.16   mycroft 			while (fip->fi_writers == 0) {
    198  1.16   mycroft 				VOP_UNLOCK(vp);
    199  1.16   mycroft 				error = tsleep((caddr_t)&fip->fi_readers,
    200  1.16   mycroft 				    PCATCH | PSOCK, openstr, 0);
    201  1.16   mycroft 				VOP_LOCK(vp);
    202  1.16   mycroft 				if (error)
    203  1.16   mycroft 					goto bad;
    204   1.1       cgd 			}
    205  1.16   mycroft 		}
    206  1.16   mycroft 	}
    207  1.16   mycroft 	if (ap->a_mode & FWRITE) {
    208  1.16   mycroft 		if (ap->a_mode & O_NONBLOCK) {
    209  1.16   mycroft 			if (fip->fi_readers == 0) {
    210  1.16   mycroft 				error = ENXIO;
    211  1.16   mycroft 				goto bad;
    212  1.16   mycroft 			}
    213  1.16   mycroft 		} else {
    214   1.2       cgd 			while (fip->fi_readers == 0) {
    215   1.2       cgd 				VOP_UNLOCK(vp);
    216   1.2       cgd 				error = tsleep((caddr_t)&fip->fi_writers,
    217   1.8   mycroft 				    PCATCH | PSOCK, openstr, 0);
    218   1.2       cgd 				VOP_LOCK(vp);
    219   1.8   mycroft 				if (error)
    220  1.16   mycroft 					goto bad;
    221   1.2       cgd 			}
    222   1.1       cgd 		}
    223   1.1       cgd 	}
    224  1.16   mycroft 	return (0);
    225  1.16   mycroft bad:
    226  1.16   mycroft 	VOP_CLOSE(vp, ap->a_mode, ap->a_cred, ap->a_p);
    227   1.1       cgd 	return (error);
    228   1.1       cgd }
    229   1.1       cgd 
    230   1.1       cgd /*
    231   1.1       cgd  * Vnode op for read
    232   1.1       cgd  */
    233   1.1       cgd /* ARGSUSED */
    234  1.17  christos int
    235  1.17  christos fifo_read(v)
    236  1.17  christos 	void *v;
    237  1.17  christos {
    238   1.8   mycroft 	struct vop_read_args /* {
    239   1.8   mycroft 		struct vnode *a_vp;
    240   1.8   mycroft 		struct uio *a_uio;
    241   1.8   mycroft 		int  a_ioflag;
    242   1.8   mycroft 		struct ucred *a_cred;
    243  1.17  christos 	} */ *ap = v;
    244   1.8   mycroft 	register struct uio *uio = ap->a_uio;
    245   1.8   mycroft 	register struct socket *rso = ap->a_vp->v_fifoinfo->fi_readsock;
    246   1.1       cgd 	int error, startresid;
    247   1.1       cgd 
    248   1.1       cgd #ifdef DIAGNOSTIC
    249   1.1       cgd 	if (uio->uio_rw != UIO_READ)
    250   1.1       cgd 		panic("fifo_read mode");
    251   1.1       cgd #endif
    252   1.1       cgd 	if (uio->uio_resid == 0)
    253   1.1       cgd 		return (0);
    254   1.8   mycroft 	if (ap->a_ioflag & IO_NDELAY)
    255   1.1       cgd 		rso->so_state |= SS_NBIO;
    256   1.1       cgd 	startresid = uio->uio_resid;
    257   1.8   mycroft 	VOP_UNLOCK(ap->a_vp);
    258  1.13   mycroft 	error = soreceive(rso, (struct mbuf **)0, uio, (struct mbuf **)0,
    259  1.13   mycroft 	    (struct mbuf **)0, (int *)0);
    260   1.8   mycroft 	VOP_LOCK(ap->a_vp);
    261   1.1       cgd 	/*
    262   1.1       cgd 	 * Clear EOF indication after first such return.
    263   1.1       cgd 	 */
    264   1.1       cgd 	if (uio->uio_resid == startresid)
    265   1.1       cgd 		rso->so_state &= ~SS_CANTRCVMORE;
    266   1.8   mycroft 	if (ap->a_ioflag & IO_NDELAY)
    267   1.1       cgd 		rso->so_state &= ~SS_NBIO;
    268   1.1       cgd 	return (error);
    269   1.1       cgd }
    270   1.1       cgd 
    271   1.1       cgd /*
    272   1.1       cgd  * Vnode op for write
    273   1.1       cgd  */
    274   1.1       cgd /* ARGSUSED */
    275  1.17  christos int
    276  1.17  christos fifo_write(v)
    277  1.17  christos 	void *v;
    278  1.17  christos {
    279   1.8   mycroft 	struct vop_write_args /* {
    280   1.8   mycroft 		struct vnode *a_vp;
    281   1.8   mycroft 		struct uio *a_uio;
    282   1.8   mycroft 		int  a_ioflag;
    283   1.8   mycroft 		struct ucred *a_cred;
    284  1.17  christos 	} */ *ap = v;
    285   1.8   mycroft 	struct socket *wso = ap->a_vp->v_fifoinfo->fi_writesock;
    286   1.1       cgd 	int error;
    287   1.1       cgd 
    288   1.1       cgd #ifdef DIAGNOSTIC
    289   1.8   mycroft 	if (ap->a_uio->uio_rw != UIO_WRITE)
    290   1.1       cgd 		panic("fifo_write mode");
    291   1.1       cgd #endif
    292   1.8   mycroft 	if (ap->a_ioflag & IO_NDELAY)
    293   1.1       cgd 		wso->so_state |= SS_NBIO;
    294   1.8   mycroft 	VOP_UNLOCK(ap->a_vp);
    295   1.8   mycroft 	error = sosend(wso, (struct mbuf *)0, ap->a_uio, 0, (struct mbuf *)0, 0);
    296   1.8   mycroft 	VOP_LOCK(ap->a_vp);
    297   1.8   mycroft 	if (ap->a_ioflag & IO_NDELAY)
    298   1.1       cgd 		wso->so_state &= ~SS_NBIO;
    299   1.1       cgd 	return (error);
    300   1.1       cgd }
    301   1.1       cgd 
    302   1.1       cgd /*
    303   1.1       cgd  * Device ioctl operation.
    304   1.1       cgd  */
    305   1.1       cgd /* ARGSUSED */
    306  1.17  christos int
    307  1.17  christos fifo_ioctl(v)
    308  1.17  christos 	void *v;
    309  1.17  christos {
    310   1.8   mycroft 	struct vop_ioctl_args /* {
    311   1.8   mycroft 		struct vnode *a_vp;
    312  1.11       cgd 		u_long a_command;
    313   1.8   mycroft 		caddr_t  a_data;
    314   1.8   mycroft 		int  a_fflag;
    315   1.8   mycroft 		struct ucred *a_cred;
    316   1.8   mycroft 		struct proc *a_p;
    317  1.17  christos 	} */ *ap = v;
    318   1.1       cgd 	struct file filetmp;
    319  1.16   mycroft 	int error;
    320   1.1       cgd 
    321   1.8   mycroft 	if (ap->a_command == FIONBIO)
    322   1.1       cgd 		return (0);
    323  1.16   mycroft 	if (ap->a_fflag & FREAD) {
    324   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
    325  1.16   mycroft 		error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_p);
    326  1.16   mycroft 		if (error)
    327  1.16   mycroft 			return (error);
    328  1.16   mycroft 	}
    329  1.16   mycroft 	if (ap->a_fflag & FWRITE) {
    330   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;
    331  1.16   mycroft 		error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_p);
    332  1.16   mycroft 		if (error)
    333  1.16   mycroft 			return (error);
    334  1.16   mycroft 	}
    335  1.16   mycroft 	return (0);
    336   1.1       cgd }
    337   1.1       cgd 
    338   1.1       cgd /* ARGSUSED */
    339  1.17  christos int
    340  1.17  christos fifo_select(v)
    341  1.17  christos 	void *v;
    342  1.17  christos {
    343   1.8   mycroft 	struct vop_select_args /* {
    344   1.8   mycroft 		struct vnode *a_vp;
    345   1.8   mycroft 		int  a_which;
    346   1.8   mycroft 		int  a_fflags;
    347   1.8   mycroft 		struct ucred *a_cred;
    348   1.8   mycroft 		struct proc *a_p;
    349  1.17  christos 	} */ *ap = v;
    350   1.1       cgd 	struct file filetmp;
    351  1.16   mycroft 	int ready;
    352   1.1       cgd 
    353  1.16   mycroft 	if (ap->a_fflags & FREAD) {
    354   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_readsock;
    355  1.16   mycroft 		ready = soo_select(&filetmp, ap->a_which, ap->a_p);
    356  1.16   mycroft 		if (ready)
    357  1.16   mycroft 			return (ready);
    358  1.16   mycroft 	}
    359  1.16   mycroft 	if (ap->a_fflags & FWRITE) {
    360   1.8   mycroft 		filetmp.f_data = (caddr_t)ap->a_vp->v_fifoinfo->fi_writesock;
    361  1.16   mycroft 		ready = soo_select(&filetmp, ap->a_which, ap->a_p);
    362  1.16   mycroft 		if (ready)
    363  1.16   mycroft 			return (ready);
    364  1.16   mycroft 	}
    365  1.16   mycroft 	return (0);
    366   1.1       cgd }
    367   1.1       cgd 
    368   1.1       cgd /*
    369   1.1       cgd  * This is a noop, simply returning what one has been given.
    370   1.1       cgd  */
    371  1.17  christos int
    372  1.17  christos fifo_bmap(v)
    373  1.17  christos 	void *v;
    374  1.17  christos {
    375   1.8   mycroft 	struct vop_bmap_args /* {
    376   1.8   mycroft 		struct vnode *a_vp;
    377   1.8   mycroft 		daddr_t  a_bn;
    378   1.8   mycroft 		struct vnode **a_vpp;
    379   1.8   mycroft 		daddr_t *a_bnp;
    380  1.17  christos 	} */ *ap = v;
    381   1.1       cgd 
    382   1.8   mycroft 	if (ap->a_vpp != NULL)
    383   1.8   mycroft 		*ap->a_vpp = ap->a_vp;
    384   1.8   mycroft 	if (ap->a_bnp != NULL)
    385   1.8   mycroft 		*ap->a_bnp = ap->a_bn;
    386   1.1       cgd 	return (0);
    387   1.1       cgd }
    388   1.1       cgd 
    389   1.1       cgd /*
    390   1.1       cgd  * At the moment we do not do any locking.
    391   1.1       cgd  */
    392   1.1       cgd /* ARGSUSED */
    393  1.17  christos int
    394  1.17  christos fifo_lock(v)
    395  1.17  christos 	void *v;
    396   1.1       cgd {
    397   1.1       cgd 	return (0);
    398   1.1       cgd }
    399   1.1       cgd 
    400   1.1       cgd /* ARGSUSED */
    401  1.17  christos int
    402  1.17  christos fifo_unlock(v)
    403  1.17  christos 	void *v;
    404   1.1       cgd {
    405   1.1       cgd 
    406   1.1       cgd 	return (0);
    407   1.1       cgd }
    408   1.1       cgd 
    409   1.1       cgd /*
    410   1.1       cgd  * Device close routine
    411   1.1       cgd  */
    412   1.1       cgd /* ARGSUSED */
    413  1.17  christos int
    414  1.17  christos fifo_close(v)
    415  1.17  christos 	void *v;
    416  1.17  christos {
    417   1.8   mycroft 	struct vop_close_args /* {
    418   1.8   mycroft 		struct vnode *a_vp;
    419   1.8   mycroft 		int  a_fflag;
    420   1.8   mycroft 		struct ucred *a_cred;
    421   1.8   mycroft 		struct proc *a_p;
    422  1.17  christos 	} */ *ap = v;
    423   1.8   mycroft 	register struct vnode *vp = ap->a_vp;
    424   1.1       cgd 	register struct fifoinfo *fip = vp->v_fifoinfo;
    425   1.1       cgd 	int error1, error2;
    426   1.1       cgd 
    427  1.16   mycroft 	if (ap->a_fflag & FREAD) {
    428  1.16   mycroft 		if (--fip->fi_readers == 0)
    429  1.16   mycroft 			socantsendmore(fip->fi_writesock);
    430  1.16   mycroft 	}
    431   1.8   mycroft 	if (ap->a_fflag & FWRITE) {
    432  1.16   mycroft 		if (--fip->fi_writers == 0)
    433   1.1       cgd 			socantrcvmore(fip->fi_readsock);
    434   1.1       cgd 	}
    435   1.1       cgd 	if (vp->v_usecount > 1)
    436   1.1       cgd 		return (0);
    437   1.1       cgd 	error1 = soclose(fip->fi_readsock);
    438   1.1       cgd 	error2 = soclose(fip->fi_writesock);
    439   1.1       cgd 	FREE(fip, M_VNODE);
    440   1.1       cgd 	vp->v_fifoinfo = NULL;
    441   1.1       cgd 	if (error1)
    442   1.1       cgd 		return (error1);
    443   1.1       cgd 	return (error2);
    444   1.1       cgd }
    445   1.1       cgd 
    446   1.1       cgd /*
    447   1.1       cgd  * Print out the contents of a fifo vnode.
    448   1.1       cgd  */
    449  1.17  christos int
    450  1.17  christos fifo_print(v)
    451  1.17  christos 	void *v;
    452  1.17  christos {
    453   1.8   mycroft 	struct vop_print_args /* {
    454   1.8   mycroft 		struct vnode *a_vp;
    455  1.17  christos 	} */ *ap = v;
    456   1.1       cgd 
    457   1.1       cgd 	printf("tag VT_NON");
    458   1.8   mycroft 	fifo_printinfo(ap->a_vp);
    459   1.1       cgd 	printf("\n");
    460  1.17  christos 	return 0;
    461   1.1       cgd }
    462   1.1       cgd 
    463   1.1       cgd /*
    464   1.1       cgd  * Print out internal contents of a fifo vnode.
    465   1.1       cgd  */
    466  1.17  christos void
    467   1.1       cgd fifo_printinfo(vp)
    468   1.1       cgd 	struct vnode *vp;
    469   1.1       cgd {
    470   1.1       cgd 	register struct fifoinfo *fip = vp->v_fifoinfo;
    471   1.1       cgd 
    472   1.1       cgd 	printf(", fifo with %d readers and %d writers",
    473   1.1       cgd 		fip->fi_readers, fip->fi_writers);
    474   1.1       cgd }
    475   1.1       cgd 
    476   1.1       cgd /*
    477   1.8   mycroft  * Return POSIX pathconf information applicable to fifo's.
    478   1.8   mycroft  */
    479  1.17  christos int
    480  1.17  christos fifo_pathconf(v)
    481  1.17  christos 	void *v;
    482  1.17  christos {
    483   1.8   mycroft 	struct vop_pathconf_args /* {
    484   1.8   mycroft 		struct vnode *a_vp;
    485   1.8   mycroft 		int a_name;
    486  1.10       cgd 		register_t *a_retval;
    487  1.17  christos 	} */ *ap = v;
    488   1.8   mycroft 
    489   1.8   mycroft 	switch (ap->a_name) {
    490   1.8   mycroft 	case _PC_LINK_MAX:
    491   1.8   mycroft 		*ap->a_retval = LINK_MAX;
    492   1.8   mycroft 		return (0);
    493   1.8   mycroft 	case _PC_PIPE_BUF:
    494   1.8   mycroft 		*ap->a_retval = PIPE_BUF;
    495   1.8   mycroft 		return (0);
    496   1.8   mycroft 	case _PC_CHOWN_RESTRICTED:
    497   1.8   mycroft 		*ap->a_retval = 1;
    498   1.8   mycroft 		return (0);
    499   1.8   mycroft 	default:
    500   1.8   mycroft 		return (EINVAL);
    501   1.8   mycroft 	}
    502   1.8   mycroft 	/* NOTREACHED */
    503   1.8   mycroft }
    504   1.8   mycroft 
    505   1.8   mycroft /*
    506   1.1       cgd  * Fifo failed operation
    507   1.1       cgd  */
    508  1.17  christos /*ARGSUSED*/
    509  1.17  christos int
    510  1.17  christos fifo_ebadf(v)
    511  1.17  christos 	void *v;
    512   1.1       cgd {
    513   1.1       cgd 
    514   1.1       cgd 	return (EBADF);
    515   1.1       cgd }
    516   1.1       cgd 
    517   1.1       cgd /*
    518   1.1       cgd  * Fifo advisory byte-level locks.
    519   1.1       cgd  */
    520   1.1       cgd /* ARGSUSED */
    521  1.17  christos int
    522  1.17  christos fifo_advlock(v)
    523  1.17  christos 	void *v;
    524   1.1       cgd {
    525   1.1       cgd 	return (EOPNOTSUPP);
    526   1.1       cgd }
    527   1.1       cgd 
    528   1.1       cgd /*
    529   1.1       cgd  * Fifo bad operation
    530   1.1       cgd  */
    531  1.17  christos /*ARGSUSED*/
    532  1.17  christos int
    533  1.17  christos fifo_badop(v)
    534  1.17  christos 	void *v;
    535   1.1       cgd {
    536   1.1       cgd 
    537   1.1       cgd 	panic("fifo_badop called");
    538   1.1       cgd 	/* NOTREACHED */
    539   1.1       cgd }
    540