1, Linux file hole and sparse file 2, file system data storage 3, File system debugging
file Hole
- In UNIX file operations, the file offset can be greater than the current length of the file
In this case, the next write to the file will extend the file and form a hole in the file. Bytes located in the file but not written
are set to 0.
- If offset is larger than the current length of the file, the next write operation will "extend" the file
Create a "void (hole)" in a file.
All bytes that are not actually written to the file are represented by a duplicate of 0. Whether the hole occupies hard disk space is determined by the filesystem (file system)
Of
Sparse files (Sparse file)
- Sparse files are basically the same as other ordinary files, except that some of the data in the file is full 0, and this part of the data does not occupy the disk
Space.
The following is the creation and viewing of sparse files
[[email protected] ~]# dd if=/dev/zeroof=sparse-file bs=1 count=1 seek=1024k[[email protected] ~]# ls-l sparse-file-rw-r- -r--1 root root 1048577 Oct 17:50 sparse-file[[email protected] ~]# du-sh sparse-file8.0k sparse-file[[email protecte D] ~]# cat anaconda-ks.cfg >> sparse-file[[email protected] ~]# du-sh sparse-file12k sparse-file[[email protected] ~]# du-sh anaconda-ks.cfg12k anaconda-ks.cfg[[email protected] ~]#
Linux file system Inode data block storage
The index node uses the multi-index structure, which is mainly embodied in the direct pointer and 3 indirect pointers. The direct pointer consists of 12 direct fingers
Pin blocks, which directly point to the data block containing the file data, followed by the 3 indirect pointers in order to accommodate the size of the file
and design for change.
Linux sparse file inode data block storage
When the file system stores sparse files, the Inode index node only gives the block number that actually consumes disk space,
The data is all 0 and does not occupy disk space of the file block and there is no physical disk block number.
Linux sparse file inode data block storage
- file void portion does not occupy disk space
- The disk space occupied by the file is still contiguous
Instance:
[[email protected] mnt]# du-sh sparse-file20k sparse-file[[email protected] mnt]# ls-lh sparse-file-rw-r--r--1 root Roo T 1.1G Oct 10:36 sparse-file[[email protected] mnt] #debugfs: Stat sparse-fileinode:49153 type:regular mode:0644 Flag s:0x0 generation:3068382963user:0 group:0 size:1073742848file acl:0 Directory acl:0links:1 blockcount:40fragment: address:0 number:0 Size:0ctime:0x507b76af--Mon Oct 10:36:31 2012atime:0x507b765f--Mon Oct 10:35:11 2012mtim E:0X507B76AF--Mon Oct 10:36:31 2012BLOCKS: (Ind): 106496, (): 106497, (DIND): 106504, (IND): 106505, (262144) : 106506total:5
Linux File system blocks store multiple indexes
- Linux file system data is stored in multiple inode
Re-index structure with direct pointers and 3 indirect fingers
Needle.
Similar to the definition of variables in programming:
unsigned long blk;
unsigned long *blk;
unsigned long **blk;
unsigned long ***blk;
- Direct pointer to block that holds data
No.
- The first level pointer points to a block in which the block
The data is the block pointer, pointing to the true save number
The block of the data.
? level two three pointers and so on.
- Top 12 direct pointers directly to the stored data region
If the blocks size is 4096, the first 12 direct pointers can save the 48KB file.
- First-level pointers can store file size calculations
Assuming that each pointer occupies 4 bytes, the block that the first level pointer points to can hold 4096/4
Pointer, which can point to 1024 blocks. The first-level pointer can store the file data size of 1024*4096 =
4MB.
- Second-level pointers can store file size calculations
Also according to the blocks size of 4096, the two-level pointer can hold the number of block pointers is (4096/4) *
(4096/4) = 1024*1024. The size of the number of files that can be saved by level two pointers is (1024*1024) *4096
= 4GB.
- Level three pointer to store file size calculation
With the first-level, two-level pointer calculation method and so on, the three-level pointer can store the file data size of
(1024*1024*1024) *4096 = 4TB.
Linux_file_hole_and_sparse_files
Linux file hole and sparse file turn