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.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Consistency Semantics for file sharing
- Difference between Local File System (LFS) and Distributed File System (DFS)
- File System Implementation in Operating System
- File Systems in Operating System
- Unix File System
- File Access Methods in Operating System
- Network File System (NFS)
- Various terms in File System
- Levels in a File Management System
- Understanding File System
- Compare file system in Windows and Linux
- Protection in File System
- System Protection in Operating System
- Allocating kernel memory (buddy system and slab system)
- User View Vs Hardware View Vs System View of Operating System
- System Programs in Operating System
- Xv6 Operating System -adding a new system call
- Traps and System Calls in Operating System (OS)
- File Allocation Methods
- Path Name in File Directory
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.