Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 06-24-2010 #1
- Join Date
- Jun 2010
Implementing Read for char device driver
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
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)
- 06-25-2010 #2
- Join Date
- May 2010
When application calls read system call,he provides the length of buffer he wants to read(through argument, size_t length) and it is upto the driver to provide how much it can.Driver will return the number of bytes that has written to user buffer using copy to user utility.
Only application has to check the return value to read system call.