Device number (source code)

= Device number

A \b[device number] identifies a device interface using a <major device number> and a <minor device number>. In the Linux interfaces discussed here, the combined value has type `dev_t`; `makedev` combines the two components and `major` and `minor` recover them. The documented interpretation associates the major value with a device class and the minor value with an instance within that class.<Device-number conversion in the Linux man-pages project>[makedev(3), DESCRIPTION]{ref}

A <device node> also has an <inode> number, and its containing <file system> has a device identity of its own. The fields `st_ino`, `st_dev` and `st_rdev` therefore answer different questions: which inode, which containing device, and which represented device for a device-special file.<Device file metadata in the Linux man-pages project>[inode(7), Inode number, Device where inode resides and Device ID]{ref}

For an original metadata comparison, stipulate two character-special nodes in one file system with inode numbers 40 and 90, each representing major 240, minor 7. They are different named file-system objects representing the same interface in this example. A third node with major 240, minor 8 represents a different minor interface. The file type remains relevant: character and <block device> numbers are not equated solely by matching two integers.

Combining the components is not decimal concatenation. The pairs $(1,23)$ and $(12,3)$ both become the character string `123` if their decimal spellings are joined without a separator. The structured pairs are nevertheless different. The appropriate `dev_t` conversion preserves their distinct components rather than imposing that ambiguous textual encoding.

For valid supported component values, the intended round trips are
$$
\operatorname{major}(\operatorname{makedev}(a,b))=a,\qquad
\operatorname{minor}(\operatorname{makedev}(a,b))=b.
$$
Use the defined conversion interface rather than assuming a particular in-memory packing. The device number is an interface identifier; it is not automatically a serial number, a stable physical-device identity or the process-local <file descriptor> returned by opening the node.