1,在/sys/class/目录下创建一个设备节点,比如创建一个class_test_usb的设备节点
[cpp] view plaincopy
- static struct calss *test_class;
- test_class = class_creat(THIS_MODULE,"class_test_usb");
2,在class_test_usb目录下创建另外一个设备节点android0,如下
[cpp] view plaincopy
- struct device *dev;
- dev = device_creat(test_calss,NULL,MKDEV(0,0),NULL,"android0");
- if(IS_ERR(dev))
- return PTR_ERR(dev);
3,在/sys/class/class_test_usb/android0/目录下创建几个其它设备节点enable state等
[cpp] view plaincopy
- static struct device_attribute* test_attributes[]={
- &dev_attr_state,
- &dev_attr_enable,
- NULL
- }
- static DEVICE_ATTR(enable,S_IRUGO |S_IWUSR,enable_show,enable_store);
- struct device_attribute ** attrs=test_attributes;
- struct device_attribute *attr;
- int err;
- while((attr=*attrs++))
- {
- err=device_creat_file(dev,attr);
- if(err)
- {
- device_destory(test_class,dev->devt);
- return err;
- }
- }
时间: 2024-10-10 13:27:40