当前位置:网站首页>Understanding inode
Understanding inode
2022-06-13 05:01:00 【Clown clown clown】
List of articles
inode Is a data structure in the file system .
notes : The files mentioned here are hard disk files , Instead of being loaded into memory and managed by the process
Disk composition

A disk is a mechanical device , For example, a mechanical hard disk is a kind of disk .( Solid state drives are not disks )
Disks can store information , It can be divided into three areas to store information .
1. Different disk surfaces
2. cylinder
3. A sector
The cylinder divides the disk into many concentric circles , Different concentric circles are different cylinders .
The sector is on the same concentric circle , There are many small pieces , It's called sector .
Mapping of disk storage
File systems are managing physical memory , Abstract management . The hard disk will be divided into a linear structure . And this is a linear structure Block management 
After layer upon layer , It will eventually be divided into one called block group The partition .
One block group There are many members in it , Mainly about several important .
inode and data block( a key )
The file system is through struct file To manage hardware level files .struct file There's a dentry member , Can pass dentry Member found inode.( Can be interpreted as struct file You can find inode)
Why find inode Well ? Because by inode File data can be found .
inode It's a data structure , There are all kinds of documents and information stored inside , Mapping relationship with file data area . namely
map[inode id] = data block
inode bitmap
inode There is a member named inode id. Each file has its own inode id.
Without considering hard links , A file has only one inode id. The system also uses... When searching for files inode id To find out .
We can use ls -i To see the file inode id. The preceding figures are inode id
It can also be used. stat To see more file information , You can see inode id yes 665534
got it inode id, You know the inode bitmap What did you do .
bitmap It's a bitmap , every last bit One for one inode id Are you free , Not being used . Once used, you can no longer use it .
block bitmap
block bitmap It is also a bitmap , every last bit One for one data block Are you free , When you are free, you can put data in it .
inode table
One block group It can store many file information . from inode bitmap I know , One group There will be a lot of inode Need to manage , therefore inode table It's used to store inode Of .
data table
To store the data of a file .
Find a diagram of the file ( a key )
1. Find... By file name inode id How much is the
2. Through the first inode id find inode stay inode table The location of
3. Then through the mapping relationship , Find the data of this file in data block Those positions of , And get the data 
What you need to do to create a new file ( a key )
1. Find a free inode id, use inode Save the file information of this new file .
2. Save the contents of the file to data block
3. Record the contents of the document data block, And keep it in inode Inside .
4. Add the file name to the directory
Why is there still space , But can't create a file
We know inode id In a group There is a limit , When inode id When it's finished , Even if there is space , Still unable to create file .
Operations required to create a directory
We know , Directory is also a kind of file . So the catalog is also related to inode It matters .
Similar to what is required to create a file , But it's not exactly the same , Because the directory has no data .
The directory data block What is stored inside is the file name under the directory and inode id The mapping relation of .
Summarize all the steps :
1. Find a free inode id, Use this inode Save the file information of the directory
2. Save the contents of the file to data block Inside ( The contents here are the file name and inode id The mapping relation of )
3. use inode Record where the data is placed data block in
4. Add the file name to the directory
Actions required to delete files
Deleting a file does not require that data block and inode Empty , Just put this inode id and data block id Become idle . This operation has no cost .
This is why data can be restored after deletion , The reason is that as long as the data is not overwritten , Still there .
Catalog files and inode
There is a phenomenon , When a directory file is unreadable , We can still access the contents of the files in the directory . But when a directory file is not executable , We cannot read or write the contents of the files in the directory .
This sum inode It's also relevant .
When a directory file is unreadable , It's just inode The information inside is unreadable , But we can still map to data block Get the files in the directory inode id To access the file . But if there is no directory x jurisdiction , We can't get through inode Get data block Of the mapping relationship .
Hard links
In general , One file name corresponds to one inode, But the hard link special file can be shared with other files inode.
ln file Hard links
notes : Hard links are not links , It's an ordinary document .
Number of hard links in file information
This 2 Yes is the number of hard links to the file .
Why is the number of hard links in a newly created Directory 2?
Recall the definition of hard links , share inode id The number of files is the number of hard links . Who else shares the same with this directory inode id Well ???
We know linux There are two hidden files in each directory . and …, They are the current directory and the parent directory .
Turned out to be . This document and tmp Directories share the same inode id, So the number of hard links is 2.


Soft link
Soft links are a bit like shortcuts . If the executable program is in a deep Directory , It is inconvenient to enter and run ( Or it is inconvenient to use absolute path ) You can create soft links to files in the current directory , Then you can run in the current directory .
ln -s file Soft link
l Soft links 
Three times in the file information a c m
Access Last access time
Modify Last modification time of file content
Change Property last modified
边栏推荐
- Shell built-in string substitution
- Reductive elimination
- String()和toString()方法得区别
- C # get all callable methods of WebService interface [webmethod]
- Section 2 - branch and loop statements
- Differences between string() and tostring() methods
- Luogu p1012 guess
- Gradient descent, learning rate
- The games that you've tasted
- Clause 48: understand template metaprogramming
猜你喜欢

RuoYi-Cloud启动教程(手把手图文)

Explain the differences and usage scenarios between created and mounted

Chapter 15 mechanism: Address Translation
![[JS solution] leedcode 200 Number of islands](/img/c1/bcdb3fc079c634a9a1b3d0fc264987.png)
[JS solution] leedcode 200 Number of islands

QT realizes message sending and file transmission between client and server

Draw a hammer

Section 3 - functions

Spice story

C language learning log 12.5

约瑟夫问题
随机推荐
Chapter 17 free space management
MySQL8.0.13安装教程(有图)
Ruoyi cloud startup tutorial (hand-held graphics)
Force deduction 121 questions
C language learning log 1.24
Clause 27: alternatives to overloading with familiar universal reference types
利用Javeswingjdbc基於mvc設計系統
Win8.1和Win10各自的優勢
BM1Z002FJ-EVK-001开机测评
QT direction key to move focus
C # get all callable methods of WebService interface [webmethod]
Differences between string() and tostring() methods
Shell variable learning notes
QT using layout manager is invalid or abnormal
C language learning log 10.6
QT client development -- driver loading problem of connecting to MySQL database
Autumn wind, dust, youth
Four methods for judging JS data types and user-defined methods
Section 6 - pointers
JS to realize the conversion between string and array and an interview question