LDD3 Chapter3 分配主设备号测试代码

mail:[email protected]

qq:196568501

author:DriveMonkey

phone:13410905075


#include <linux/init.h>
#include <linux/module.h>
#include <linux/cdev.h>
#include <linux/fs.h>

MODULE_LICENSE("Dual BSD/GPL");


static dev_t g_dev = 0; 

static int mmap_init(void)
{
	dev_t dev = MKDEV(300,0);
	
	printk("mmap_init()++\n");
	
	printk("major = %d, minor = %d\n", MAJOR(dev),MINOR(dev));
	
	if(0 != register_chrdev_region(dev,2,"Hello_world"))
		printk("Hello_world device error\n");
	if(0 != alloc_chrdev_region(&g_dev, 0,1, "Hello_world1"))
		printk("Hello_world device error1\n");

	printk("major = %d, minor = %d\n", MAJOR(g_dev),MINOR(g_dev));
	
	printk("mmap_init()--\n");
	
	return 0;
}

static void mmap_exit(void)
{
	printk("mmap_exit()++\n");
	unregister_chrdev_region(MKDEV(300,0),2);
	unregister_chrdev_region(g_dev,1);
	printk("mmap_exit()--\n");
}

module_init(mmap_init);
module_exit(mmap_exit);


你可能感兴趣的:(LDD3 Chapter3 分配主设备号测试代码)