Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the "struct file_operations" arguments?

I'm implementing a Linux character device driver.

The linux/fs.h header file lists the file_operations without argument names.

e.g.

struct file_operations {
    struct module *owner;
    loff_t (*llseek) (struct file *, loff_t, int);
    ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
    ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
    ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
    ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
    int (*readdir) (struct file *, void *, filldir_t);
    unsigned int (*poll) (struct file *, struct poll_table_struct *);
    long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
    long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
    int (*mmap) (struct file *, struct vm_area_struct *);
    int (*open) (struct inode *, struct file *);
    int (*flush) (struct file *, fl_owner_t id);
    int (*release) (struct inode *, struct file *);
    int (*fsync) (struct file *, loff_t, loff_t, int datasync);
    int (*aio_fsync) (struct kiocb *, int datasync);
    int (*fasync) (int, struct file *, int);
    int (*lock) (struct file *, int, struct file_lock *);
    ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
    unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
    int (*check_flags)(int);
    int (*flock) (struct file *, int, struct file_lock *);
    ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
    ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
    int (*setlease)(struct file *, long, struct file_lock **);
    long (*fallocate)(struct file *file, int mode, loff_t offset,
              loff_t len);
};

Where is the documentation that tells me what each argument is? Some are sort-of obvious, but some aren't. I prefer to refer to official documentation if I can, but I just can't find it.

e.g.

int (*fsync) (struct file *, loff_t, loff_t, int datasync);

There are two loff_t arguments. How do I know what they do?

I've been Googling and reading the device driver book, but I can't find any documents that explain what the arguments are for. Some of the arguments have also changed from when LDD3 was written.

like image 763
Mr Stinky Avatar asked Mar 04 '13 16:03

Mr Stinky


2 Answers

The LDD3 book is very useful still to understand the big picture, but it won't help with details (it is for kernel 2.6.10, meanwhile we are marching towards 3.9). The kernelnewbies drivers page is perhaps the most up-to-date, comprehensive resource. For day-to-day changes, LWN regularly comments on API changes and publishes longer overviews for new features. H-online carries a series of articles detailing changes from kernel version to kernel version, with links to discussions and patches.

like image 121
vonbrand Avatar answered Oct 25 '22 07:10

vonbrand


I had to implement my first linux driver a while back. By far the best thing I think you can do is download the Kernel source for the version you're developing against. Within the kernel source tree there is a directory called /Documentation. I'd start there, last I checked this is the "Official Documentation" for the kernel.

That being said, once you have the source code there really isn't a better documentation than reading the code and seeing what it's used as. For things like this, I'd look through /drivers/fs/ and find an example of where this struct is used and see how they're using it.

like image 21
Sean Madden Avatar answered Oct 25 '22 06:10

Sean Madden