Create a device node in Linux -- class_creat ()

Source: Internet
Author: User

After a Linux kernel version of 2.6, devfs no longer exists, and udev becomes a replacement for devfs. Compared with devfs, udev has many advantages, so it won't be long-winded here. Note that udev is the application layer, so do not try to find it in the Kernel configuration options; it is very easy to add udev support, take the character Device Driver written by the author as an example.CodeCall class_create to create a class for the device, and then call
Class_device_create: create a device. The general usage is as follows:

Struct class * myclass = class_create (this_module, "my_device_driver ");

Class_device_create (myclass, null, mkdev (major_num, 0), null, "my_device ");

When such a module is loaded , Udev daemon will automatically create the my_device file under/dev .


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.

Create a class directory under/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 shoshould be registered.

@ 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

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.