user277465
user277465

Reputation:

Reaching the "write" and "ioctl" inside fops

I'm looking at the linux source code and I'm trying to figure out the path taken when a write or an ioctl is performed on a device node. I'd like to know how exactly and where the function pointer in the fops struct is invoked. I could not find any references to the fops structure in the source code.

Could anyone give me more information on this / point me in the right direction?

Upvotes: 0

Views: 197

Answers (1)

bytefire
bytefire

Reputation: 4422

It depends upon specific subsystem. Taking filesystem as an example, we can check any of the different filesystems. Let's take FAT since that's the one I've been looking into recently. Its implementation is under fs/fat/ directory. Running git grep file_operations in that directory gives us exactly what we are looking for:

$ git grep file_operations
dir.c:const struct file_operations fat_dir_operations = {
fat.h:extern const struct file_operations fat_dir_operations;
fat.h:extern const struct file_operations fat_file_operations;
file.c:const struct file_operations fat_file_operations = {
inode.c:                inode->i_fop = &fat_file_operations;

So there are two definitions of file_operations - one in dir.c called fat_dir_operations and the other in file.c called fat_file_operations. The names are self explanatory. Inside those files you can see implementations for read, write and unlocked_ioctl (which is ioctl that doesn't hold the BKL lock).

Similarly you can grep for file_operations for different drivers under drivers/. Many drivers implement them.

Upvotes: 1

Related Questions