歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> Linux設備驅動(3)常用的宏、結構體、數據類型、函數等

Linux設備驅動(3)常用的宏、結構體、數據類型、函數等

日期:2017/3/3 13:03:13   编辑:Linux技術

struct file

重要成員mode_t f_mode:文件模式,可讀(FMODE_READ)?可寫(FMODE_WRITE)?

loff_t f_pos:這是用來記錄文件的偏移量。在應用程序中,打開文件時偏移量為0,每次的讀寫操作都會使偏移量增加;

void *private_data:

struct file_operations *fops:打開文件後,內核會把fops存放在這裡,以後的操作就在這裡在這裡找函數了

unsigned int f_flags : 文件標志,如阻塞非阻塞等;

struct dentry *f_dentry:文件對應的目錄項。可以用filp->f_dentry->d_inode的方式來訪問索引節點。

container_of

[code]/**
 * container_of - cast a member of a structure out to the containing structure
 * @ptr:    the pointer to the member.成員的指針
 * @type:   the type of the container struct this is embedded in.結構體類型
 * @member: the name of the member within the struct.成員
 *
 */
#define container_of(ptr, type, member) ({          \
    const typeof(((type *)0)->member) * __mptr = (ptr); \
    (type *)((char *)__mptr - offsetof(type, member)); })
通過一個結構體成員的指針,獲得這個結構體的指針

Copyright © Linux教程網 All Rights Reserved