1

I am reading linux device driver book of rubini,corbet and hartmen.I have doubt regarding dynamic allocation of major and minor device numbers.They say

The disadvantage of dynamic assignment is that you can’t create the device nodes in advance, because the major number assigned to your module will vary.For normal use of the driver, this is hardly a problem, because once the number has been assigned, you can read it from /proc/devices.

1)What does it mean by advance here?

2)Why major and minor numbers must be read from /proc/devices when function alloc_chrdev_region provides major and minor numbers in the argument sent to it.can that argument sent, not be used directly?

Thanks in advance

4

2 回答 2

2

1) Dynamic assignment would mean that you cannot create device nodes before the driver is loaded, for example having them as a static part of the filesystem when the system boots. Instead you could only create them once you discover what their major/minor numbers are this time.

2) The driver may know what it's major and minor numbers are, but the device nodes should be created by something in userspace. They are suggesting that if this information cannot be given in advance in parallel to both the kernel driver and userspace, then userspace will have to discover it at runtime from something such as /proc/devices.

于 2012-06-22T05:12:57.273 回答
0
  1. When we assign a major number dynamically to a device driver, we are not aware with the Major Number till the alloc_chrdev_region function finishes execution or let's say that you don't get to know the Major Number before you insert the module into the kernel (and for this we use insmod). And so you cannot create a node for your driver (for which we use mknod) unless you load a device driver, this is referred to as advanced by the author.

  2. We read /proc/devices for Major and Minor Numbers of one device driver when a different device/program needs them.

于 2015-06-18T05:35:31.220 回答