[PATCH/RFC] dmxdev: Add support for the FIONREAD ioctl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a standard ioctl supported by file descriptors, sockets (as
SIOCINQ), and ttys (as TIOCOUTQ) to get the size of the available
read buffer. It provides userspace with a feedback mechanism to
avoid overflow of the kernel ringbuffer, and is used by e.g.
libevent.

Signed-off-by: Dominic Chen <d.c.ddcc@xxxxxxxxx>
---
 drivers/media/dvb-core/dmxdev.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index a168cbe..668c8d2 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -28,6 +28,7 @@
 #include <linux/poll.h>
 #include <linux/ioctl.h>
 #include <linux/wait.h>
+#include <asm/ioctls.h>
 #include <asm/uaccess.h>
 #include "dmxdev.h"
 
@@ -57,6 +58,22 @@ static int dvb_dmxdev_buffer_write(struct dvb_ringbuffer *buf,
 	return dvb_ringbuffer_write(buf, src, len);
 }
 
+static int dvb_dmxdev_get_buffer_avail(struct dvb_ringbuffer *src,
+				       u32 *len)
+{
+	if (!src->data) {
+		*len = 0;
+		return 0;
+	}
+
+	if (src->error)
+		return src->error;
+
+	*len = dvb_ringbuffer_avail(src);
+
+	return 0;
+}
+
 static ssize_t dvb_dmxdev_buffer_read(struct dvb_ringbuffer *src,
 				      int non_blocking, char __user *buf,
 				      size_t count, loff_t *ppos)
@@ -965,6 +982,16 @@ static int dvb_demux_do_ioctl(struct file *file,
 		return -ERESTARTSYS;
 
 	switch (cmd) {
+	case FIONREAD:
+		if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
+			mutex_unlock(&dmxdev->mutex);
+			return -ERESTARTSYS;
+		}
+		ret = dvb_dmxdev_get_buffer_avail(&dmxdevfilter->buffer, parg);
+		mutex_unlock(&dmxdevfilter->mutex);
+
+		break;
+
 	case DMX_START:
 		if (mutex_lock_interruptible(&dmxdevfilter->mutex)) {
 			mutex_unlock(&dmxdev->mutex);
@@ -1160,6 +1187,10 @@ static int dvb_dvr_do_ioctl(struct file *file,
 		return -ERESTARTSYS;
 
 	switch (cmd) {
+	case FIONREAD:
+		ret = dvb_dmxdev_get_buffer_avail(&dmxdev->dvr_buffer, parg);
+		break;
+
 	case DMX_SET_BUFFER_SIZE:
 		ret = dvb_dvr_set_buffer_size(dmxdev, arg);
 		break;
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux