The data is stored on the disk, and the files are stored in the form of data. Because the data on the disk is stored continuously, it is necessary to manage it. That is, the file system (FS).
First, FS should be independent of the OS, the smallest unit stored in FS is block, and the block must specify its size when creating FS, usually (1KB,2KB,4KB ...).
Usually a file has some attributes that need to be logged in addition to its internal data. such as permissions, size, etc., i.e. metadata,
The metadata is stored in a single inode, and data is stored in a block (the inode itself is also in blocks, of course), and a file corresponds to an inode, which now associates the inode with the block.
1, indexed, Inode holds index of all blocks
2, chained, Inode holds the first block, then each block points to its next
As for the directory, the same as the normal file, but the contents of the directory is a directory item, it should contain the directory of all files (including directory) name, and its inode index, so that we can find the corresponding file.
In addition, in order to manage and allocate blocks and inode. There is also a bitmap bitmap used with the identification of a block is not used.
EXT2 File System
Ext2 File System structure:
Description: (This information is copied externally from the reference, labeled with the background color ...) With a piece is also a copy)
One, super blocks (Super block):describes the file system information for the entire partition. 1, block and inode total;2, unused and used inode, block number;3. The size of the block and the inode; the inode is a Byte, and the block size is specified when it is formatted4, the file system mount time, the most recent time to write data, the most recent test disk time and other file system related information;5, a validbit value, if this file system is mounted, then Validbit is 0, if not mounted, then validbit is 1;
In general, the size of the superblock is 1024bytes. Related Superblock Information we can call out the dumpe2fs command to observe!
The super block has one copy at the beginning of each block group. In fact, except that the first block group contains Superblock, the subsequent block group does not necessarily contain superblock,
And if it is the first block group within the Superblock backup, so that can be superblock rescue!
Second, group descriptor Table (Gdt,group descriptor):
Consists of a number of block group descriptors, and how many block groups the entire partition is divided into will correspond to the number of block group descriptors. Each block group descriptor (Group descriptor) stores the descriptive information for a block group, such as where the Inode table begins in this block group, where it starts as a block of data, how many free inode and data blocks are available, and so on. Similar to the Super block, the Block group descriptor has a copy at the beginning of each block group, which is very important, and once the super block is accidentally damaged it loses the entire partition's data, and once the block group descriptor is accidentally corrupted, the entire block group of data is lost, so they all have multiple copies. Normally the kernel only uses copies of the NO. 0 block group, and when the e2fsck check file system consistency is performed, the Super Block and block group descriptor in the NO. 0 block group are copied to the other block groups so that when the beginning of the NO. 0 block group is accidentally damaged, other copies can be used to recover, thereby reducing the loss.
Third, Bitmap (bitmap):
Each of these bits indicates whether a inode/block is available for free.
Consider the following: (Test results based on some commands)
(Note: After this, I will be a block of the size of B to represent, Numi represents the number of inode, numb represents the number of blocks, NUMG represents the number of group)
1, how to correspond with the physical disk and how to determine the packet size?
FS blocks the smallest unit of storage, then directly separates a file system by block, number 0~numb-1,
Because B starts with specifying, partition size/b, less than 11 B ignored, get numb. This corresponds to physical disk one by one.
Now I'm not supposed to assume that the assigned policy of the known blockgroup, then the offset address of the Inode table and the data table (that is, the start address of the group) can be determined?
According to DUMPE2FS, the block group, Superblock occupies the 1b,bitmap occupies 1b,inodetable according to (numi/numg*128)/b known size,
They are continuous, positional relationships as shown in the figure above. So, if you can determine the size of the GDT, then the offset address is still easy to count.
----(not completed, staged)
Preliminary thinking of Linux file system