Akr
Akr

Reputation: 199

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?

Upvotes: 4

Views: 759

Answers (2)

nobleminsu
nobleminsu

Reputation: 41

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.

Upvotes: 4

C. Kalita
C. Kalita

Reputation: 95

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.

Upvotes: 3

Related Questions