Only one device can be seen in/proc/devices. Why?

Source: Internet
Author: User
Only one device can be seen in/proc/devices. Why?

# Include <Linux/module. h>
# Include <Linux/types. h>
# Include <Linux/init. h>
# Include <Linux/fs. h>
# Include <Linux/cdev. h>
# Include <Linux/kdev_t.h>
# Include <Linux/string. h>

# Define device_name "chardev"
# Define device_num 5

Static dev_t devno;

Static int _ init test_init (void)
{
Int ret;

Ret = alloc_chrdev_region (& devno, 0, device_num, device_name );
If (Ret <0)
Goto err;

Err:
Return ret;
}

Static void _ exit test_exit (void)
{
Unregister_chrdev_region (devno, 5 );
}

Module_license ("GPL ");

Module_init (test_init );
Module_exit (test_exit );

Your alloc_chrdev_region (& devno, 0, device_num, device_name); generates five device numbers under a master device number, which is equivalent to sharing one master device number with five similar devices, each device has its own device number, and only the master device number is displayed in/proc/devices!

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.