3.5. Inode links Each inode counts the total number of directory entries linked to the inode. Fsck veriﬁes the link count of each inode by starting at the root of the ﬁle system, and descending through the directory structure. The actual link count for each inode is calculated during the descent. If the stored link count is nonzero and the actual link count is zero, then no directory entry appears for the inode. If this happens, fsck will place the disconnected ﬁle in the lost+found directory. If the stored and actual link counts are nonzero and unequal, a directory entry may have been added or removed without the inode being updated. If this happens, fsck replaces the incorrect stored link count by the actual link count. Each inode contains a list, or pointers to lists (indirect blocks, of all the blocks claimed by the inode. Since indirect blocks are owned by an inode, inconsistencies in indirect blocks directly affect the inode that owns it. Fsck compares each block number claimed by an inode against a list of already allocated blocks. If another inode already claims a block number, then the block number is added to a list of duplicate blocks. Otherwise, the list of allocated blocks is updated to include the block number. If there are any duplicate blocks, fsck will perform a partial second pass over the inode list to ﬁnd the inode of the duplicated block. The second pass is needed, since without examining the ﬁles associated with these inodes for correct content, not enough information is available to determine which inode is corrupted and should be cleared. If this condition does arise (only hardware failure will cause it, then the inode with the earliest modify time is usually incorrect, and should be cleared. If this happens, fsck prompts the operator to clear both inodes. The operator must decide which one should be kept and which one should be cleared.
The UNIX File System Check Program SMM:3-7 Fsck checks the range of each block number claimed by an inode. If the block number is lower than the ﬁrst data block in the ﬁle system, or greater than the last data block, then the block number is a bad block number. Many bad blocks in an inode are usually caused by an indirect block that was not written to the ﬁle system, a condition which can only occur if there has been a hardware failure. If an inode contains bad block numbers, fsck prompts the operator to clear it.