container_of宏定義

<linux/kernel.h>

#define      container_of ( ptr,  type,  member)              … …

指針ptr指向結構體type中的成員member,已知指針ptr,計算結構體type的起始地址。


structscull_pipe {

            wait_queue_head_t inq, outq;

            char *buffer, *end;

            int buffersize;

            char *rp, *wp;

            int nreaders, nwrites;

            struct semaphore sem;

            struct cdev cedv;

};

例如,結構體scull_pipe中封裝了結構cdev,已知cdev的地址,計算scull_pipe的地址。

container_of(inode->i_cdev, struct scull_pipe,  cdev)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章