Trey
Trey

Reputation: 554

What is the device of inode?

I'm messing with the stat structure and trying to comprehend it, however most of the documentation is rather cryptic, specifically, I can't understand the purpose of the first member, st_dev, what exactly is a "device of inode"?

Upvotes: 2

Views: 1617

Answers (1)

Ctx
Ctx

Reputation: 18420

In the field st_dev you find a system-dependent number of the device which backs this file. It usually is the major/minor number (combined with makedev(3)) of the block device which contains the filesystem where the file is located on. If the file is a device node, it is the major/minor number of the device itself.

For example:

$ ls -la /dev/null
crw-rw-rw- 1 root root 1, 3 May 17 09:52 /dev/null

st_dev will contain makedev(1,3) (which is 259 on linux), or

for /etc/passwd, st_dev will contain makedev(8,1) (which is 2049 on linux), if the file is located on /dev/sda1.

You can extract the major/minor number with the corresponding macros major(st_dev) and minor(st_dev), as described in the manpage for makedev(3).

Upvotes: 2

Related Questions