使用register_chrdev函数为动态分配的主设备号指定256个次设备号是否有重要意义?
To dynamically assign a major number I use register_chrdev function defined in kernel
static inline int register_chrdev(unsigned int major, const char *name, const struct file_operations *fops) { return __register_chrdev(major, 0, 256, name, fops); }
__register_chrdev now will assign a dynamic major number if value of major passed as argument is 0.This particular operation has following source code in kernel
if (major == 0) { for (i = ARRAY_SIZE(chrdevs)-1; i > 0; i--) { if (chrdevs[i] == NULL) break; }
chrdev is an array of pointers to struct char_device_struct *chrdevs[CHRDEV_MAJOR_HASH_SIZE];
Macro CHRDEV_MAJOR_HASH_SIZE is of size 255
5.ARRAY_SIZE(chrdevs)将返回*chrdevs数组的大小,考虑到struct char_device_struct结构体的大小为84字节,因此数组大小是5334(对我的错误数学计算表示歉意)。
问题:这可能是一个愚蠢的问题,但为什么自动分配了256个次设备号?
上面的源代码片段来自linux-3.6.7内核文件:fs/char_dev.c