Linux Kernel Programming - File Operations or FOPs - struct file_operations
Linux Kernel Programming - File Operations or FOPs - struct file_operations

Whenever you do Linux Kernel programming, you must’ve noticed file operations are defined with respect to certain data-structures. Its quite common you may find these in Linux Device Drivers and so on. The data-structure mostly offers a certain service, say for example proc, sysfs, drivers, etc. So when a data-structure is instantiated (via a certain provided init/create API, example: proc_create()), we have to “populate” its corresponding File Operations (also known as FOPs in short). You can find these in various example kernel sample code which I discussed in the past video episodes. Depending upon the “capabilities or features” we provide it is required to populate (i.e define) these FOPs. So here is my detailed YouTube video episode about Linux Kernel File Operations.

Refer:
Linux Kernel /proc Interface – create and read /proc file ↗
Linux Kernel /proc Interface – create and write /proc file ↗
Linux Kernel /sysfs Interface – Sample Kernel Module create and read/write /sysfs file ↗

Refer Linux Kernel source:
/drivers/net/tap.c ↗
/drivers/net/tun.c ↗
/include/linux/fs.h ↗
/fs/nfs/file.c ↗