dev_t expands at last
[Posted September 24, 2003 by corbet]
The expansion of the
dev_t device number type has been on the list
of goals for 2.6 since the beginning. The only problem is that it has
stayed on that list through the entire 2.5 development process; for various
reasons, work on that project stalled for a long time. As of
September 24, however, the
dev_t expansion can be checked off
the list; Linus has merged the required changes into his BitKeeper tree.
They will appear in the 2.6.0-test6 release.
For some time, it had appeared that dev_t would expand to 64 bits,
with 32 bits each for the major and minor numbers. The actual change,
however, is to 32 bits, with a 12-bit major number and 20 bits for the
minor. That should be adequate for some time, especially given that the
new registration mechanisms and sysfs make it much easier for the system to
use device numbers more effectively.
Internally, the new kernel dev_t type uses the encoding one would
expect: the major number sits in the top twelve bits of a 32-bit value,
with the minor number in the bottom 20 bits. The encoding seen by user
space is different, however, as shown in the diagram to the right. Here,
the major number sits in bits 8-19, while the minor number is split across
bits 20-31 and 0-7. This representation may seem strange, but it has one
very nice property: old 16-bit device numbers are still valid in the new
scheme. Encoding device numbers this way helps keep no end of applications
from breaking with the new device number type. One might wonder why this
workaround is necessary, given that the C library can convert device
numbers as needed for the few system calls (mknod(),
stat(), etc.) that actually need them. The problem is that device
number pop up in a number of other contexts, such as in filesystems and
ioctl() calls, where the C library is unable to help.
There are places, however, where an explicitly 16-bit value is passed.
There is no way to change that without breaking applications. In such
cases, the kernel checks whether 16 bits is sufficient; if not, the system
call has no choice but to fail with an EOVERFLOW error.
Beyond that, most of the groundwork for the new dev_t had already
been laid over the last few months. There are, however, certain to be a
few surprises left after such a fundamental change. The next couple
kernels could be interesting to use while the remaining issues get ironed
out.
(
Log in to post comments)