Filesystems – What is Metadata and How It Aids in fsck Process

filesystems

If I understand it correctly, "fsck" is used in UNIX systems to check for internal consistency within disks after there has been a crash. I was wondering, then, how it uses "metadata" to make sure that everything in the filesystem is consistent, for instance what steps the fsck process needs to take in order to restore and repair?

-> edit: it would also be helpful if someone could clarify what "synchronous write-through" refers to in this picture as well.

Best Answer

Metadata is information about data. If you think about a text file, the sequence of letters that text file is the actual data the file contains. However, the file has a name, an owner, a creation date, a location on the the storage medium, etc. All this information is metadata. Note that metadata can be handled the same way that data is. For instance, Unix stores file metadata in data files called directories (or folders in this new age of computing :-)

The Unix file system uses a basic unit of storage called an inodes. An individual inode can either contain actual file data, directory information (metadata), or be unused (free). Note that the act of creating a new file involves changing the state of an inode from free to allocated, writing data to the new file, and writing metadata to a directory file. It is possible for a computer to crash in the middle of this type of operation, in which case the file system can be corrupted.

File system checking consists of reading all the inodes and attempting to resolve as many corruption issues as possible. For instance, suppose an inode is not on the list of free inodes, but there are no directory entries that say that this inode is part of a file in any of the directories that the file system knows about. This inode can be placed back on the list of free inodes.

Synchronous write-thru is a way of performing writing to the disk in a manner that assures that if a crash does occur, the file system can be recovered. For instance, when you are creating a new file, you need to allocate an inode, create the inode with its metadata set, then update the file containing the directory information. With synchronous write-thru, these are done as separate actions, one at a time, in that order. If the crash occurs before the directory is written, then the inode can be placed back on the free list, and the file creation did not occur.

Other types of file system checks are possible as well.