The thread/proc pointer argument in the VFS subsystem originally existed
[dragonfly.git] / sys / vfs / fifofs / fifo_vnops.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1990, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)fifo_vnops.c 8.10 (Berkeley) 5/27/95
34 * $FreeBSD: src/sys/miscfs/fifofs/fifo_vnops.c,v 1.45.2.4 2003/04/22 10:11:24 bde Exp $
87de5057 35 * $DragonFly: src/sys/vfs/fifofs/fifo_vnops.c,v 1.28 2006/05/06 02:43:13 dillon Exp $
984263bc
MD
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/unistd.h>
41#include <sys/kernel.h>
42#include <sys/lock.h>
43#include <sys/malloc.h>
87de5057 44#include <sys/thread2.h>
984263bc
MD
45#include <sys/vnode.h>
46#include <sys/socket.h>
47#include <sys/socketvar.h>
48#include <sys/filio.h>
49#include <sys/fcntl.h>
50#include <sys/file.h>
51#include <sys/event.h>
52#include <sys/poll.h>
53#include <sys/un.h>
87de5057
MD
54
55#include <sys/thread2.h>
56
1f2de5d4 57#include "fifo.h"
984263bc
MD
58
59/*
60 * This structure is associated with the FIFO vnode and stores
61 * the state associated with the FIFO.
62 */
63struct fifoinfo {
64 struct socket *fi_readsock;
65 struct socket *fi_writesock;
66 long fi_readers;
67 long fi_writers;
68};
69
a6ee311a
RG
70static int fifo_badop (void);
71static int fifo_print (struct vop_print_args *);
e62afb5f 72static int fifo_lookup (struct vop_old_lookup_args *);
a6ee311a
RG
73static int fifo_open (struct vop_open_args *);
74static int fifo_close (struct vop_close_args *);
75static int fifo_read (struct vop_read_args *);
76static int fifo_write (struct vop_write_args *);
77static int fifo_ioctl (struct vop_ioctl_args *);
78static int fifo_poll (struct vop_poll_args *);
79static int fifo_kqfilter (struct vop_kqfilter_args *);
80static int fifo_inactive (struct vop_inactive_args *);
81static int fifo_bmap (struct vop_bmap_args *);
82static int fifo_pathconf (struct vop_pathconf_args *);
83static int fifo_advlock (struct vop_advlock_args *);
984263bc
MD
84
85static void filt_fifordetach(struct knote *kn);
86static int filt_fiforead(struct knote *kn, long hint);
87static void filt_fifowdetach(struct knote *kn);
88static int filt_fifowrite(struct knote *kn, long hint);
89
90static struct filterops fiforead_filtops =
91 { 1, NULL, filt_fifordetach, filt_fiforead };
92static struct filterops fifowrite_filtops =
93 { 1, NULL, filt_fifowdetach, filt_fifowrite };
94
2d3e977e 95struct vop_ops *fifo_vnode_vops;
984263bc 96static struct vnodeopv_entry_desc fifo_vnodeop_entries[] = {
625ddaba
JS
97 { &vop_default_desc, (vnodeopv_entry_t) vop_defaultop },
98 { &vop_access_desc, (vnodeopv_entry_t) vop_ebadf },
99 { &vop_advlock_desc, (vnodeopv_entry_t) fifo_advlock },
100 { &vop_bmap_desc, (vnodeopv_entry_t) fifo_bmap },
101 { &vop_close_desc, (vnodeopv_entry_t) fifo_close },
e62afb5f 102 { &vop_old_create_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba
JS
103 { &vop_getattr_desc, (vnodeopv_entry_t) vop_ebadf },
104 { &vop_inactive_desc, (vnodeopv_entry_t) fifo_inactive },
105 { &vop_ioctl_desc, (vnodeopv_entry_t) fifo_ioctl },
106 { &vop_kqfilter_desc, (vnodeopv_entry_t) fifo_kqfilter },
e62afb5f
MD
107 { &vop_old_link_desc, (vnodeopv_entry_t) fifo_badop },
108 { &vop_old_lookup_desc, (vnodeopv_entry_t) fifo_lookup },
109 { &vop_old_mkdir_desc, (vnodeopv_entry_t) fifo_badop },
110 { &vop_old_mknod_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba
JS
111 { &vop_open_desc, (vnodeopv_entry_t) fifo_open },
112 { &vop_pathconf_desc, (vnodeopv_entry_t) fifo_pathconf },
113 { &vop_poll_desc, (vnodeopv_entry_t) fifo_poll },
114 { &vop_print_desc, (vnodeopv_entry_t) fifo_print },
115 { &vop_read_desc, (vnodeopv_entry_t) fifo_read },
116 { &vop_readdir_desc, (vnodeopv_entry_t) fifo_badop },
117 { &vop_readlink_desc, (vnodeopv_entry_t) fifo_badop },
118 { &vop_reallocblks_desc, (vnodeopv_entry_t) fifo_badop },
119 { &vop_reclaim_desc, (vnodeopv_entry_t) vop_null },
e62afb5f
MD
120 { &vop_old_remove_desc, (vnodeopv_entry_t) fifo_badop },
121 { &vop_old_rename_desc, (vnodeopv_entry_t) fifo_badop },
122 { &vop_old_rmdir_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba 123 { &vop_setattr_desc, (vnodeopv_entry_t) vop_ebadf },
e62afb5f 124 { &vop_old_symlink_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba 125 { &vop_write_desc, (vnodeopv_entry_t) fifo_write },
984263bc
MD
126 { NULL, NULL }
127};
128static struct vnodeopv_desc fifo_vnodeop_opv_desc =
dc1be39c 129 { &fifo_vnode_vops, fifo_vnodeop_entries, 0 };
984263bc
MD
130
131VNODEOP_SET(fifo_vnodeop_opv_desc);
132
5fd012e0
MD
133static MALLOC_DEFINE(M_FIFOINFO, "Fifo info", "Fifo info entries");
134
b5f12e21
CP
135/*
136 * fifo_vnoperate(struct vnodeop_desc *a_desc, ...)
137 */
984263bc 138int
b5f12e21 139fifo_vnoperate(struct vop_generic_args *ap)
984263bc 140{
0961aa92 141 return (VOCALL(fifo_vnode_vops, ap));
984263bc
MD
142}
143
144/*
145 * Trivial lookup routine that always fails.
b5f12e21
CP
146 *
147 * fifo_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
148 * struct componentname *a_cnp)
984263bc
MD
149 */
150/* ARGSUSED */
151static int
e62afb5f 152fifo_lookup(struct vop_old_lookup_args *ap)
984263bc 153{
984263bc
MD
154 *ap->a_vpp = NULL;
155 return (ENOTDIR);
156}
157
158/*
159 * Open called to set up a new instance of a fifo or
160 * to find an active instance of a fifo.
b5f12e21
CP
161 *
162 * fifo_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
163 * struct thread *a_td)
984263bc
MD
164 */
165/* ARGSUSED */
166static int
b5f12e21 167fifo_open(struct vop_open_args *ap)
984263bc 168{
87de5057 169 struct thread *td = curthread;
984263bc
MD
170 struct vnode *vp = ap->a_vp;
171 struct fifoinfo *fip;
984263bc
MD
172 struct socket *rso, *wso;
173 int error;
174
175 if ((fip = vp->v_fifoinfo) == NULL) {
5fd012e0 176 MALLOC(fip, struct fifoinfo *, sizeof(*fip), M_FIFOINFO, M_WAITOK);
984263bc 177 vp->v_fifoinfo = fip;
87de5057 178 error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0, td);
984263bc 179 if (error) {
5fd012e0 180 free(fip, M_FIFOINFO);
984263bc
MD
181 vp->v_fifoinfo = NULL;
182 return (error);
183 }
184 fip->fi_readsock = rso;
87de5057 185 error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0, td);
984263bc 186 if (error) {
b1ce5639 187 soclose(rso);
5fd012e0 188 free(fip, M_FIFOINFO);
984263bc
MD
189 vp->v_fifoinfo = NULL;
190 return (error);
191 }
192 fip->fi_writesock = wso;
193 error = unp_connect2(wso, rso);
194 if (error) {
b1ce5639
SW
195 soclose(wso);
196 soclose(rso);
5fd012e0 197 free(fip, M_FIFOINFO);
984263bc
MD
198 vp->v_fifoinfo = NULL;
199 return (error);
200 }
201 fip->fi_readers = fip->fi_writers = 0;
202 wso->so_snd.sb_lowat = PIPE_BUF;
203 rso->so_state |= SS_CANTRCVMORE;
204 }
205 if (ap->a_mode & FREAD) {
206 fip->fi_readers++;
207 if (fip->fi_readers == 1) {
208 fip->fi_writesock->so_state &= ~SS_CANTSENDMORE;
209 if (fip->fi_writers > 0) {
210 wakeup((caddr_t)&fip->fi_writers);
211 sowwakeup(fip->fi_writesock);
212 }
213 }
214 }
215 if (ap->a_mode & FWRITE) {
216 fip->fi_writers++;
217 if (fip->fi_writers == 1) {
218 fip->fi_readsock->so_state &= ~SS_CANTRCVMORE;
219 if (fip->fi_readers > 0) {
220 wakeup((caddr_t)&fip->fi_readers);
221 sorwakeup(fip->fi_writesock);
222 }
223 }
224 }
225 if ((ap->a_mode & FREAD) && (ap->a_mode & O_NONBLOCK) == 0) {
226 if (fip->fi_writers == 0) {
ca466bae 227 VOP_UNLOCK(vp, 0);
984263bc 228 error = tsleep((caddr_t)&fip->fi_readers,
377d4740 229 PCATCH, "fifoor", 0);
ca466bae 230 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
231 if (error)
232 goto bad;
233 /*
234 * We must have got woken up because we had a writer.
235 * That (and not still having one) is the condition
236 * that we must wait for.
237 */
238 }
239 }
240 if (ap->a_mode & FWRITE) {
241 if (ap->a_mode & O_NONBLOCK) {
242 if (fip->fi_readers == 0) {
243 error = ENXIO;
244 goto bad;
245 }
246 } else {
247 if (fip->fi_readers == 0) {
ca466bae 248 VOP_UNLOCK(vp, 0);
984263bc 249 error = tsleep((caddr_t)&fip->fi_writers,
377d4740 250 PCATCH, "fifoow", 0);
ca466bae 251 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
252 if (error)
253 goto bad;
254 /*
255 * We must have got woken up because we had
256 * a reader. That (and not still having one)
257 * is the condition that we must wait for.
258 */
259 }
260 }
261 }
8ddc6004 262 return (vop_stdopen(ap));
984263bc 263bad:
cbeb1f72 264 vop_stdopen(ap); /* bump opencount/writecount as appropriate */
87de5057 265 VOP_CLOSE(vp, ap->a_mode);
984263bc
MD
266 return (error);
267}
268
269/*
270 * Vnode op for read
b5f12e21
CP
271 *
272 * fifo_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
273 * struct ucred *a_cred)
984263bc
MD
274 */
275/* ARGSUSED */
276static int
b5f12e21 277fifo_read(struct vop_read_args *ap)
984263bc
MD
278{
279 struct uio *uio = ap->a_uio;
280 struct socket *rso = ap->a_vp->v_fifoinfo->fi_readsock;
984263bc
MD
281 int error, startresid;
282
283#ifdef DIAGNOSTIC
284 if (uio->uio_rw != UIO_READ)
285 panic("fifo_read mode");
286#endif
287 if (uio->uio_resid == 0)
288 return (0);
289 if (ap->a_ioflag & IO_NDELAY)
290 rso->so_state |= SS_NBIO;
291 startresid = uio->uio_resid;
ca466bae 292 VOP_UNLOCK(ap->a_vp, 0);
984263bc
MD
293 error = soreceive(rso, (struct sockaddr **)0, uio, (struct mbuf **)0,
294 (struct mbuf **)0, (int *)0);
ca466bae 295 vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
296 if (ap->a_ioflag & IO_NDELAY)
297 rso->so_state &= ~SS_NBIO;
298 return (error);
299}
300
301/*
302 * Vnode op for write
b5f12e21
CP
303 *
304 * fifo_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
305 * struct ucred *a_cred)
984263bc
MD
306 */
307/* ARGSUSED */
308static int
b5f12e21 309fifo_write(struct vop_write_args *ap)
984263bc
MD
310{
311 struct socket *wso = ap->a_vp->v_fifoinfo->fi_writesock;
dadab5e9 312 struct thread *td = ap->a_uio->uio_td;
984263bc
MD
313 int error;
314
315#ifdef DIAGNOSTIC
316 if (ap->a_uio->uio_rw != UIO_WRITE)
317 panic("fifo_write mode");
318#endif
319 if (ap->a_ioflag & IO_NDELAY)
320 wso->so_state |= SS_NBIO;
ca466bae 321 VOP_UNLOCK(ap->a_vp, 0);
984263bc 322 error = sosend(wso, (struct sockaddr *)0, ap->a_uio, 0,
dadab5e9 323 (struct mbuf *)0, 0, td);
ca466bae 324 vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
325 if (ap->a_ioflag & IO_NDELAY)
326 wso->so_state &= ~SS_NBIO;
327 return (error);
328}
329
330/*
331 * Device ioctl operation.
b5f12e21
CP
332 *
333 * fifo_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data, int a_fflag,
334 * struct ucred *a_cred, struct thread *a_td)
984263bc
MD
335 */
336/* ARGSUSED */
337static int
b5f12e21 338fifo_ioctl(struct vop_ioctl_args *ap)
984263bc 339{
9443ca22 340 struct file filetmp; /* Local */
984263bc
MD
341 int error;
342
343 if (ap->a_command == FIONBIO)
344 return (0);
345 if (ap->a_fflag & FREAD) {
fbb4eeab 346 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_readsock;
87de5057 347 error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_cred);
984263bc
MD
348 if (error)
349 return (error);
350 }
351 if (ap->a_fflag & FWRITE) {
fbb4eeab 352 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_writesock;
87de5057 353 error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_cred);
984263bc
MD
354 if (error)
355 return (error);
356 }
357 return (0);
358}
359
b5f12e21
CP
360/*
361 * fifo_kqfilter(struct vnode *a_vp, struct knote *a_kn)
362 */
984263bc
MD
363/* ARGSUSED */
364static int
b5f12e21 365fifo_kqfilter(struct vop_kqfilter_args *ap)
984263bc
MD
366{
367 struct fifoinfo *fi = ap->a_vp->v_fifoinfo;
368 struct socket *so;
369 struct sockbuf *sb;
370
371 switch (ap->a_kn->kn_filter) {
372 case EVFILT_READ:
373 ap->a_kn->kn_fop = &fiforead_filtops;
374 so = fi->fi_readsock;
375 sb = &so->so_rcv;
376 break;
377 case EVFILT_WRITE:
378 ap->a_kn->kn_fop = &fifowrite_filtops;
379 so = fi->fi_writesock;
380 sb = &so->so_snd;
381 break;
382 default:
383 return (1);
384 }
385
386 ap->a_kn->kn_hook = (caddr_t)so;
387
388 SLIST_INSERT_HEAD(&sb->sb_sel.si_note, ap->a_kn, kn_selnext);
389 sb->sb_flags |= SB_KNOTE;
390
391 return (0);
392}
393
394static void
395filt_fifordetach(struct knote *kn)
396{
397 struct socket *so = (struct socket *)kn->kn_hook;
398
399 SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext);
400 if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note))
401 so->so_rcv.sb_flags &= ~SB_KNOTE;
402}
403
404static int
405filt_fiforead(struct knote *kn, long hint)
406{
407 struct socket *so = (struct socket *)kn->kn_hook;
408
409 kn->kn_data = so->so_rcv.sb_cc;
410 if (so->so_state & SS_CANTRCVMORE) {
411 kn->kn_flags |= EV_EOF;
412 return (1);
413 }
414 kn->kn_flags &= ~EV_EOF;
415 return (kn->kn_data > 0);
416}
417
418static void
419filt_fifowdetach(struct knote *kn)
420{
421 struct socket *so = (struct socket *)kn->kn_hook;
422
423 SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext);
424 if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note))
425 so->so_snd.sb_flags &= ~SB_KNOTE;
426}
427
428static int
429filt_fifowrite(struct knote *kn, long hint)
430{
431 struct socket *so = (struct socket *)kn->kn_hook;
432
433 kn->kn_data = sbspace(&so->so_snd);
434 if (so->so_state & SS_CANTSENDMORE) {
435 kn->kn_flags |= EV_EOF;
436 return (1);
437 }
438 kn->kn_flags &= ~EV_EOF;
439 return (kn->kn_data >= so->so_snd.sb_lowat);
440}
441
b5f12e21
CP
442/*
443 * fifo_poll(struct vnode *a_vp, int a_events, struct ucred *a_cred,
444 * struct thread *a_td)
445 */
984263bc
MD
446/* ARGSUSED */
447static int
b5f12e21 448fifo_poll(struct vop_poll_args *ap)
984263bc
MD
449{
450 struct file filetmp;
d08a3c4d
HP
451 int events, revents = 0;
452
630a348c 453 events = ap->a_events &
9443ca22 454 (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND);
d08a3c4d
HP
455 if (events) {
456 /*
9443ca22
HP
457 * If POLLIN or POLLRDNORM is requested and POLLINIGNEOF is
458 * not, then convert the first two to the last one. This
459 * tells the socket poll function to ignore EOF so that we
460 * block if there is no writer (and no data). Callers can
461 * set POLLINIGNEOF to get non-blocking behavior.
d08a3c4d 462 */
ad4bd3a5
HP
463 if (events & (POLLIN | POLLRDNORM) &&
464 !(events & POLLINIGNEOF)) {
d08a3c4d
HP
465 events &= ~(POLLIN | POLLRDNORM);
466 events |= POLLINIGNEOF;
467 }
9443ca22 468
fbb4eeab 469 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_readsock;
984263bc 470 if (filetmp.f_data)
87de5057 471 revents |= soo_poll(&filetmp, events, ap->a_cred);
d08a3c4d 472
9443ca22
HP
473 /* Reverse the above conversion. */
474 if ((revents & POLLINIGNEOF) &&
475 !(ap->a_events & POLLINIGNEOF)) {
476 revents |= (ap->a_events & (POLLIN | POLLRDNORM));
d08a3c4d 477 revents &= ~POLLINIGNEOF;
d08a3c4d 478 }
984263bc 479 }
d08a3c4d
HP
480 events = ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND);
481 if (events) {
fbb4eeab 482 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_writesock;
984263bc 483 if (filetmp.f_data)
87de5057 484 revents |= soo_poll(&filetmp, events, ap->a_cred);
984263bc
MD
485 }
486 return (revents);
487}
488
b5f12e21
CP
489/*
490 * fifo_inactive(struct vnode *a_vp, struct thread *a_td)
491 */
984263bc 492static int
b5f12e21 493fifo_inactive(struct vop_inactive_args *ap)
984263bc 494{
984263bc
MD
495 return (0);
496}
497
498/*
499 * This is a noop, simply returning what one has been given.
b5f12e21 500 *
54078292
MD
501 * fifo_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
502 * off_t *a_doffsetp, int *a_runp, int *a_runb)
984263bc
MD
503 */
504static int
b5f12e21 505fifo_bmap(struct vop_bmap_args *ap)
984263bc 506{
984263bc
MD
507 if (ap->a_vpp != NULL)
508 *ap->a_vpp = ap->a_vp;
54078292
MD
509 if (ap->a_doffsetp != NULL)
510 *ap->a_doffsetp = ap->a_loffset;
984263bc
MD
511 if (ap->a_runp != NULL)
512 *ap->a_runp = 0;
513 if (ap->a_runb != NULL)
514 *ap->a_runb = 0;
515 return (0);
516}
517
518/*
519 * Device close routine
b5f12e21
CP
520 *
521 * fifo_close(struct vnode *a_vp, int a_fflag, struct ucred *a_cred,
522 * struct thread *a_td)
984263bc
MD
523 */
524/* ARGSUSED */
525static int
b5f12e21 526fifo_close(struct vop_close_args *ap)
984263bc 527{
0e99e805
RG
528 struct vnode *vp = ap->a_vp;
529 struct fifoinfo *fip = vp->v_fifoinfo;
984263bc
MD
530 int error1, error2;
531
532 if (ap->a_fflag & FREAD) {
533 fip->fi_readers--;
534 if (fip->fi_readers == 0)
535 socantsendmore(fip->fi_writesock);
536 }
537 if (ap->a_fflag & FWRITE) {
538 fip->fi_writers--;
539 if (fip->fi_writers == 0)
540 socantrcvmore(fip->fi_readsock);
541 }
8ddc6004
MD
542 if (vp->v_usecount > 1) {
543 vop_stdclose(ap);
984263bc 544 return (0);
8ddc6004 545 }
984263bc
MD
546 error1 = soclose(fip->fi_readsock);
547 error2 = soclose(fip->fi_writesock);
5fd012e0 548 FREE(fip, M_FIFOINFO);
984263bc
MD
549 vp->v_fifoinfo = NULL;
550 if (error1)
551 return (error1);
8ddc6004 552 vop_stdclose(ap);
984263bc
MD
553 return (error2);
554}
555
556
557/*
558 * Print out internal contents of a fifo vnode.
559 */
560int
b5f12e21 561fifo_printinfo(struct vnode *vp)
984263bc 562{
0e99e805 563 struct fifoinfo *fip = vp->v_fifoinfo;
984263bc
MD
564
565 printf(", fifo with %ld readers and %ld writers",
566 fip->fi_readers, fip->fi_writers);
567 return (0);
568}
569
570/*
571 * Print out the contents of a fifo vnode.
b5f12e21
CP
572 *
573 * fifo_print(struct vnode *a_vp)
984263bc
MD
574 */
575static int
b5f12e21 576fifo_print(struct vop_print_args *ap)
984263bc 577{
984263bc
MD
578 printf("tag VT_NON");
579 fifo_printinfo(ap->a_vp);
580 printf("\n");
581 return (0);
582}
583
584/*
585 * Return POSIX pathconf information applicable to fifo's.
b5f12e21
CP
586 *
587 * fifo_pathconf(struct vnode *a_vp, int a_name, int *a_retval)
984263bc
MD
588 */
589int
b5f12e21 590fifo_pathconf(struct vop_pathconf_args *ap)
984263bc 591{
984263bc
MD
592 switch (ap->a_name) {
593 case _PC_LINK_MAX:
594 *ap->a_retval = LINK_MAX;
595 return (0);
596 case _PC_PIPE_BUF:
597 *ap->a_retval = PIPE_BUF;
598 return (0);
599 case _PC_CHOWN_RESTRICTED:
600 *ap->a_retval = 1;
601 return (0);
602 default:
603 return (EINVAL);
604 }
605 /* NOTREACHED */
606}
607
608/*
609 * Fifo advisory byte-level locks.
b5f12e21
CP
610 *
611 * fifo_advlock(struct vnode *a_vp, caddr_t a_id, int a_op, struct flock *a_fl,
612 * int a_flags)
984263bc
MD
613 */
614/* ARGSUSED */
615static int
b5f12e21 616fifo_advlock(struct vop_advlock_args *ap)
984263bc 617{
984263bc
MD
618 return (ap->a_flags & F_FLOCK ? EOPNOTSUPP : EINVAL);
619}
620
621/*
622 * Fifo bad operation
623 */
624static int
b5f12e21 625fifo_badop(void)
984263bc 626{
984263bc
MD
627 panic("fifo_badop called");
628 /* NOTREACHED */
629}