[英]In the newer Linux, which function in ext4 is responsible for read?
Conventional filesystems create a struct file_operations structure to implement the VFS functions.传统的文件系统创建一个struct file_operations结构来实现 VFS 功能。 For example, in the ext4 (Linux 4.0 and before) the struct file_operations ext4_file_operations make the read pointer point to new_sync_read.
例如,在 ext4(Linux 4.0 及之前)中, struct file_operations ext4_file_operations使读取指针指向 new_sync_read。
Linux 4.0 /fs/ext4/file.c Linux 4.0 /fs/ext4/文件.c
const struct file_operations ext4_dax_file_operations = {
.read = new_sync_read,
.read_iter = generic_file_read_iter,
....
}
However, in Linux 4.1 and later, there is no such assignment for the read pointer, but a splice_read pointer is added.但是在Linux 4.1及之后的版本中,读指针就没有这样的赋值了,而是增加了一个splice_read指针。
Linux 4.1 /fs/ext4/file.c Linux 4.1 /fs/ext4/文件.c
const struct file_operations ext4_file_operations = {
.read_iter = generic_file_read_iter,
.splice_read = generic_file_splice_read,
...
}
But the struct file_operations defined in "/include/linux/fs.h" still has the read pointer.但是“/include/linux/fs.h”中定义的struct file_operations仍然有读指针。 So, which function in ext4 now is responsible for the conventional read function?
那么,现在ext4中的哪个函数负责常规的读取函数呢?
I know this question has been quite old, but I was actually looking for the same thing and found the answer.我知道这个问题已经很老了,但实际上我一直在寻找同样的东西并找到了答案。
In Linux 5.8, inside vfs_read()
function,在 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);
these lines find whether .read
is defined by file
's file operations ( f_op
).这些行查找
.read
是否由file
的文件操作 ( f_op
) 定义。 If not, .read_iter
calls in new_sync_read()
will handle the read operation instead.如果不是,
new_sync_read()
中的.read_iter
调用将改为处理读取操作。
I have tested by writing a new file system and found if we initialise both pointers then .read
is called if I use cat command.我通过编写一个新的文件系统进行了测试,发现如果我们初始化两个指针,那么如果我使用cat命令,
.read
就会被调用。 If I use cat command without initialising .read
but initialising .read_iter
the .read_iter
is called.如果我使用cat命令而不初始化
.read
但初始化.read_iter
则调用.read_iter
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.