abstract:Linux混雜設備是字符設備的一類,主要是混雜設備擁有相同的主設備號(10),但是次設備號是不同的。所有的混雜設備行程一個鏈表,對設備訪問時內(nèi)核更據(jù)次設備號查找到相應的混雜設備?;祀s設備用struct miscdevice來描述一個混雜設備。struct miscdevice { int minor; /*
Linux混雜設備是字符設備的一類,主要是混雜設備擁有相同的主設備號(10),但是次設備號是不同的。所有的混雜設備行程一個鏈表,對設備訪問時內(nèi)核更據(jù)次設備號查找到相應的混雜設備。
混雜設備用struct miscdevice來描述一個混雜設備。
struct miscdevice { int minor; /*次設備號*/ const char *name; /*設備名*/ const struct file_operations *fops; /*文件操作 其他由內(nèi)核來完成*/ struct list_head list; struct device *parent; struct device *this_device; const char *nodename; mode_t mode; };
首先初始化結構體struct miscdevice
初始化struct file_operations *
完成 struct file_operations * 對應的函數(shù)
在模塊初始化函數(shù)中,注冊設備驅動mis_register()即可
注銷mis_deregister()
#include <linux/miscdevice.h>