Linux字符设备动态申请设备号

独自空忆成欢 提交于 2019-12-10 00:55:25

alloc_chrdev_region是一个函数语句,头文件是<linux/fs.h>,可以动态分配设备编号。int alloc_chrdev_region(dev_t *dev,unsigned int -firstminor,unsigned int -count,char *name);

dev_t *dev:用于返回的设备号参数
unsigned int -firstminor:默认为0
unsigned int -count:请求连续设备号的个数
char *name:待注册的设备名称在不再使用时释放这些设备编号void unregister_chrdev_region(dev_t from, unsigned int count);

 

////////////////////////////////////////////////////////////////////////
dev_t dev = 0;

ret = alloc_chrdev_region(&dev, 0, 1,DEVICE_NAME);

if(ret<0)
{ 
    printk(KERN_ERR "register_chrdev_region error\r\n"); goto alloc_err; 
}

///////////////////////////////////////////////////////////////////////

  

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!