Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux kernel 在寄存器chrdev_区域中使用count变量_Linux Kernel_Linux Device Driver_Kernel Module_Drivers - Fatal编程技术网

Linux kernel 在寄存器chrdev_区域中使用count变量

Linux kernel 在寄存器chrdev_区域中使用count变量,linux-kernel,linux-device-driver,kernel-module,drivers,Linux Kernel,Linux Device Driver,Kernel Module,Drivers,据我所知,寄存器chrdev\u区域的签名描述如下 extern int register_chrdev_region(dev_t firstmajor,unsigned int count,const char*dev_name); //firstmajor: The major number requested for reservation of the dirver //dev_name: Name of the device associated with the major numb

据我所知,
寄存器chrdev\u区域的签名描述如下

extern int register_chrdev_region(dev_t firstmajor,unsigned int count,const char*dev_name);
//firstmajor: The major number requested for reservation of the dirver
//dev_name: Name of the device associated with the major number(for procfs and sysfs)
//count: Total number of contagious device numbes that is requested??
我没有在函数中使用
count
arguement(在
alloc\u chrdev\u区域中也是如此)。请解释一个为驾驶员保留传染性设备编号的简单用例

参考第3.2.2节中的评论说:

/**     
 * alloc_chrdev_region() - register a range of char device numbers
 * @dev: output parameter for first assigned number
 * @baseminor: first of the requested range of minor numbers
 * @count: the number of minor numbers required
 * @name: the name of the associated device or driver
 *      
 * Allocates a range of char device numbers.  The major number will be
 * chosen dynamically, and returned (along with the first minor number)
 * in @dev.  Returns zero or a negative error code.
 */
您可以在fs/fuse/cuse.c中找到一个示例:

/* determine and reserve devt */
devt = MKDEV(arg->dev_major, arg->dev_minor);
if (!MAJOR(devt))
        rc = alloc_chrdev_region(&devt, MINOR(devt), 1, devinfo.name);
else
        rc = register_chrdev_region(devt, 1, devinfo.name);
if (rc) {
        printk(KERN_ERR "CUSE: failed to register chrdev region\n");
        goto err;
}
评论说:

/**     
 * alloc_chrdev_region() - register a range of char device numbers
 * @dev: output parameter for first assigned number
 * @baseminor: first of the requested range of minor numbers
 * @count: the number of minor numbers required
 * @name: the name of the associated device or driver
 *      
 * Allocates a range of char device numbers.  The major number will be
 * chosen dynamically, and returned (along with the first minor number)
 * in @dev.  Returns zero or a negative error code.
 */
您可以在fs/fuse/cuse.c中找到一个示例:

/* determine and reserve devt */
devt = MKDEV(arg->dev_major, arg->dev_minor);
if (!MAJOR(devt))
        rc = alloc_chrdev_region(&devt, MINOR(devt), 1, devinfo.name);
else
        rc = register_chrdev_region(devt, 1, devinfo.name);
if (rc) {
        printk(KERN_ERR "CUSE: failed to register chrdev region\n");
        goto err;
}

Count是分配给此主要号码或此驱动程序的次要号码数 在创建设备节点时,用户有责任使用允许的次要编号(应小于计数)创建设备节点。

例: 若我们创建第一个数字为0、计数为2的驱动程序,内核会将0到2个小数字分配给这个驱动程序。 但用户仍然可以创建次要编号大于2的设备节点。
如果次要编号大于2,内核将无法访问该设备节点的驱动程序,因为该次要编号未注册,因此当您要在该设备节点上执行文件操作时,它无法打开设备节点并抛出错误

Count是分配给此主要号码或此驱动程序的次要号码数 在创建设备节点时,用户有责任使用允许的次要编号(应小于计数)创建设备节点。

例: 若我们创建第一个数字为0、计数为2的驱动程序,内核会将0到2个小数字分配给这个驱动程序。 但用户仍然可以创建次要编号大于2的设备节点。 如果次要编号大于2,内核将无法访问该设备节点的驱动程序,因为该次要编号未注册,因此当您要在该设备节点上执行文件操作时,它无法打开设备节点并抛出错误