0

I am new to linux device drivers. I see that the fops structures defines write as ::

static ssize_t device_write(struct file *, const char *, size_t, loff_t *);

whereas the write function in the userspace program uses 3 parameters?

ssize_t write(int fd, const void *buf, size_t nbytes);

What happens to the offset parameter loff_t?

claw107
  • 71
  • 1
  • 9
  • 1
    The `device_write` which you are seeing is the last function in the chain of "write" callbacks from user space to kernel; which actually talks to hardware (or some pseudo implementation) Linux kernel has an abstraction for file system related calls which is called VFS. The `offset` is handled there, so that user do not have to worry when writing. However you can still access the offset by making appropriate "seek" call. Hope this helps. – vtha Jul 14 '17 at 05:37
  • Some more information about offset can be found here: https://stackoverflow.com/questions/9713112/understanding-loff-t-offp-for-file-operations – vtha Jul 14 '17 at 05:42
  • Thanks , that is the answer i was looking for. – claw107 Jul 14 '17 at 06:15

0 Answers0