2021SC@SDUSC
vfs-read
Function vfs-read is in fs/read_write.c just as sys_read is.In the last blog we've analysed about sys_read, and a dramatic thing is that in the OS experiment we've operated this term, file system is also a fancinating part.The experiment uses Nachos as platform, which is a simulation of operating system runs on Linux(I heard that it is also available in Windows somehow)based in Linux itself. In the last blog I said that how system call read transfer to vfs_read is out of the question of these blogs, but in the experiment after doing it myself(in a simpler way of course), I now a little bit understand that system calls are functioned as exceptions.When an exception is caught, the system will discuss the type of it in which sys_call is a particular one.Then the real function like sys_read will be called to handle this exception, the system call.
Let's go back to topic.Here is the code(ver 5.14.8)
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
ssize_t ret;
if (!(file->f_mode & FMODE_READ))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_READ))
return -EINVAL;
if (unlikely(!access_ok(buf, count)))
return -EFAULT;
ret = rw_verify_area(READ, file, pos, count);
if (ret)
return ret;
if (count > MAX_RW_COUNT)
count = MAX_RW_COUNT;
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);
else
ret = -EINVAL;
if (ret > 0) {
fsnotify_access(file);
add_rc