我正在实现一个Linux字符设备驱动程序。
linux/fs.h头文件列出没有参数名称的file_operations。
例如:
struct file_operations {
struct module *owner;
loff_t (*llseek) (struct file *, loff_t, int);
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
int (*readdir) (struct file *, void *, filldir_t);
unsigned int (*poll) (struct file *, struct poll_table_struct *);
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*flush) (struct file *, fl_owner_t id);
int (*release) (struct inode *, struct file *);
int (*fsync) (struct file *, loff_t, loff_t, int datasync);
int (*aio_fsync) (struct kiocb *, int datasync);
int (*fasync) (int, struct file *, int);
int (*lock) (struct file *, int, struct file_lock *);
ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
int (*check_flags)(int);
int (*flock) (struct file *, int, struct file_lock *);
ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
int (*setlease)(struct file *, long, struct file_lock **);
long (*fallocate)(struct file *file, int mode, loff_t offset,
loff_t len);
};告诉我每个参数是什么的文档在哪里?有些是很明显的,但有些则不是。如果可以的话,我更喜欢参考官方文件,但我就是找不到。
例如:
int (*fsync) (struct file *, loff_t, loff_t, int datasync);有两个loff_t参数。我怎么知道他们是干什么的?
我一直在谷歌上搜索和阅读设备驱动程序手册,但是我找不到任何文件来解释这些论点是为了什么。与编写LDD3时相比,有些参数也发生了变化。
发布于 2013-03-04 17:11:17
LDD3的书对于理解全局仍然是非常有用的,但是它不会对细节有所帮助(这是针对2.6.10内核的,同时我们正在向3.9迈进)。内核新手驱动程序页面也许是最最新、最全面的资源。对于日常的变化,LWN定期评论API的变化,并发布更长的新特性概述。H-联机提供了一系列文章,详细介绍了从内核版本到内核版本的更改,并提供了讨论和补丁的链接。
发布于 2013-03-05 12:56:31
不久前,我不得不实现我的第一个linux驱动程序。到目前为止,我认为您能做的最好的事情就是下载您正在开发的版本的内核源代码。在内核源代码树中有一个名为/Documentation的目录。我从这里开始,最后我检查了一下这是内核的“正式文档”。
也就是说,一旦您有了源代码,就没有比阅读代码和查看它的用途更好的文档了。对于这种情况,我会查看/drivers/fs/,并找到这个结构在何处使用的示例,并查看它们是如何使用的。
发布于 2020-07-11 14:42:22
现在,在文档/文件系统/vfs.rst:https://www.kernel.org/doc/html/latest/filesystems/locking.html#file-operations上也有一些最小的树内文档,但是它并没有说出从签名中不明显的任何东西。他们应该把这些东西写在Doxygen的评论上。
我还在:https://github.com/cirosantilli/linux-kernel-module-cheat/tree/9be19ae1cf3f3f346a5bc25f4a4d1e1cbac23cb3#file-operations中保留了几个可运行的示例,这些示例可能会引起人们的兴趣。
https://stackoverflow.com/questions/15213932
复制相似问题