|
|
The list of inodes in the filesystem is checked sequentially starting with inode 2 (inode 0 marks unused inodes; inode 1 is saved for future generations) and progressing through the last inode in the filesystem. Each inode is checked for inconsistencies involving:
Each inode contains a mode word. This mode word describes the type and state of the inode. Inodes can be one of six types:
Each inode counts the total number of directory entries linked to the inode. fsck verifies the link count of each inode by starting at the root of the filesystem, and descending through the directory structure. The actual link count for each inode is calculated during the descent.
Discrepancies between the link count stored in the inode and the actual link count as determined by fsck can be of two types:
This can occur if no directory entry appears for the inode. In this case, fsck can link the disconnected file to the lost+found directory.
This can occur if a directory entry has been removed but the inode has not been updated. In this case, fsck can replace the stored count by the actual link count.
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 performs a partial second pass over the inode list to find the inode of the duplicated block. The second pass is needed, because without examining the files 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, the inode with the earliest modify time is usually incorrect, and should be cleared. If this happens, fsck prompts you to clear both inodes. You must decide which one should be kept and which one should be cleared.
fsck checks the range of each block number claimed by an inode. If the block number is lower than the first data block in the filesystem, 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 filesystem, a condition that can occur only if there has been a hardware failure. If an inode contains bad block numbers, fsck prompts you to clear it.
Each inode contains a count of the number of data blocks that it contains. The number of actual data blocks is the sum of the allocated data blocks and the indirect blocks. fsck computes the actual number of data blocks and compares that block count against the actual number of blocks the inode claims. If an inode contains an incorrect count, fsck prompts you to fix it.
Each inode contains a 32-bit size field. The size is the number of data bytes in the file associated with the inode. The consistency of the byte size field is roughly checked by computing, from the size field, the maximum number of blocks that should be associated with the inode, and comparing that expected block count against the actual number of blocks the inode claims.
An inode can directly or indirectly reference three kinds of data blocks. All referenced blocks must be the same kind. The three types of data blocks are plain data blocks, symbolic link data blocks, and directory data blocks. Plain data blocks contain the information stored in a file; symbolic link data blocks contain the pathname stored in a link; and directory data blocks contain directory entries. fsck can only check the validity of directory data blocks.