1. Basic concepts of file systems
A file system is a method used to store and organize computer files, directories, and the data it contains. It simplifies searching and accessing files, directories, and data.
2. Differences between hard and soft links
Differences between hard and soft links
-Symbolic Link
-Ln-s file1 file2
• Directory item. The content is a pointer to the file name, and no other data exists. When the target file is deleted, the symbolic link remains unchanged. An independent inode is used. The inode data segment contains a string that provides the path of the link directory. (Equivalent to a shortcut in Windows)
-Hard Link
-Ln file1 file2
• Share an inode with the original file to increase the reference count. When you create or delete a hard link, the reference count is increased or decreased accordingly. If the value is 0, the source file is deleted;
• The same is true for dentry and inode.
3. struct inode struct
Inode nodes in the Virtual File System refer to inode nodes in the memory, which contain information not available to inode nodes on the actual hard disk.
[CPP]View plaincopy
- <PRE name = "code" class = "CPP"> <fs. h>
- Struct inode {
- Struct hlist_node I _hash;
- Struct list_head I _list;
- Struct list_head I _sb_list;
- Struct list_head I _dentry;
- Unsigned long I _ino; // unique ID of each inode
- Atomic_t I _count; <span style = "white-space: pre"> </span> // record the number of processes using this inode
- Unsigned int I _nlink; <span style = "white-space: pre"> </span> // number of hard connections using this inode
- Uid_t I _uid; <span style = "white-space: pre"> </span> // user of the file
- Gid_t I _gid; <span style = "white-space: pre"> </span> // The group of the object
- Dev_t I _rdev; <span style = "white-space: pre"> </span> // when the inode indicates the device file, it indicates which device file to communicate with. It is only a number.
- Unsigned long I _version;
- Loff_t I _size; <span style = "white-space: pre"> </span> // file length, in bytes
- Struct timespec I _atime; // last file access time
- Struct timespec I _mtime; <span style = "white-space: pre"> </span> // last file modification time
- Struct timespec I _ctime; // The time when the inode structure itself was last modified
- Unsigned int I _blkbits;
- Blkcnt_t I _blocks; <span style = "white-space: pre"> </span> // block-based file length
- Umode_t I _mode; <span style = "white-space: pre"> </span> // File Permission
- Struct inode_operations * I _op; <span style = "white-space: pre"> </span> // inode operation, create a connection, rename a file, create a file under the directory, and delete the file
- Const struct file_operations * I _fop;/* former-> I _op-> default_file_ops * // operations on file content, setting file location pointers, etc.
- Struct super_block * I _sb;
- Struct address_space * I _mapping;
- Struct address_space I _data;
- Struct dquot * I _dquot [maxquotas];
- Struct list_head I _devices;
- Union {
- Struct pipe_inode_info * I _pipe; // Pipe
- Struct block_device * I _bdev; <span style = "white-space: pre"> </span> // block Device
- Struct cdev * I _cdev; <span style = "white-space: pre"> </span> // character device
- };
- Int I _cindex;
- _ U32 I _generation;
- Unsigned long I _state;
- Unsigned long dirtied_when;/* jiffies of first dirtying */
- Unsigned int I _flags;
- Atomic_t I _writecount;
- Void * I _security;
- };
The I _mapping Member points to the memory space of the file. the actual content of the file to be accessed is accessed by the Member. address_space is used to manage the page mapped to the memory of the file.
The I _mapping member in the inode structure aims to cache the file content. Read and Write operations on the file first look for the file content in the cache contained in I _mapping. If there is a cache, read/write operations on files can be obtained directly from the cache, instead of reading files from the physical hard disk. Write operations are first written to the cache and then written to the disk by the cache at the appropriate time.
Each inode has an I _list member to store inode in a linked list. According to the inode status, there are three main scenarios:
(1) inode is in the memory and is not associated with any files and is inactive.
(2) inode is in memory and is being used by one or more processes. It usually indicates a file. At this time, I _count and I _nlink are both greater than 0.
Both the file content and underlying metadata share the same information on the underlying disk,
(3) inode is active and its data content has changed. Unlike the content on the storage medium, inode nodes in this state are dirty.
Superblock is used to manage all inode-related information in the file system, such as adding inode and the starting address of each inode.
If the size of a partition is 1 GB, each block is 4 kb, and one inode is B, it is assumed that each file occupies two blocks on average. So the number of inode is 1 GB/(8 KB + 129055.5 B) = 129055, that is. The inode table size is 129055*15.75 B = Mb. Therefore, according to this plan, if a 1 GB disk is used, after formatting, 15.75mb is used.
3. Command for viewing file inode Information
STAT command
[File System] File System Study Notes (1) --- basic concepts and inode