简体   繁体   中英

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?

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.

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. If I use cat command without initialising .read but initialising .read_iter the .read_iter is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM