传统文件系统创建一个struct file_operations结构来实现VFS功能。例如,在 ext4(Linux 4.0 及之前)中,struct file_operations ext4_file_operations 使读指针指向 new_sync_read。
Linux 4.0 /fs/ext4/file.cconst 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.cconst 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/