static ssize_t ci_ll_read(struct dvb_ringbuffer *cibuf, struct file *file, char __user *buf, size_t count, loff_t *ppos) { int avail; int non_blocking = file->f_flags & O_NONBLOCK; ssize_t len; if (!cibuf->data || !count) return 0; if (non_blocking && (dvb_ringbuffer_empty(cibuf))) return -EWOULDBLOCK; if (wait_event_interruptible(cibuf->queue, !dvb_ringbuffer_empty(cibuf))) return -ERESTARTSYS; avail = dvb_ringbuffer_avail(cibuf); if (avail < 4) return 0; len = DVB_RINGBUFFER_PEEK(cibuf, 0) << 8; len |= DVB_RINGBUFFER_PEEK(cibuf, 1); if (avail < len + 2 || count < len) return -EINVAL; DVB_RINGBUFFER_SKIP(cibuf, 2); return dvb_ringbuffer_read(cibuf, buf, len, 1); }
static ssize_t dvb_dmxdev_buffer_read(struct dvb_ringbuffer *src, int non_blocking, char __user *buf, size_t count, loff_t *ppos) { size_t todo; ssize_t avail; ssize_t ret = 0; if (!src->data) return 0; if (src->error) { ret = src->error; dvb_ringbuffer_flush(src); return ret; } for (todo = count; todo > 0; todo -= ret) { if (non_blocking && dvb_ringbuffer_empty(src)) { ret = -EWOULDBLOCK; break; } ret = wait_event_interruptible(src->queue, !dvb_ringbuffer_empty(src) || (src->error != 0)); if (ret < 0) break; if (src->error) { ret = src->error; dvb_ringbuffer_flush(src); break; } avail = dvb_ringbuffer_avail(src); if (avail > todo) avail = todo; ret = dvb_ringbuffer_read(src, (u8 *)buf, avail, 1); if (ret < 0) break; buf += ret; } return (count - todo) ? (count - todo) : ret; }
ssize_t mpq_streambuffer_data_read( struct mpq_streambuffer *sbuff, u8 *buf, size_t len) { ssize_t actual_len = 0; if ((NULL == sbuff) || (NULL == buf)) return -EINVAL; if (MPQ_STREAMBUFFER_BUFFER_MODE_RING == sbuff->mode) { /* * Secure buffers are not permitted to be mapped into kernel * memory, and so buffer base address may be NULL */ if (NULL == sbuff->raw_data.data) return -EPERM; actual_len = dvb_ringbuffer_avail(&sbuff->raw_data); if (actual_len < len) len = actual_len; if (len) dvb_ringbuffer_read(&sbuff->raw_data, buf, len); wake_up_all(&sbuff->raw_data.queue); } else { /* Linear buffer group */ struct mpq_streambuffer_buffer_desc *desc; desc = (struct mpq_streambuffer_buffer_desc *) &sbuff->raw_data.data[sbuff->raw_data.pread]; /* * Secure buffers are not permitted to be mapped into kernel * memory, and so buffer base address may be NULL */ if (NULL == desc->base) return -EPERM; actual_len = (desc->write_ptr - desc->read_ptr); if (actual_len < len) len = actual_len; memcpy(buf, desc->base + desc->read_ptr, len); desc->read_ptr += len; } return len; }
void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags) { struct ngene_channel *chan = priv; struct ngene *dev = chan->dev; u32 alen; alen = dvb_ringbuffer_avail(&dev->tsout_rbuf); alen -= alen % 188; if (alen < len) FillTSBuffer(buf + alen, len - alen, flags); else alen = len; dvb_ringbuffer_read(&dev->tsout_rbuf, buf, alen); if (flags & DF_SWAP32) swap_buffer((u32 *)buf, alen); wake_up_interruptible(&dev->tsout_rbuf.queue); return buf; }