In Posix, how is the dev_t type used?

What I need is a value of this type and what interface can use it.

The Posix specification explains what is dev_t

used for device IDs. However, what does a device identifier mean for any object described in a path, which can be a file, directive, phylo, or physical device?

For example, a call stat()

should give you a structure that includes a member of this type; and you can install any kind of objects on your filesystem. The device ID must have different meanings for different file types.


source to share

3 answers

The only use dev_t

in the vast majority of programs (portable and not connected to the same OS) is to determine that two filenames or file descriptors refer to the same base file. This is true if and only if the records st_ino

and st_dev

for the structures of the two files stat


Basically, it st_dev

indicates which "device" (eg, mounted partition, network share, etc.) is located, and st_ino

is the unique identifier of the file in the context of one device.



There are actually struct stat

two dev_t

-typed fields in there :

  • st_dev

    is the "[d] identifier of the device containing the file", so if two files have the same st_dev

    , they are on the same filesystem.
  • st_rdev

    is a device device identifier denoted by a special symbol or block file, that is, files commonly found in /dev

    . It doesn't matter for other file types.


Within the kernel, the dev_t type, which is defined in, is used to store device numbers (major / minor). dev_t is a 32-bit quantity with 12 bits allocated for the major number and 20 for the minor number.



All Articles