/**
* register_chrdev() - Register a major number for character devices. 为字符设备注册一个主设备号
* @major: major device number or 0 for dynamic allocation;当
major 参数=0时,为动态分分配
* @name: name of this range of devices; 暂时没有发现这个参数的作用
* @fops: file operations associated with this devices 设备操作相关的函数映射
*
* If @major == 0 this functions will dynamically allocate a major and return
* its number.
*
* If @major > 0 this function will attempt to reserve a device with the given
* major number and will return zero on success.
*
* Returns a -ve errno on failure.
失败返回负数
*
* The name of this device has nothing to do with the name of the device in
* /dev. It only helps to keep track of the different owners of devices. If
* your module name has only one type of devices it's ok to use e.g. the name
* of the module here.
*
;这里的name 和/dev 下的name 没有任何关系,mknod
/dev 下的名字和:
firstdrv_class_dev = class_device_create(firstdrv_class, NULL, MKDEV(major, 0), NULL, "xyz");
这个函数中的“最后一个参数有关,udev”
/* /dev/xyz */
* This function registers a range of 256 minor numbers. The first minor number
* is 0.
*/
register_chrdev()
函数是老版本里面的设备号注册函数,可以实现静态和动态注册两种方法,主要是通过给定的主设备号是否为0来进行区别,为0的时候为动态注册。
而register_chrdev_region以及alloc_chrdev_region就是将上述函数的静态和动态注册设备号进行了拆分的强化。
尤其需要注alloc_chrdev_region()函数中,函数原型为int alloc_chrdev_region(dev_t *dev, unsigned int firstminor,unsigned int count, char *name)
这个是用来存放动态分配后,根据所得的主设备号和预设的第一个设备号所组合出来的----设备号。
阅读(2174) | 评论(0) | 转发(0) |