当前位置:网站首页>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
边栏推荐
- Win8.1和Win10各自的優勢
- Mind mapping series - Database
- Flutter dart variables and constants
- Sampo Lock
- Article 29: assuming that the mobile operation does not exist, is expensive, and is not used
- Luogu p1088 Martians
- 利用Javeswingjdbc基于mvc设计系统
- C language learning log 1.22
- josephus problem
- C language learning log 12.25
猜你喜欢

What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM

Configuration used by automatic teaching evaluation script

Explain the opencv function cv:: add() in detail, and attach sample code and running results of various cases

Bm1z002fj-evk-001 startup evaluation

Mind mapping series - Database

Cesium:cesiumlab makes image slices and loads slices

Avantages de win8.1 et win10

OpenCV中的saturate操作(饱和操作)究竟是怎么回事

Draw a hammer

Advantages of win8.1 and win10
随机推荐
Ruoyi cloud startup tutorial (hand-held graphics)
Advanced C - Section 2 - pointers
PostgreSQL Guide: Insider exploration (Chapter 7 heap tuples and index only scanning) - Notes
Optocoupler working principle function electric parameter application circuit
How to lay copper in AD (aluminum designer)
Kaggle 时间序列教程
C language learning log 11.7
Win8.1和Win10各自的優勢
C language learning log 1.19
C language learning log 10.19
关于匿名内部类
QT using layout manager is invalid or abnormal
[leetcode]- sliding window
C language learning log 10.11
Simple-SR:Best-Buddy GANs for Highly Detailed Image Super-Resolution论文浅析
shell变量学习笔记
Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
Luogu p3654 fisrt step
C language learning log 12.5
Reductive elimination