Lecture 24 - Filesystem Consistency
Every "reasonable" filesystem has some method of monitoring its own self-consistency (even chkdisk).
No matter what allocation policy is used for allocating disk blocks, it is necessary to keep track of which ones have been allocated. You can use:
- Linked list: when you need one block, search the list for an appropriate amount of space
- bitmap: do the same thing with a bitmap; uses less memory but may require more searching as the disk fills up
We can do the same thing for inodes if your filesystem has them.
To check them for consistency:
- Create an array of counters for allocated and free blocks:

- Sweep through the filesystem and free list and increment the aprpopriate counter each time a block is found.
If all goes well each block will be found in one of the lists:

If not there's a problem:

You may have the following problems:
- Missing block: the solution is to place it in the
freelist - Allocated block in
freelist: remove it from thefreelist - Block allocated twice: copy the block to a
freeone and hope things work out ok
- Do the same thing for references counts from directories to
inodes.
Possible problems:
- Referenced
inodehas incorrect link count: correct the count if this is the case - unreferenced
inodehas nonzero link count: put theinodein lost and found (yes, really) and anything that links to it can check there as a last resort.