Recently i'm working on a sample code about the communication between kernel driver module and user space applications. I have a question about the .read and .write interface in the file_operations(). According to LDD3:
ssize_t read(struct file *filp, char __user *buff, size_t count, loff_t *offp);
ssize_t write(struct file *filp, const char __user *buff,size_t count, loff_t *offp);
For both methods,
filp
is the file pointer andcount
is the size of the requested data transfer. Thebuff
argument points to the user buffer holding the data to be written or the empty buffer where the newly read data should be placed. Finally,offp
is a pointer to a “long offset type” object that indicates the file position the user is accessing.
I'm wondering, why do we need the parameter loff_t *offp
? Since the element in the file descriptor:
filp->f_pos
already indicates the current read and write position.
And according to my observation, after the read's or write's return, the system will automatically give filp->f_pos
the value of offp
.
Thanks a lot!