The C language convention counts array indices from 0. Why do inode numbers start from 1 and not 0?
If inode 0 is reserved is for some special use, then what is the significance of inode 0?
Join Stack Overflow to learn, share knowledge, and build your career.
|
The C language convention counts array indices from 0. Why do inode numbers start from 1 and not 0? If inode 0 is reserved is for some special use, then what is the significance of inode 0? |
|||||||||||||
|
|
Usually, the inode 0 is reserved because a return value of 0 usually signals an error. Multiple method in the Linux kernel -- especially in the VFS layer shared by all file systems -- return an ino_t, e.g. find_inode_number. There are more reserved inode numbers. For example in ext2:
and ext3 has:
and ext4 has:
Other fileystems use the ino 1 as root inode number. In general, a file system is free to choose its inode numbers and its reserved ino values (with the exception of 0). |
|||||||||
|
|
0 is used as a sentinel value to indicate null or no inode. similar to how pointers can be NULL in C. without a sentinel, you'd need an extra bit to test if an inode in a struct was set or not. more info here:
http://uranus.chrysocome.net/explore2fs/es2fs.htm for instance, in old filesystems where directories were represented as a fixed array of file entries, deleting a file would result in setting that entry's inode val to 0. when traversing the directory, any entry with an inode of 0 would be ignored. |
|||||||||||||||||
|
|
OSX specifies that inode 0 signifies a deleted file that has not yet been deleted; this may have also been used in other filesystems, as OSX is BSD-derived, although at least NetBSD seems to have now removed this usage. See the OSX manpage for getdirentries http://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man2/getdirentries.2.html |
|||
|
|
|
When I wrote a filesystem ages ago, I used inode 0 for the On some filesystems There is some ancient tradition that inodes start from 1, #1 is |
||||
|
|