MBR

MBR occupies the size of a sector. MBR is located in the first sector of the disk. CHS is represented by 0 cylinder, 0 head, and sector 1. The notation for LBA is sector 0. After the CPU is powered on and reset, the BIOS loads the MBR into the memory to boot the operating system.

Block (Block)

Ext2 and Ext3 are the default File systems of many Linux operating System distributions. They are generally referred to as bit-extx, which is based on Unix File System (UFS).

ExtX divides the entire file system into blocks, which are used as storage units for data. A block consists of several consecutive sectors, usually 2, 4, or 8 sectors. The size of this value is recorded in the superblock located in sectors 2 to 3 of the file system.

All blocks are assigned an address, numbered from 0, starting from the first sector of the file system.

The basic layout information for ExtX is stored in a structure called a “superblock.” The first superblock is located in sector 2 of the file system and occupies two sectors in size. The first two sectors are used to house boot programs and are called boot sectors. If there is no boot program, leave unused. Normally, only the superblock information of block 0 is used by the file system.

  • When the block size is 1024 bytes, block 0 is the boot block or the reservation block, and the superblock starts at block 1.
  • When the block size is 2048 bytes, the superblock starts in block 0 and is located in the last two sectors of block 9.
  • When the block size is 4096 bytes, the superblock starts in block 0 and is located in sectors 2 to 3.

Super Block

The super block is located at 1024 bytes of the file system and contains configuration information, such as the block size and the total number of blocks.

Superblock data structures

The number of bytes meaning
4 Total number of i-nodes of the file system
4 Total number of file system blocks
4 Number of blocks reserved for the file system
4 Free blocks
4 Number of idle I-nodes
4 Block group 0 Indicates the start block number
4 Number of bytes per block. Assuming n, the block size is 2 to the power of n multiplied by 1024 bytes
4 Fragment size (exactly the same as the block size field). In UFS file systems, a block is divided into fragments to reduce the amount of space wasted at the end of the file when storing data. The ExtX file system, from UFS, also retains this field in the superblock, but ExtX does not support the partitioning of blocks into segments, so the fragment size is always the same as the block size
4 Number of blocks per block group
4 Number of fragments per block group
4 I – Number of nodes per block
4 Last mount time
4 Last write time
2 Maximum number of mounts
2 Signature mark “53EF”
2 Status of the file system: 0x0001 indicates that the file system is normal, 0x0002 indicates that there is an error, and 0x0004 indicates that the isolated I-node is recovered
2 Error handling: 1 indicates continue, 2 indicates re-mount the file system in read-only mode, and 3 indicates emergency handling
2 Sub-release level
4 Finally, the consistency check time is performed
4 Consistency check interval
4 The operation coefficients for creating this file system are 0 for Linux, 1 for GNU Hurd,2 for Masix, 3 for FreeBSD, and 4 for Lites
4 Major version level: 0 indicates initial version and 1 indicates dynamic version
2 Default UID reserved block
2 The default GID is reserved for blocks
2 The first non-reserved I-node
2 The size of each i-node structure
2 Id of the block group to which the super block belongs
4 Compatible characteristic mark
4 Incompatible feature flag
4 Read-only compatible feature flag
16 File system ID
16 Volume name
64 Last mount path
4 Bitmaps use algorithms
1 Number of file reallocation blocks
1 Number of directory reallocation blocks
2 Don’t use
16 Log ID
4 Log i-node
4 Logging equipment
4 Isolate the i-node header
788 Don’t use

Group descriptor table

Group descriptor data structure

The number of bytes meaning
4 Block bitmap start address (Block number)
4 I – Node bitmap Start address (block number)
4 I – Start IP address of node table (block number)
2 The number of free blocks in the block group
2 Number of free I-nodes in the block group
2 The number of directories in the block group
2 fill
12 unused

Block the bitmap

File contents are stored in blocks, and block allocations are recorded in block bitmaps. Each block group has a block bitmap structure that describes the allocation of all blocks within the group. Block bitmaps occupy the space of a block. Each bit in the block bitmap is set one by one. If a block has been allocated and used, the corresponding bit in the block bitmap is set to 1 and the unused bit is set to 0.

I – Node bitmap

Similar to the block bitmap, note that i-node numbers are numbered from 1 instead of 0. That is, all I-nodes in the entire file system are numbered from 1. The first i-node is i-node 1.

I-node table and I-node

A file or directory corresponds to an I-node

I-node data structure

The number of bytes meaning
2 File mode (type and permission) : 0 to 9 bits indicates the permission. Each bit corresponds to a permission.
2 The lower 16 bits of the UID
4 Size The number of bytes is 32 bits lower
4 Last visit time
4 I – The node changes the time
4 Delete the time
2 The lower 16 bits of the GID
2 Number of links
4 Number of sectors
4 mark
4 Don’t use
4 The first direct block pointer
4 Second direct block pointer
4 The third direct block pointer
4 The fourth direct block pointer
4 The fifth direct block pointer
4 The sixth direct block pointer
4 The seventh direct block pointer
4 The eighth direct block pointer
4 The ninth direct block pointer
4 The 10th direct block pointer
4 The 11th direct block pointer
4 The 12th direct block pointer
4 A first-level indirect block pointer
4 A secondary indirect block pointer
4 A three-level indirect block pointer
4 Time Series (NFS)
4 Extended attribute block (file ACL)
4 Size Number of bytes high 32 bits (directory ACL)
4 Segment address
1 Segment index number
1 Fragment size
2 Don’t use
2 UID 16 bit high
2 GID 16 bit high
4 Don’t use

File pattern

File mode takes up 2 bytes of 16 bits, which can be divided into 3 groups.

  • 0 to 8bit: indicates the permission flag.

Permissions are classified into read, write, and execute permissions.

Permission value (binary) meaning
0000 0001 0000 0000 Owner to read
0000 0000 1000 0000 Owner can write
0000 0000 0100 0000 Owner can execute
0000 0000 0010 0000 Group users can read it
0000 0000 0001 0000 Group users can write
0000 0000 0000 1000 Group users can run this command
0000 0000 0000 0100 Other users can read it
0000 0000 0000 0010 Other users can write
0000 0000 0000 0001 Other users can perform this operation
  • 9 to 11bit: defines executable files and directories
Value (binary) meaning
0000 0010 0000 0000 In the case of an executable file, setting 1 means that the code still resides in memory after the program is closed. In the case of a directory, only the owner of the file can delete files in the directory
0000 0100 0000 0000 SGID (sets the group ID)
0000 1000 0000 0000 SUID (set user ID)
  • 12 to 15bit: describes the file type
Value (binary) meaning Value (binary) meaning
0001 0000 0000 0000 The pipe 1000 0000 0000 0000 Normal file
0010 0000 0000 0000 Character device 1010 0000 0000 0000 Dynamic link
0100 0000 0000 0000 directory 1100 0000 0000 0000 The socket
0110 0000 0000 0000 Piece of equipment

Directory entry

An i-node represents a file, a directory is a file, a normal file stores data in a block, a directory does the same thing, but a directory has a directory entry structure, the I-node doesn’t have a name, the names that you see in a file with a name are actually in a directory entry structure.

byte meaning
4 I – node number
2 Directory entry length
1 The length of a name
1 File type: 0x01 indicates a file. 0x02 indicates a directory. 0x03 represents a symbolic link
longer The name