[Linux Driver] device driver model related (ii)--Common API

Source: Internet
Author: User

1, create a device node in the/sys/class/directory, such as creating a CLASS_TEST_USB device node

[CPP]View Plaincopy
    1. Static struct CALSS *test_class;
    2. Test_class = Class_creat (This_module,"Class_test_usb");


2, create another device node in the CLASS_TEST_USB directory android0, as follows

[CPP]View Plaincopy
    1. struct device *dev;
    2. dev = device_creat (Test_calss,null,mkdev (0,0), NULL,"android0");
    3. if (Is_err (dev))
    4. return Ptr_err (dev);


3, create several other device nodes in the/sys/class/class_test_usb/android0/directory enable state, etc.

[CPP]View Plaincopy
    1. Static struct device_attribute* test_attributes[]={
    2. &dev_attr_state,
    3. &dev_attr_enable,
    4. Null
    5. }
    6. Static Device_attr (Enable,s_irugo | S_iwusr,enable_show,enable_store);
    7. struct Device_attribute * * attrs=test_attributes;
    8. struct Device_attribute *attr;
    9. int err;
    10. while ((attr=*attrs++))
    11. {
    12. Err=device_creat_file (DEV,ATTR);
    13. if (err)
    14. {
    15. Device_destory (TEST_CLASS,DEV->DEVT);
    16. return err;
    17. }
    18. }

[Linux Driver] device driver model related (ii)--Common API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.