0
votes

I am getting started in linux device driver development and I often see this kind of code and am unable to understand what it exactly does:

#<linux/fs.h>
loff_t (*llseek) (struct file *, loff_t,int);

The llseek method is used to change the read write position in a file.The loff_t is a long offset parameter. What I dont understand is the above syntax and how it actually works. Could someone please shed some light?

1

1 Answers

1
votes
    loff_t (*llseek) (struct file *, loff_t,int);

This just says that llseek is a pointer to a function that returns a loff_t and takes three parameters. The first parameter is a pointer to a struct file. The second is a loff_t. The third is an int.

However, if you look closely, you'll see it appears inside the declaration for struct file_operations. This means that struct file_operations contains a member called llseek that is a pointer to a function that returns a loff_t and takes those three parameters.

By the way, if you don't understand how to do OOP programming in C by using things like structures that contain pointers to functions, you really have no business going anywhere near a kernel device driver. (If you're familiar with C++, then just understand that a structure with pointers to functions is basically the way you fake a class in C.)