read()

read()_第1张图片
read函数在用户空间是由read系统调用实现的,由编译器编译成软中断int 0x80来进入内核空间,然后在中端门上进入函数sys_read,从而进入内核空间执行read操作。

sys_read函数定义在fs/read_write.c文件,定义如下

asmlinkage ssize_t sys_read(unsigned int fd, char __user * buf, size_t count)
{
struct file *file;/*文件指针*/
ssize_t ret = -EBADF;
int fput_needed;
 
 
/*轻量级的由文件描述符得到文件指针函数*/
file = fget_light(fd, &fput_needed);
if (file) {
/*file结构体里的指示文件读写位置的int变量读取*/
loff_t pos = file_pos_read(file);
/*vfs虚拟文件系统实现read操作的地方*/
ret = vfs_read(file, buf, count, &pos);
/*file结构体里的指示文件读写位置的int变量写入*/
file_pos_write(file, pos);
/*释放file结构体指针*/
fput_light(file, fput_needed);
}
 
 
return ret;
}

read()_第2张图片

你可能感兴趣的:(架构)