|
楼主 |
发表于 2007-10-12 18:45:19
|
显示全部楼层
写了个小程序测试了一下, 当count < 1048576时, for循环只执行一次, 并且分别
1048576 - MINOR(n)个设备.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kdev_t.h>
MODULE_LICENSE("Dual BSD/GPL");
static int howmany = 1;
static char* whom = "world";
module_param(howmany, int, S_IRUGO);
module_param(whom, charp, S_IRUGO);
void register_chrdev_region_test(dev_t from, unsigned count)
{
dev_t to = from + count;
dev_t n, next;
int i;
i = 1;
printk(KERN_ALERT"from = %d, count = %d, to = %d\n", from, count, to);
for (n = from; n < to; n = next)
{
next = MKDEV(MAJOR(n)+1, 0);
printk(KERN_ALERT"next = %d , i = %d, next -n = %d, ", next, i, next - n);
if (next > to)
{
next = to;
printk(KERN_ALERT"next > to is true\n");
}
i++;
}
}
static int __init hello_init(void)
{
int i;
printk(KERN_ALERT"Hello, world, howmany = %d, whom = %s\n", howmany, whom);
for (i=0; i<howmany; i++)
printk(KERN_ALERT"Hello, %s, i = %d\n", whom, i);
/*printk(KERN_INFO"Hello, %s, i = %d\n", whom, i);*/
printk(KERN_ALERT"Hello, world2, howmany = %d, whom = %s\n", howmany, whom);
i = MKDEV(1, 1);
printk(KERN_ALERT"dev_t i = %d\n", i);
i = MKDEV(5, 3);
register_chrdev_region_test(i, 12);
printk(KERN_ALERT"register again.\n");
register_chrdev_region_test(i, 122);
return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT"Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit); |
|