2.4内核引入
优点:
设备初始化时在/dev下创建设备文件,卸载时候删除
可以指定设备名,所有者,权位,
可以不需要分配主设备号
static devfs_handle_t devfs_handle;
static int __init xxx_init(void)
{
int ret;
int i;
ret = register_chrdev(XXX_MAJOR,DEVICE_NAME, &xxx_fops);
if(ret<0)
{
printk(DEVICE_NAME "cant register major num/n");
retrun ret;
}
devfs_handle = devfs_register(devfs_handle_t dir, DEVICE_NAME,DEVFS_FLAG,xxx_MAJOR
,0,S_IFCHR|S_IRUSR|S_IWUSR, &xxx_fops, void * info);
return 0;
}
static void __eixt xxx_exit(void)
{
devfs_unregister(devfs_handle);
unregister_chrdev(XXX_MAJOR,DEVICE_NAME);
}
文章出处:http://www.diybl.com/course/6_system/linux/Linuxjs/2008628/129012.html