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