What I am after is the meaning of such type and what interface can use it.
It is explained in Posix spec that dev_t
is used for device IDs. However, what device id means for any object described by a path, which can be a file, a directy, a fifo or a physical device?
For example, calling stat()
shall give you a struct including a member of such type; and you can stat any kinds of object in your file system. The device id should have different meanings for different file types then.
The only use of dev_t
in the vast majority of programs (ones which are portable and not connected to a single OS) is to determine that two file names or file descriptors refer to the same underlying file. This is true if and only if the st_ino
and st_dev
entries for the two files' stat
structures match one another.
Basically, st_dev
tells which "device" (e.g. mounted partition, network share, etc.) the file resides on, and st_ino
is a unique identifier of the file within the context of a single device.
Actually, there are two dev_t
-typed fields in struct stat
:
st_dev
is the "[d]evice ID of device containing file", so if two files have the same st_dev
, they're on the same filesystem.st_rdev
is the device ID of the device denoted by a character or block special file, i.e. the files commonly encountered in /dev
. It has no meaning for other types of files.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With