file_operations下函數詳解
struct file_operations{
struct module *owner;
// 指向擁有該結構的模塊的指針,避免正在操作時(shí)被卸載,一般為初始化為T(mén)HIS_MODULES
loff_t (*llseek) (struct file *, loff_t, int);
// llseek用來(lái)修改文件當前的讀寫(xiě)位置,返回新位置
// loff_t為一個(gè)長(cháng)偏移量。當此函數指針為空,seek調用將會(huì )以不可預期的方式修改file結構中的位置計數器。
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
// 從設備中同步讀取數據。讀取成功返回讀取的字節數。設置為NULL,調用時(shí)返回-EINVAL
ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t);
// 初始化一個(gè)異步的讀取操作,為NULL時(shí)全部通過(guò)read處理
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
// 向設備發(fā)送數據。
ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t);
// 初始化一個(gè)異步的寫(xiě)入操作。
int (*readdir) (struct file *, void *, filldir_t);
// 僅用于讀取目錄,對于設備文件,該字段為 NULL
unsigned int (*poll) (struct file *, struct poll_table_struct *);
// 返回一個(gè)位掩碼,用來(lái)指出非阻塞的讀取或寫(xiě)入是否可能。
// 將pool定義為 NULL,設備會(huì )被認為即可讀也可寫(xiě)。
int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
// 提供一種執行設備特殊命令的方法。不設置入口點(diǎn),返回-ENOTTY
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
// 不使用BLK的文件系統,將使用此種函數指針代替ioctl
long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
// 在64位系統上,32位的ioctl調用,將使用此函數指針代替
int (*mmap) (struct file *, struct vm_area_struct *);
// 用于請求將設備內存映射到進(jìn)程地址空間。如果無(wú)此方法,將訪(fǎng)問(wèn)-ENODEV。
int (*open) (struct inode *, struct file *);
// 如果為空,設備的打開(kāi)操作永遠成功,但系統不會(huì )通知驅動(dòng)程序
// 由VFS調用,當VFS打開(kāi)一個(gè)文件,即建立了一個(gè)新的struct file,之后調用open方法分配文件結構。open屬于struct
inode_operations。
int (*flush) (struct file *);
// 發(fā)生在進(jìn)程關(guān)閉設備文件描述符副本,執行并等待,若設置為NULL,內核將忽略用戶(hù)應用程序的請求。
int (*release) (struct inode *, struct file *);
// file結構釋放時(shí),將調用此指針函數,release與open相同可設置為NULL
int (*fsync) (struct file *, struct dentry *, int datasync);
評論