Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

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,
     ....
}

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 /fs/ext4/file.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. So, which function in ext4 now is responsible for the conventional read function?

like image 345
Akr Avatar asked Nov 02 '25 00:11

Akr


1 Answers

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,

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). If not, .read_iter calls in new_sync_read() will handle the read operation instead.

like image 80
nobleminsu Avatar answered Nov 04 '25 09:11

nobleminsu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!