File System Consistency Checker (FSCK)

File system inconsistency is a major issue in operating systems. FSCK is one of the standard solutions adopted.

File System Consistency Checker (FSCK):
FSCK is one approach still used by older Linux-based systems to find and repair inconsistencies. It is not a complete solution and may still have inodes pointing to garbage data. The major focus is to make the metadata internally consistent.

The following are the checks that FSCK performs to achieve consistency:

  • Superblock Checks:
    FSCK performs a sanity check to see if the file size is greater than the number of blocks allocated. In this case, it tries to find the suspect superblock and use an alternate copy instead.
  • Free Block Checks:
    FSCK also scans inodes to ensure that blocks in inodes are marked allocated.
  • Inode State Checks:
    FSCK checks inodes for corruption. Corrupted inodes are simply cleared.
  • Inode Link Checks:
    FSCK counts the number of links to an inode, and modifies the inode count. If an allocated inode has no directory or file referring to it, FSCK moves it to the lost and found directory.
  • Duplicate Pointers:
    FSCK checks duplicate pointers. For example, if two inodes have pointers to the same data block, one of the inode can be deleted.
  • Bad Blocks:
    A bad pointer is simply one that points to a memory address which is out of range. In this case, FSCK deletes the pointer.
  • Directory Checks:
    FSCK makes sure the directory format is correct, e.g. they should start with “.” and “..”.

Advantages of FSCK:

  • It requires little overhead space.

Disadvantages of FSCK:

  • Scanning the disk, again and again, is slow and infeasible for large disk sizes.
  • It requires a heavy understanding and prior knowledge of the file system. As file systems continue to evolve, it is difficult to keep track of each and every nuance.

fsck Command in Linux:
The fsck command in Linux allows us to manually check for file system inconsistencies. Below is the sample usage of the command.

sudo fsck /dev/sda2

The above command simply checks the file system mounted onto the /dev/sda2 partition. If the file system may have some inconsistencies, fsck prompts us with possible actions.

fsck.fat 4.1 (2017-01-24) 

0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt: Remove dirty bit, and No action.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.