What is an inode as defined by POSIX?

The Wikipedia article on inodes has a section titled POSIX inode description which says an inode contains (among 8 other bullet points):

  • Device ID (this identifies the device containing the file).

This doesn't seem right to me, and I note that there is no link to a POSIX document in the references.

What does POSIX say about the structure of an inode? Please provide references as appropriate.

  • 5
    The Wikipedia article apparently confuses struct stat with an inode. struct stat includes the st_dev field which contains the device id. It would make no sense for the on-disk inode to contain the device id, because the file system should not care about which device it is contained in. – Johan Myréen Aug 19 '17 at 5:14

The POSIX standard (IEEE Std 1003.1) is silent on what an inode is. That is simply an implementation detail which is outside the scope of the standard.

There is no definition of an inode in the POSIX standard.

The POSIX Programmers Guide by Donald Lewine says POSIX uses the term “file serial number” to refer to what’s commonly known as an i-node number, namely the unique number of a file entry in a filesystem.

POSIX <sys/types.h> says:

... and ino_t shall be defined as unsigned integer types.


Interestingly, the standard does include the word “inode”, as @apricot boy mentions, but I also can’t find a definition of the term.  Perhaps the closest is:

ino_t st_ino            File serial number.

in POSIX <sys/stat.h>.

In this comment, Johan Myréen says Wikipedia is probably confusing an inode with the contents of the stat structure.  The stat structure does contain device information and the other information Wikipedia erroneously says is included in the inode.

  • The Wikipedia article gets more than just that wrong. I've mentioned some related errors on its talk page. – JdeBP Aug 19 '17 at 7:30
  • Cheers! For others interested, the entry is here. – Tom Hale Aug 19 '17 at 12:22
  • 1
    (1) An inode is a thing (a data structure), not a number.  An “inode number” is the name / address of an inode.  (2) That statement from POSIX sys/types.h says that an inode number is an unsigned integer, not that an inode contains unsigned integer(s).  I.e., an inode number is a whole number ≥0 and <2³² (or whatever the maximum integer is). (Of course, an inode number cannot be 0, but I guess that's an implementation detail, not specified by the standard.) (3) Why do you say “erroneously” in your last sentence?  I believe that that's inapplicable. – G-Man Aug 22 '17 at 5:02
  • Thanks for the feedback - I fixed (2). Regarding (3), my assertion is that an inode is what Donald Lewine is calling a file in the link given. Files have attributes which stat picks up which are not stored in the filesystem itself (eg which device the filesystem is currently attached to) – Tom Hale Aug 22 '17 at 14:02

Is there such a thing as a POSIX inode? I did a search for "inode" in the POSIX.1-2008 spec, and it only pops up as a passing reference in a few manpages and header files. Inodes don't seem to be defined there. I'd guess that inodes are handled by the kernel or the driver of whatever filesystem you're using.

As for your question about device IDs in inodes, I had a look at the inode structs for both ext4 and btrfs, both don't have any mention of device number, so again I'd guess that's done by the kernel.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.