日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 嵌入式 > 嵌入式教程
[導(dǎo)讀]file_operations下函數(shù)詳解

struct file_operations{
    
    struct module *owner;
    
    // 指向擁有該結(jié)構(gòu)的模塊的指針,避免正在操作時(shí)被卸載,一般為初始化為THIS_MODULES
    
    loff_t (*llseek) (struct file *, loff_t, int);
    
    // llseek用來修改文件當(dāng)前的讀寫位置,返回新位置
    
    // loff_t為一個(gè)"長(zhǎng)偏移量"。當(dāng)此函數(shù)指針為空,seek調(diào)用將會(huì)以不可預(yù)期的方式修改file結(jié)構(gòu)中的位置計(jì)數(shù)器。
    
    ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
    
    // 從設(shè)備中同步讀取數(shù)據(jù)。讀取成功返回讀取的字節(jié)數(shù)。設(shè)置為NULL,調(diào)用時(shí)返回-EINVAL
    
    ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t);
    
    // 初始化一個(gè)異步的讀取操作,為NULL時(shí)全部通過read處理
    
    ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
    
    // 向設(shè)備發(fā)送數(shù)據(jù)。
    
    ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t);
    
    // 初始化一個(gè)異步的寫入操作。
    
    int (*readdir) (struct file *, void *, filldir_t);
    
    // 僅用于讀取目錄,對(duì)于設(shè)備文件,該字段為 NULL
    
    unsigned int (*poll) (struct file *, struct poll_table_struct *);
    
    // 返回一個(gè)位掩碼,用來指出非阻塞的讀取或?qū)懭胧欠窨赡堋?br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px; word-wrap: break-word" />     
    // 將pool定義為 NULL,設(shè)備會(huì)被認(rèn)為即可讀也可寫。
    
    int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
    
    // 提供一種執(zhí)行設(shè)備特殊命令的方法。不設(shè)置入口點(diǎn),返回-ENOTTY
    
    long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
    
    // 不使用BLK的文件系統(tǒng),將使用此種函數(shù)指針代替ioctl
    
    long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
    
    // 在64位系統(tǒng)上,32位的ioctl調(diào)用,將使用此函數(shù)指針代替
    
    int (*mmap) (struct file *, struct vm_area_struct *);
    
    // 用于請(qǐng)求將設(shè)備內(nèi)存映射到進(jìn)程地址空間。如果無(wú)此方法,將訪問-ENODEV。
    
    int (*open) (struct inode *, struct file *);
    
    // 如果為空,設(shè)備的打開操作永遠(yuǎn)成功,但系統(tǒng)不會(huì)通知驅(qū)動(dòng)程序
    
    // 由VFS調(diào)用,當(dāng)VFS打開一個(gè)文件,即建立了一個(gè)新的"struct file",之后調(diào)用open方法分配文件結(jié)構(gòu)。open屬于struct
    
    inode_operations。
    
    int (*flush) (struct file *);
    
    // 發(fā)生在進(jìn)程關(guān)閉設(shè)備文件描述符副本,執(zhí)行并等待,若設(shè)置為NULL,內(nèi)核將忽略用戶應(yīng)用程序的請(qǐng)求。
    
    int (*release) (struct inode *, struct file *);
    
    // file結(jié)構(gòu)釋放時(shí),將調(diào)用此指針函數(shù),release與open相同可設(shè)置為NULL
    
    int (*fsync) (struct file *, struct dentry *, int datasync);[!--empirenews.page--]
    
    // 刷新待處理的數(shù)據(jù),如果驅(qū)動(dòng)程序沒有實(shí)現(xiàn),fsync調(diào)用將返回-EINVAL
    
    int (*aio_fsync) (struct kiocb *, int datasync);
    
    // 異步fsync
    
    int (*fasync) (int, struct file *, int);
    
    // 通知設(shè)備FASYNC標(biāo)志發(fā)生變化,如果設(shè)備不支持異步通知,該字段可以為NULL
    
    int (*lock) (struct file *, int, struct file_lock *);
    
    // 實(shí)現(xiàn)文件鎖,設(shè)備驅(qū)動(dòng)常不去實(shí)現(xiàn)此lock
    
    ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
    
    ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
    
    // readv和writev 分散/聚集型的讀寫操作,實(shí)現(xiàn)進(jìn)行涉及多個(gè)內(nèi)存區(qū)域的單次讀或?qū)懖僮鳌?br style="padding-right: 0px; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px; word-wrap: break-word" />     
    ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *);
    
    // 實(shí)現(xiàn)sendfile調(diào)用的讀取部分,將數(shù)據(jù)從一個(gè)文件描述符移到另一個(gè),設(shè)備驅(qū)動(dòng)通常將其設(shè)置為 NULL
    
    ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
    
    // 實(shí)現(xiàn)sendfile調(diào)用的另一部分,內(nèi)核調(diào)用將其數(shù)據(jù)發(fā)送到對(duì)應(yīng)文件,每次一個(gè)數(shù)據(jù)頁(yè),設(shè)備驅(qū)動(dòng)通常將其設(shè)置為NULL
    
    unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned
    
    long);
    
    // 在進(jìn)程地址空間找到一個(gè)合適的位置,以便將底層設(shè)備中的內(nèi)存段映射到該位置。大部分驅(qū)動(dòng)可將其設(shè)置為NULL
    
    int (*check_flags)(int);
    
    // 允許模塊檢查傳遞給fcntl(F_SETEL…)調(diào)用的標(biāo)志
    
    int (*dir_notify)(struct file *filp, unsigned long arg);
    
    // 應(yīng)用程序使用fcntl來請(qǐng)求目錄改變通知時(shí),調(diào)用該方法。僅對(duì)文件系統(tǒng)有效,驅(qū)動(dòng)程序不必實(shí)現(xiàn)。
    
    int (*flock) (struct file *, int, struct file_lock *);
    
    // 實(shí)現(xiàn)文件鎖
    
    };

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉