我正在實現一個Linux字符設備驅動程序。什麼是「struct file_operations」參數?
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寫入時起就有所改變。
這些是我平常看的地方。我正在編寫和記錄如何爲其他人編寫設備驅動程序,並且我完全無法告訴他們如何查找此信息。我試圖贏得人心和思考,並向他們展示Linux有價值,但當我無法向他們展示設備驅動程序最有價值結構的完整或最新文檔時,這令人感到尷尬! 我知道要看其他驅動程序,並試圖「解決」,但我認爲這不夠好。 – 2013-03-04 19:51:57
不幸的是,這是它的工作方式。最接近您要查找的文檔是LDD在鼎盛時期,但是(正如「3」所證明的),它試圖描述的系統變化很快,並沒有跟上。也許最好的解決方法是挖掘內核新聞並更新他們的描述? – vonbrand 2013-03-04 20:01:31
我覺得可能是這種情況,認爲值得檢查是我最後一次嘗試。我記得在2.4系統被2.6系統淘汰時使用了LDD3。即使我正在關注本書中的示例,在移植較舊的設備驅動程序時,我收到「已棄用」警告的時間也不長。我已經有好幾年不必做Linux設備驅動程序開發了,所以我正處於開始運行和學習在工作階段。我希望不再是這種情況。 – 2013-03-05 10:24:19