[ACCEPTED]-Why do inode numbers start from 1 and not 0?-superblock

Accepted answer
Score: 34

0 is used as a sentinel value to indicate null or no inode. similar 12 to how pointers can be NULL in C. without 11 a sentinel, you'd need an extra bit to test 10 if an inode in a struct was set or not.

more 9 info here:

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

http://uranus.chrysocome.net/explore2fs/es2fs.htm

for instance, in 5 old filesystems where directories were represented 4 as a fixed array of file entries, deleting 3 a file would result in setting that entry's 2 inode val to 0. when traversing the directory, any 1 entry with an inode of 0 would be ignored.

Score: 31

Usually, the inode 0 is reserved because 10 a return value of 0 usually signals an error. Multiple 9 method in the Linux kernel -- especially 8 in the VFS layer shared by all file systems 7 -- return an ino_t, e.g. find_inode_number.

There are more 6 reserved inode numbers. For example in ext2:

#define EXT2_BAD_INO             1      /* Bad blocks inode */
#define EXT2_ROOT_INO            2      /* Root inode */
#define EXT2_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT2_UNDEL_DIR_INO       6      /* Undelete directory inode */

and 5 ext3 has:

#define EXT3_BAD_INO             1      /* Bad blocks inode */
#define EXT3_ROOT_INO            2      /* Root inode */
#define EXT3_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT3_UNDEL_DIR_INO       6      /* Undelete directory inode */
#define EXT3_RESIZE_INO          7      /* Reserved group descriptors inode */
#define EXT3_JOURNAL_INO         8      /* Journal inode */

and ext4 has:

#define EXT4_BAD_INO             1      /* Bad blocks inode */
#define EXT4_ROOT_INO            2      /* Root inode */
#define EXT4_USR_QUOTA_INO       3      /* User quota inode */
#define EXT4_GRP_QUOTA_INO       4      /* Group quota inode */
#define EXT4_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT4_UNDEL_DIR_INO       6      /* Undelete directory inode */
#define EXT4_RESIZE_INO          7      /* Reserved group descriptors inode */
#define EXT4_JOURNAL_INO         8      /* Journal inode */

Other fileystems use the ino 4 1 as root inode number. In general, a file 3 system is free to choose its inode numbers 2 and its reserved ino values (with the exception 1 of 0).

Score: 5

OSX specifies that inode 0 signifies a deleted 5 file that has not yet been deleted; this 4 may have also been used in other filesystems, as 3 OSX is BSD-derived, although at least NetBSD 2 seems to have now removed this usage.

See 1 the OSX manpage for getdirentries http://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man2/getdirentries.2.html

Score: 0

When I wrote a filesystem ages ago, I used 9 inode 0 for the .badblocks pseudo-file.

On some filesystems 8 .badblocks is actually present in the root directory 7 as a regular file owned by root and mode 6 0. root can open it but reading or writing 5 it is undefined.

There is some ancient tradition 4 that inodes start from 1, #1 is .badblocks, and #2 3 is the root directory. Even though .badblocks is not 2 particularly well-guaranteed, many filesystems 1 go out of their way to make root #2.

More Related questions