clinuxfilesystemsinodesuperblock

Why do inode numbers start from 1 and not 0?


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?


Solution

  • 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:

    #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 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 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).