Ext2- Part II: Inside the bonnet
A file system usually comprises of blocks of data. A typical filesystem volume starts with a `Super Block’, which has all information regarding used and unused blocks as well as availability and location of various inodes. Only the superuser can access super block.
We have two kinds of blocks: Physical and Logical. Physical blocks are those that reside on the actual storage media, where the data is kept and has a fixed size. Logical blocks, on the other hand, are those whose size is specified once the filesystem is created. Logical blocks are further divided into smaller logical units called as fragments. A logical block consists of an integral number of fragments. This logical block size need not be the same as the physical block size. It is the job of the file system driver to provide the mapping from the logical block size to the physical block size. A single logical block is divided into an integral number of physical blocks. Ext2 has a default logical file size of 4k.
The filesystem volume starts with block 0, which is called the ‘boot’ block, which is available on the ext2 filesystem too. The blocks on disk are divided into groups. Each of these groups duplicates critical information of the file system. Moreover, the presence of block groups on disk allows the use of efficient disk allocation algorithms.
Each group contains the following:
The Super Block: In the ext2 filesystem, superblock is the area which can be accessed by the superuser only. The superuser is that area of the filesystem, which stores information about the number of free blocks, free inodes, logical block size, the number of times the volume has been mounted, and other accounting information about the filesystem.
Group Descriptors: Immediately following the Super block on the disk are the group descriptors. They hold critical information about the groups in the filesystem. Each group descriptor describes one group.
Block Bitmap of the Group: In order to account for the usage of the blocks on the filesystem, the ext2 filesystem consists of a block bitmap. This keeps track of blocks that have been used and those that are free. Each bit in the Block Bitmap denotes an integral number of fragments. So if a bit is allocated to a file and marked as used, then an entire set of fragments are allocated to it.