【发布时间】:2021-07-17 01:33:33
【问题描述】:
(所有sn-ps代码均取自:https://docs.huihoo.com/doxygen/linux/kernel/3.7/dir_97b3d2b63ac216821c2d7a22ee0ab2b0.html)
嗨!为了确定我的问题,我一直在研究 Linux fs 代码近一个月来进行研究,但我被困在这里。所以我正在查看include/linux/fs.h 中的这段代码(如果我没记错的话,几乎所有主要结构和指针的定义都被read_write.c 和open.c 等代码使用)并且我观察到这段代码sn-p:
struct file_operations {
1519 struct module *owner;
1520 loff_t (*llseek) (struct file *, loff_t, int);
1521 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
1522 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
1523 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
1524 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
1525 int (*readdir) (struct file *, void *, filldir_t);
1526 unsigned int (*poll) (struct file *, struct poll_table_struct *);
1527 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
1528 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
1529 int (*mmap) (struct file *, struct vm_area_struct *);
1530 int (*open) (struct inode *, struct file *);
1531 int (*flush) (struct file *, fl_owner_t id);
1532 int (*release) (struct inode *, struct file *);
1533 int (*fsync) (struct file *, loff_t, loff_t, int datasync);
1534 int (*aio_fsync) (struct kiocb *, int datasync);
1535 int (*fasync) (int, struct file *, int);
1536 int (*lock) (struct file *, int, struct file_lock *);
1537 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
1538 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
1539 int (*check_flags)(int);
1540 int (*flock) (struct file *, int, struct file_lock *);
1541 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
1542 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
1543 int (*setlease)(struct file *, long, struct file_lock **);
1544 long (*fallocate)(struct file *file, int mode, loff_t offset,
1545 loff_t len);
1546 };
在这里,您可以看到他们已经定义了这些非常具体的系统调用,这些系统调用已在各自的文件中声明。例如 read_write.c 的 read 和 write 系统调用定义分别为 SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count) 和 SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf, size_t, count)。现在出于研究目的,我基本上进入了这两个定义,并追查了每个函数调用(至少是那些在 Doxygen 文档中链接的)发生在它们中的每个函数以及这些函数调用中但无法回答的函数调用一个非常简单的问题。 这两个系统调用如何调用虚拟文件系统以进一步调用从文件系统读取实际数据块所需的驱动程序? (如果它是特定于文件系统的,那么请告诉我代码中将其交给 FS 驱动程序的位置)
附:我对打开的系统调用进行了同样的搜索,但能够找到他们调用namei.c 代码的一部分以专门执行该任务的位置:struct file *do_filp_open(int dfd, struct filename *pathname, const struct open_flags *op, int flags)。在这里,他们使用具有来自 inode 的相关信息的结构 nameidata 来打开文件。
【问题讨论】:
标签: c linux-kernel filesystems vfs