ext2 File System 2
Here is the long awaited sequel to my last post. This will be mostly the same information, but with more pictures.
The disk is organized into a number of sectors, each of which is 512 bytes (256 16 bit words). Each of these sectors has an address called the Logical Base Address, or LBA. To read from the disk, we ask the drive for a number of sectors starting at a given LBA.
Since this is an MBR disk, the very first sector of the disk contains the master boot record, which contains bootstrap code, a signature, and 4 partition entries. Each partition entry gives information about that partition as well as its location on the disk.
The ext2 partition begins at the location given in the MBR. The first two sectors are ignored. The second two sectors contain the superblock, and following that are the group descriptors.
The superblock contains information about the file system, but the ones in the picture are the important ones to start. Each group, for which the number can be calculated using information from the superblock, has a group descriptor. The important part of each group descriptor is the inode table address, which is where all of the inodes for that group are.
Each inode contains information about the file or folder it is associated with. The important parts for reading the file are the number of sectors used, and the various block pointers. There are 12 direct block pointers. If you go to the blocks that those point to, you will find raw data. The indirect pointer points to a table full of data block pointers, which gives you 256 more data blocks. The doubly indirect pointer points to a table full of indirect pointers, which gives you 256*256 more data blocks, and finally the triply indirect pointer points to a table full of doubly indirect pointers, giving you 256*256*256 more data blocks. Once you turn a data block pointer into an LBA, by multiplying it by 2 (since blocks are twice the size of sectors) and adding the partition offset, you can read that data block from the disk.