gkr2d2
gkr2d2

Reputation: 773

maximum values of major and minor numbers in linux

I am learning linux device driver development and created the code of a basic kernel module which creates a pseudo char device. That module got compiled and inserted too.. When I did lsmod the result was like this

 Module                 Size   Used by
modeldriver             2540    0 

what does that number indicate? what is meant by size of the module? And what is the maximum value of major and minor numbers in linux? Where can I get to know about the values of linux kernel 2.6.37

Upvotes: 3

Views: 5028

Answers (1)

Eugene
Eugene

Reputation: 6097

1. "Size" is the amount of memory the kernel module occupies, that is, the size of code, data and probably some special sections of the module loaded to memory. Note that the memory allocated dynamically by the module itself is not included there.

2. As for the major/minor numbers, it is better not to rely on the particular limits. If you need to reserve such numbers for your character devices, for example, you can use alloc_chrdev_region().

From the definitions of MAJOR(), MINOR() and MKDEV() in <linux/kdev_t.h>, it follows that 12 bits are used to encode a major number (0..4095, it seems), 20 bits - for the minors. Section "The Internal Representation of Device Numbers" of chapter 3 of "The Linux Device Drivers" book (3rd ed.) confirms that too:

As of Version 2.6.0 of the kernel, dev_t is a 32-bit quantity with 12 bits set aside for the major number and 20 for the minor number. Your code should, of course, never make any assumptions about the internal organization of device numbers; it should, instead, make use of a set of macros found in linux/kdev_t.h

If you have not done so already, I would recommend taking a look at Linux Device Drivers book mentioned above. While a bit outdated in some places, it is still very useful.

Upvotes: 4

Related Questions