class_create和class_device_create
生活随笔
收集整理的這篇文章主要介紹了
class_create和class_device_create
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//主要是在/sys/class/ 下創建一個 “name”的文件夾 !從linux內核2.6的某個版本之后,devfs不復存在,udev成為devfs的替代。相比devfs,udev有很多優勢,在此就不羅嗦了,提醒一點,udev是應用層的東東,不要試圖在內核的配置選項里找到它;加入對udev的支持很簡單,以作者所寫的一個字符設備驅動為例,在驅動初始化的代碼里調用class_create為該設備創建一個class,再為每個設備調用 class_device_create創建對應的設備。大致用法如下:
struct class *myclass = class_create(THIS_MODULE, “my_device_driver”);
class_device_create(myclass, NULL, MKDEV(major_num, 0), NULL, “my_device”);
這樣的module被加載時,udev daemon就會自動在/dev下創建my_device設備文件。class_create()
-------------------------------------------------
linux-2.6.22/include/linux/device.h
struct class *class_create(struct module *owner, const char *name)class_create - create a struct class structure@owner: pointer to the module that is to "own" this struct class@name: pointer to a string for the name of this class.
在/sys/class/下創建類目錄class_device_create()
-------------------------------------------------
linux-2.6.22/include/linux/device.h
struct class_device *class_device_create(struct class *cls,struct class_device *parent,dev_t devt,struct device *device,const char *fmt, ...)class_device_create - creates a class device and registers it with sysfs@cls: pointer to the struct class that this device should be registered to.@parent: pointer to the parent struct class_device of this new device, if any.@devt: the dev_t for the char device to be added.@device: a pointer to a struct device that is assiociated with this class device.@fmt: string for the class device's name
//主要是在/sys/class/ 下創建一個 “name”的文件夾 !從linux內核2.6的某個版本之后,devfs不復存在,udev成為devfs的替代。相比devfs,udev有很多優勢,在此就不羅嗦了,提醒一點,udev是應用層的東東,不要試圖在內核的配置選項里找到它;加入對udev的支持很簡單,以作者所寫的一個字符設備驅動為例,在驅動初始化的代碼里調用class_create為該設備創建一個class,再為每個設備調用 class_device_create創建對應的設備。大致用法如下:
struct class *myclass = class_create(THIS_MODULE, “my_device_driver”);
class_device_create(myclass, NULL, MKDEV(major_num, 0), NULL, “my_device”);
這樣的module被加載時,udev daemon就會自動在/dev下創建my_device設備文件。class_create()
-------------------------------------------------
linux-2.6.22/include/linux/device.h
struct class *class_create(struct module *owner, const char *name)class_create - create a struct class structure@owner: pointer to the module that is to "own" this struct class@name: pointer to a string for the name of this class.
在/sys/class/下創建類目錄class_device_create()
-------------------------------------------------
linux-2.6.22/include/linux/device.h
struct class_device *class_device_create(struct class *cls,struct class_device *parent,dev_t devt,struct device *device,const char *fmt, ...)class_device_create - creates a class device and registers it with sysfs@cls: pointer to the struct class that this device should be registered to.@parent: pointer to the parent struct class_device of this new device, if any.@devt: the dev_t for the char device to be added.@device: a pointer to a struct device that is assiociated with this class device.@fmt: string for the class device's name
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎
總結
以上是生活随笔為你收集整理的class_create和class_device_create的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 性能优化专题 - MySql 性能优化
- 下一篇: 时间序列预测算法----Prophet