Concept:
① Hard Link: If an inode number corresponds to more than one file name, these files are called hard links. That is, a hard link is the same file that uses multiple aliases. Hard links can be created by the command link or ln.
Its characteristics:
- The file has the same inode and data block;
- Only files that already exist can be created;
- Cannot cross file system for hard link creation;
- The directory cannot be created, only the file can be created;
- Deleting a hard-link file does not affect other files that have the same inode number.
② Soft Connection: If the contents of the file user data block are pointing to the path name of another file, then the file is a soft connection. Soft link is a normal file, but the content of the data block is a bit special. Soft links have their own inode numbers and user data blocks
Its characteristics:
- Soft links have their own file attributes and permissions, etc.;
- You can create a soft link to a nonexistent file or directory;
- Soft link can cross file system;
- Soft links can be created on files or directories;
- When you create a soft link, the link count i_nlink not increase;
- Deleting a soft link does not affect the file being pointed to, but if the original file being pointed to is deleted, the associated soft connection is called a dead link (that is, dangling link, if it is re-created by pointing to the path file, the dead link can revert to the normal soft link).
The difference between the two:
③ Basic Concepts:
Files: General Documents
Catalog item (Dentry): That is, each directory unit in the path is a catalog item.
Index node (inode): The structure of the record file properties.
Mount point:
④linux VFS has four basic objects:
Super Block Objects (Superblock object): Represents an installed file system.
Index node objects (Inode object): Represents a file.
Catalog Item Object (Dentry object): Represents a directory entry, such as a device file event5 in Path/DEV/INPUT/EVENT5, which has four directory item objects:/, dev/, input/, and EVENT5.
File object: Represents a file opened by a process.
Processing between the objects of the VFS
The Inode and inode_operations structure in VFS
1 structInode {2 ... 3 Const structInode_operations *i_op;//Index node Operations4UnsignedLongI_ino;//Index Node Number5atomic_t I_count;//Reference Counter6UnsignedintI_nlink;//number of hard links7 ... 8 } 9 Ten structinode_operations { One ... A int(*create) (structInode *,structDentry *,int,structNameidata *); - int(*link) (structDentry *,structInode *,structDentry *); - int(*unlink) (structInode *,structDentry *); the int(*symlink) (structInode *,structDentry *,Const Char*); - int(*mkdir) (structInode *,structDentry *,int); - int(*rmdir) (structInode *,structDentry *); - ... +}Struct Inode
There are two counters per file: I_count and I_nlink, that is, reference count and hard link count. The i_count in the struct inode is used to track the number of files accessed, while I_nlink is the number of hard links to the file seen using commands such as ls-l. Or I_count trace the file in memory, and I_nlink is the disk counter. When the file is deleted, the I_nlink is set to 0 first. These two counters of the file make the Linux system upgrade or program update easy. The system or program can not be closed (that is, the file I_count is not 0), the new file is replaced with the same file name, the new file has its own inode and data block, the old file will be completely deleted after the relevant process is closed.
⑤ in Linux everything is a file except for the process.
Linux Kernel learning Note--VFS