Why do inode numbers start from 1 and not 0?

manav m-n picture manav m-n · Jan 20, 2010 · Viewed 13.5k times · Source

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?

Answer

jspcal picture jspcal · Jan 20, 2010

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:

All block and inode addresses start at 1. The first block on the disk is block 1. 0 is used to indicate no block. (Sparse files can have these inside them)

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.