Implementing Read for char device driver
Hello,
I'm pretty much newb to linux kernel programming, I hope you'll be able to help me.
I need to implement the following functionality:
Userland proccess reads X elements from file descriptor.
Data comes from a buffer held in kernel module (device),
if X > buffer.len then return buffer.len elements
If X < buffer.len then return x elements
if buffer.len == 0 block the current proccess.
1.How do I know the X in kernel (how much data user requested to read)?
2.How do I return to userland with less then X element without "eof"ing the file?
This is the prototype of read function I use for file_operations struct
Code:
static ssize_t read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t * offset)
10x.