A file system is a method used by an operating system to store, organize, manage, and retrieve files and directories on storage devices such as hard drives, SSDs, USB drives, and optical media. It acts as an interface between the physical storage hardware and the operating system, allowing users and applications to access data efficiently without dealing directly with hardware.
Data Organization: Structures files and directories in a hierarchical (tree-like) manner, usually with a single root directory at the top.
Naming Conventions: Specifies rules for file names, such as allowed characters and maximum length.
Metadata Management: Maintains information about each file, including size, creation/modification dates, permissions, and location on the disk.
Space Management: Tracks free and used space, allocates space for new files, and recovers space when files are deleted.
Security and Permissions: Controls access to files through permissions, ensuring data security.
Data Access: Provides mechanisms for reading, writing, updating, and deleting files.
Partitions: Storage devices are often divided into partitions, each of which can use a different file system.
Mounting: For a file system to be accessible, it must be mounted to a directory mount point in the system's directory tree.
Journaling: Many modern file systems use journaling to maintain consistency and prevent corruption in case of system failures.
File systems are fundamental to how computers manage and secure data, enabling everything from basic file storage to complex enterprise data management.
Notes:
For ext2/ext3/ext4, the number of inodes is fixed at filesystem creation and determined by the bytes-per-inode ratio (default: 1 inode per 16 KB of disk space). Inode size defaults to 128 bytes (ext2/ext3) or 256 bytes (ext4), but can be set at creation1234.
XFS, Btrfs, JFS, ReiserFS, and F2FS use dynamic inode allocation, so the number of inodes is limited only by available space, not by a fixed count at creation8.
Size limits are theoretical maxima; practical limits may be lower depending on kernel and distribution support68.
Linux file systems (such as ext4, XFS, Btrfs) use several internal data structures to manage files and directories:
Superblock: Contains metadata about the file system itself, like size, block size, and status.
Inode Table: Stores metadata for each file and directory (permissions, owner, size, timestamps, pointers to data blocks).
Block Groups: Collections of blocks, inodes, and related structures to improve management and performance.
Bitmaps: Track free and used blocks and inodes.
Directory Entries: Map file and directory names to inode numbers.
Linked File Allocation
Linked File Allocation is a fundamental method used by operating systems to manage how files are stored on a disk. It treats each file as a collection of disk blocks that are linked together, forming a chain or a linked list. This approach offers flexibility in block placement, as the blocks do not need to be physically contiguous on the disk.
Directory Entry: For every file, the file system's directory maintains a crucial entry. This entry typically includes:
The name of the file.
The starting block address on the disk where the file begins.
Often, it also stores the last block address (to facilitate appending data) and the total size of the file.
Chained Blocks: Each individual disk block that belongs to a file is designed to hold two types of information:
The actual data content of the file.
A pointer (which is essentially the disk address) to the next block in the sequence that belongs to the same file.
End of File Marker: The final block in a file's chain contains a special value or a null pointer. This marker signals to the operating system that there are no more blocks belonging to this file.
When the operating system needs to access a file, it retrieves the starting block address from the directory. It then reads the data from this block and follows the embedded pointer to locate the next block. This process continues, traversing the chain of pointers from one block to the next, until the end-of-file marker is encountered.