Introduction to device file operations
Operations that you can perform on files depend on the drivers that manage those files. Such operations are defined in the kernel as instances of struct file_operations
. struct file_operations
exposes a set of callbacks that will handle any user space system call on a file. For example, if you want users to be able to perform a write
on the file representing your device, you must implement the callback corresponding to that write
function and add it into the struct file_operations
that will be tied to your device. Let's fill in a file operations structure:
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 *); unsigned int (*poll) (struct file *, struct poll_table_struct *); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) ...