当前位置:网站首页>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
边栏推荐
- [LeetCode]-滑动窗口
- Chapter 13 abstraction: address space
- CMB's written test -- data analysis
- Kaggle 时间序列教程
- Explain the opencv function cv:: add() in detail, and attach sample code and running results of various cases
- QT brushes and brushes
- Explain the role of key attribute in V-for
- 详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
- Explain the differences and usage scenarios between created and mounted
- Section 2 - branch and loop statements
猜你喜欢
![C # get all callable methods of WebService interface [webmethod]](/img/44/4429b78c5b8341ed9a4a08d75a683e.png)
C # get all callable methods of WebService interface [webmethod]

Ruoyi cloud startup tutorial (hand-held graphics)

Sampo Lock

What is the saturate operation in opencv

关于匿名内部类

Interpretation of QT keypressevent

C language learning log 1.22

Section 3 - functions

Chapter 18 pagination: Introduction

Stepping on a horse (one stroke)
随机推荐
Advanced C - Section 3 - character functions and string functions
Clause 28: understanding reference folding
Introduction to QT XML
Bomb disposal cat
利用Javeswingjdbc基於mvc設計系統
[JS solution] leedcode 117 Populate the next right node pointer II for each node
C language learning log 1.19
C language exercise 1
QT realizes message sending and file transmission between client and server
Kaggle 时间序列教程
[LeetCode]-二分查找
C disk lossless move file
Clause 33: decltype is used for auto & type formal parameters, with std:: forward
Spice story
Section 5 - Operator details
[JS solution] leedcode 200 Number of islands
约瑟夫问题
C language learning log 1.17
C language learning log 11.7
UNO