#define VOPFUNC int (*)(void *)
-extern int soo_ioctl(struct fileproc *fp, u_long cmd, caddr_t data, vfs_context_t ctx);
-extern int soo_select(struct fileproc *fp, int which, void * wql, vfs_context_t ctx);
-
int (**fifo_vnodeop_p)(void *);
struct vnodeopv_entry_desc fifo_vnodeop_entries[] = {
{ &vnop_default_desc, (VOPFUNC)vn_default_error },
if ( (error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0)) ) {
goto bad1;
}
- fip->fi_readsock = rso;
if ( (error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0)) ) {
(void)soclose(rso);
goto bad1;
}
- fip->fi_writesock = wso;
if ( (error = soconnect2(wso, rso)) ) {
(void)soclose(wso);
}
fip->fi_readers = fip->fi_writers = 0;
- socket_lock(wso, 1);
+ /* Lock ordering between wso and rso does not matter here
+ * because they are just created and no one has a reference to them
+ */
+ socket_lock(wso, 1);
wso->so_state |= SS_CANTRCVMORE;
wso->so_snd.sb_lowat = PIPE_BUF;
-#if 0
- /* Because all the unp is protected by single mutex
- * doing it in two step may actually cause problems
- * as it opens up window between the drop and acquire
- */
- socket_unlock(wso, 1);
+ socket_unlock(wso, 1);
- socket_lock(rso, 1);
-#endif
+ socket_lock(rso, 1);
rso->so_state |= SS_CANTSENDMORE;
- socket_unlock(wso, 1);
+ socket_unlock(rso, 1);
vnode_lock(vp);
+ fip->fi_readsock = rso;
+ fip->fi_writesock = wso;
+
fip->fi_flags |= FIFO_CREATED;
fip->fi_flags &= ~FIFO_INCREATE;
{
struct uio *uio = ap->a_uio;
struct socket *rso = ap->a_vp->v_fifoinfo->fi_readsock;
- int error, startresid;
+ user_ssize_t startresid;
+ int error;
int rflags;
#if DIAGNOSTIC
rflags = (ap->a_ioflag & IO_NDELAY) ? MSG_NBIO : 0;
- // LP64todo - fix this!
startresid = uio_resid(uio);
/* fifo conformance - if we have a reader open on the fifo but no
return (error2);
}
-#if !CONFIG_NO_PRINTF_STRINGS
/*
* Print out internal contents of a fifo vnode.
*/
printf(", fifo with %ld readers and %ld writers",
fip->fi_readers, fip->fi_writers);
}
-#endif /* !CONFIG_NO_PRINTF_STRINGS */
/*
* Return POSIX pathconf information applicable to fifo's.
return (ENOTSUP);
}
+
+/* You'd certainly better have an iocount on the vnode! */
+int
+fifo_freespace(struct vnode *vp, long *count)
+{
+ struct socket *rsock;
+ rsock = vp->v_fifoinfo->fi_readsock;
+ socket_lock(rsock, 1);
+ *count = sbspace(&rsock->so_rcv);
+ socket_unlock(rsock, 1);
+ return 0;
+}
+
+int
+fifo_charcount(struct vnode *vp, int *count)
+{
+ int mcount;
+ int err = sock_ioctl(vp->v_fifoinfo->fi_readsock, FIONREAD, (void*)&mcount);
+ if (err == 0) {
+ *count = mcount;
+ }
+ return err;
+}