Search code examples
linuxfileiokernelsystem-calls

How to 'sys_seek' in terms of 'sys_read'?


File handling in a kernel module. What is the appropriate way to 'seek' in a file? I could not find a sys_seek() function (such as sys_read()). Or, is it better only to use the VFS function API?

The question How to read/write files within a Linux kernel module? does not handle input stream navigation, i.e. there is no reference to tell()/seek() of any kind.


Solution

  • seek functionality in the kernel space can be achieved by vfs_llseek function:

    loff_t vfs_llseek(struct file *file, loff_t offset, int whence);
    

    The function returns resulted offset or negative value in case of error.