linux - 在较新的Linux中,ext4中的哪个函数负责读取?

标签 linux filesystems system-calls vfs ext4

传统文件系统创建一个struct file_operations结构来实现VFS功能。例如,在 ext4(Linux 4.0 及之前)中,struct file_operations ext4_file_operations 使读指针指向 new_sync_read。

Linux 4.0 /fs/ext4/file.c

const struct file_operations ext4_dax_file_operations = {
    .read       = new_sync_read,
    .read_iter  = generic_file_read_iter,
     ....
}

但是,在Linux 4.1及更高版本中,没有对读指针进行这样的赋值,而是添加了一个splice_read指针。

Linux 4.1 /fs/ext4/file.c

const struct file_operations ext4_file_operations = {   
    .read_iter  = generic_file_read_iter,
    .splice_read    = generic_file_splice_read,
    ...
}

但是“/include/linux/fs.h”中定义的struct file_operations仍然具有读指针。那么,现在 ext4 中的哪个函数负责常规的读取功能呢?

最佳答案

我知道这个问题已经很老了,但我实际上一直在寻找同样的东西并找到了答案。

在 Linux 5.8 中,vfs_read() 函数内部,

if (file->f_op->read)
    ret = file->f_op->read(file, buf, count, pos);
else if (file->f_op->read_iter)
    ret = new_sync_read(file, buf, count, pos);

这些行查找 .read 是否由 file 的文件操作 (f_op) 定义。 如果没有,new_sync_read() 中的 .read_iter 调用将改为处理读取操作。

关于linux - 在较新的Linux中,ext4中的哪个函数负责读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45119658/

相关文章:

linux - 从变量更新 pom 文件的 Shell 命令

linux - 使用 NASM 在 macOS 中进行汇编级编程

c - 如何使这个递归函数将其内容保存到链接列表中?

c - 有关 C 语言文件和 I/O 系统调用的基础问题(在 Linux/UNIX 上)

c - 从文件中读取直到找到空格

linux - ulimits 中的 nproc 和 nofile 是什么?

linux - Ubuntu 中与交换相关的内存问题

linux - 使用 Exagear 桌面将 XCTU 安装到 Raspbian Jessie

windows - Windows 上的 Node 文件模式?

系统调用与函数调用之间的性能差异