【发布时间】:2017-02-17 08:22:35
【问题描述】:
我正在查看 linux 源代码,并试图找出在设备节点上执行 write 或 ioctl 时所采用的路径。我想知道调用 fops 结构中的函数指针的确切位置和位置。我在源代码中找不到任何对 fops 结构的引用。
谁能给我更多关于这方面的信息/指出我正确的方向?
【问题讨论】:
标签: linux linux-kernel kernel linux-device-driver
我正在查看 linux 源代码,并试图找出在设备节点上执行 write 或 ioctl 时所采用的路径。我想知道调用 fops 结构中的函数指针的确切位置和位置。我在源代码中找不到任何对 fops 结构的引用。
谁能给我更多关于这方面的信息/指出我正确的方向?
【问题讨论】:
标签: linux linux-kernel kernel linux-device-driver
这取决于特定的子系统。以文件系统为例,我们可以检查任何不同的文件系统。让我们以 FAT 为例,因为这是我最近一直在研究的。它的实现在fs/fat/ 目录下。在该目录中运行 git grep file_operations 正是我们正在寻找的内容:
$ 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;
所以file_operations 有两个定义 - 一个在 dir.c 中称为 fat_dir_operations,另一个在 file.c 中称为 fat_file_operations。这些名称是不言自明的。在这些文件中,您可以看到 read、write 和 unlocked_ioctl(即不持有 BKL 锁的 ioctl)的实现。
同样,您可以为drivers/ 下的不同驱动程序查找file_operations。许多驱动程序都实现了它们。
【讨论】: