gpt4 book ai didi

linux - "struct file_operations"参数是什么?

转载 作者:IT王子 更新时间:2023-10-29 00:26:42 27 4
gpt4 key购买 nike

我正在实现一个 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 时发生了变化。

最佳答案

LDD3 这本书对于了解大局仍然非常有用,但对细节没有帮助(它适用于内核 2.6.10,同时我们正在向 3.9 迈进)。 kernelnewbies drivers page可能是最新、最全面的资源。对于日常更改,LWN定期对 API 更改发表评论,并为新功能发布更长的概述。 H-online载有一系列文章,详细介绍了内核版本之间的变化,以及讨论和补丁的链接。

关于linux - "struct file_operations"参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15213932/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com