Analysis on the structure of Inode table
Take the Ext file system as a reference, 4k block size partition, briefly describe the Ext file system data structure principle, if there are any errors, please point out
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/25/wKioL1ea9qKwMA88AAQ0CV5awjQ474.png "title=" Inode Table structure. png "alt=" Wkiol1ea9qkwma88aaq0cv5awjq474.png "/>
Inode index Node
HDD
The size of the sector is 2 times the N times. the size of the partition can be varied, 1k, 2k, 4k ... This is illustrated by the 4k block size. The 4k block size is divided into 8 sectors, and each sector corresponds to 512 bytes. Each block is also known as a block, the file is stored in block units, and each bolck can only belong to one file, if the file size is less than 4k, also according to the size of 4k blocks to store. The number of inode is specified at the time of formatting, theoretically, the number of inode and the number of blocks is closer to the better, but in the actual process of one by one correspondence is difficult, so the general format will be used to specify a percentage of the number of inode in the server.
#df View the number of Bolck per partition of the system
#df-I view the number of inode per partition of the system
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/85/26/wKiom1ebAPKCPrmpAABYTLiUKfk558.png "title=" 1.png " alt= "Wkiom1ebapkcprmpaabytliukfk558.png"/>
Each partition has a separate inode table
Metadata is also in the inode, and the metadata takes up disk space.
Pointers: Paths to data blocks
Direct pointer: There are 12 pointers, a 4k, which can store 4*12=48k data blocks.
Indirect pointer: The 13th pointer, pointer to the next file block, is also 4k block size, 4k block, can be divided into 1024 pointers, the inside of the pointer is to point to the real data block. Altogether can store the 1024*4K=4M data block, then the file in 4M around the scope, may use the indirect pointer to complete.
Two pointers: the 14th pointer. It also points to a 4k pointer data block, and a 4k pointer block then points to 1024 pointer data blocks,
Each pointer can hold 1024 4k of data, so you can store 1024*1024*4k=4g data blocks.
Triple pointer: Similar to the two-pointer work principle, the last can be stored 1024*1024*1024*4k=4t data blocks.
The Inode table is cached in memory, so the query is fast. Generally speaking, the operation of deleting files in the system is not to delete the data block, but to delete the metadata in the Inode table, here to explain the metadata, metadata is the properties of the data block, such as: name, height, etc. these can be understood as metadata. Therefore, this is why the deletion of the file, as long as no new files overwrite the original data block, the data can generally be restored reasons. Many file systems, such as FAT and NTFS under Windows, are the same principle. In general, the data in the disk is continuous write, because sometimes delete some of the data, so that some empty position in the track is not able to store the next file in a row, generally this is scattered stored in different tracks, when reading this part of the data, the disk pointer to go back and forth a few laps, Cause performance degradation, which is the origin of file fragmentation. So it is necessary to defragment at intervals. But now some new hard drives, such as SSDs, have no tracks, so they don't need to be defragmented like traditional mechanical hard drives.
The data blocks in the disk have files and directories, and the inode is stored differently.
In the Inode table, the file refers directly to an inode number, while the directory stores the mapping between the file name and the Inode under the directory entry in the Inode table.
The effect of copying, deleting, and moving on the Inode
CP copy: The new file is assigned a free inode number, and a new entry is generated in the Inode table
Create a catalog entry in the directory, associating the name with the inode number
Copying data generates a new file, which is two completely different blocks of data.
RM Delete: The number of links is decremented so that the inode number freed can be reused
Put data blocks in the free list
Delete a catalog entry
The data is not actually deleted immediately, but it will be overwritten when another file is using the data block, and the file will be restored immediately if the Inode's metadata is restored.
MV Move: If the target and source of the MV command are under the same partition as the MV command
Create a new directory entry with a new file name
Delete old directory entries corresponding to older file names
Does not affect the Inode table (except timestamp) or data location on disk: No data is being moved! So the speed of moving files within the same partition is very fast.
If the target and source are in a different file system, MV is equivalent to CP and RM
The difference between hard links and soft links
What is a hard link?
Hard Links: Multiple file paths that point to the same inode. (Simple understanding means that a person has two names, such as Zhang San, his nickname is Lao Zhang, also called small Three, is actually the same person)
Characteristics:
1 directory does not support hard links
2 Hard links cannot span file systems (cannot span partitions)
3 Creating a hard link increases the inode reference count;
Create a hard-link file command
ln source file hard-link file ...
ln [OPTION] ... [-T] TARGET link_name (1st form) Ln-make links between files
Delete one of the hard link files, other hard link files are unaffected
What is a soft link (symbolic link)
Soft Link: Another file path pointing to the same file path;
Characteristics:
1 symbols linked to a file are two separate files, each with their own inode; Create symbolic links to the original file
Do not add reference count back;
2 support to create symbolic links to the directory, can cross the file system;
3 Delete the symbolic link file does not affect the original file, but delete the original file, the symbol specified by the path, even if it does not exist, this will
becomes an invalid link.
Note: The size of the symbolic link file is the number of bytes of the path string of the file it specifies
Create a soft link file command
#ln-S original file path file 1 Soft link file 1: 2: Create soft link-s,--symbolic make symbolic links instead of hard links
When creating a soft link, you must use an absolute path!
The original file is relative to the soft-link file path, not to the current working directory.
The difference between the two:
This is a small form of personal understanding.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/38/wKiom1edagqDeu7mAAB4bq3JH9s031.png "title=" 2.png " alt= "Wkiom1edagqdeu7maab4bq3jh9s031.png"/>
Exercises
1. Display all files or directories with L, ending with a lowercase letter, and with at least one digit in the middle of the/var directory
# Ls-ld/var/l*[0-9]*[[:lower:]]
2. display files or directories that start with any digit in the/etc directory and end with a non-digit
# Ls-ld/etc/[0-9]*[^0-9]
3, display/etc/directory with a non-letter beginning, followed by a letter and any other arbitrary length of any character file or directory
# ls-ld/etc/[^[:alpha:]][[:alpha:]]*
4. Display all files or directories in/etc that start with a non-numeric end of M
# Ls-ld/m*[^0-9]
5. Display all files or directories ending with. D in the/etc directory
# LS-LD/ETC/*.D
6. Display the files or directories with the end of. conf and beginning with m,n,r,p in the/etc directory
# ls-ld/etc/[mnrp]*.conf
7, using the alias command, the daily/etc/directory of all files, backup to/testdir/under the new directory, and require the new directory format is BACKUPYYYY-MM-DD, the backup process is visible
# alias bkday= ' cp-av/etc//testdir/backup ' date +%f ' # Bkday
8, first create the/testdir/rootdir directory, and then copy the/root all the next file into the directory, and ask to retain the original permissions
#cp-av/root/testdir/rootdir
9, how to create/testdir/dir1/x,/testdir/dir1/y,/testdir/dir1/x/a,/testdir/dir1/x/b,/testdir/dir1/y/a,/testdir/dir1/y/b
# Mkdir-p/testdir/dir1/{x,y}/{a,b}
10. How to create/testdir/dir2/x,/testdir/dir2/y,/testdir/dir2/x/a,/testdir/dir2/x/b
# mkdir-pv/testdir/dir2/{x/{a,b},y}
11, how to create/TESTDIR/DIR3,/TESTDIR/DIR4,/TESTDIR/DIR5,/TESTDIR/DIR5/DIR6,/TESTDIR/DIR5/DIR7
# Mkdir-p/testdir/dir{3,4,5/dir{6,7}}
This article is from the "~ Breeze ~" blog, please be sure to keep this source http://wanweifeng.blog.51cto.com/1957995/1832280
The principle analysis of 7.28_LINUX_EXT data structure inode and the difference between soft and hard links