|
static int __init demo_init(void)
{
int result;
wbuff = kmalloc(BUFFSIZE, GFP_KERNEL);
rbuff = kmalloc(BUFFSIZE, GFP_KERNEL);
result = register_chrdev(DEMO_MAJOR, "demo", &demo_fops);
if(result < 0) {
printk(KERN_ERR "Cannot register demo device.\n");
kfree(wbuff);
kfree(rbuff);
return -EIO;
}
if(DEMO_MAJOR==0)
DEMO_MAJOR = result;
/*devfs*/
#ifdef CONFIG_DEVFS_FS
devfs_demo_dir = devfs_mk_dir(NULL, "demo", NULL); //make demo device directory
devfs_demoraw = devfs_register(devfs_demo_dir, "0", DEVFS_FL_DEFAULT,
DEMO_MAJOR, DEMO_MINOR, S_IFCHR | S_IRUSR | S_IWUSR,
&demo_fops, NULL); //register demo device "0"
#endif
/* some furthertreatment for this case */
return 0;
}
以上是一个驱动程序的初始化函数,在此函数前面已经定义了“CONFIG_DEVFS_FS”宏,请问高手为什么要用devfs_register()和register_chrdev()两个注册??只用register_chrdev()函数不就可以动态的选定一个主设备号吗?为什么还要用devfs_register()函数再注册一变???这两个注册函数有什么区别阿???谢谢…… |
|