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?
This just says that
llseekis a pointer to a function that returns aloff_tand takes three parameters. The first parameter is a pointer to astruct file. The second is aloff_t. The third is anint.However, if you look closely, you’ll see it appears inside the declaration for
struct file_operations. This means thatstruct file_operationscontains a member calledllseekthat is a pointer to a function that returns aloff_tand 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.)