[File System] File System Study Notes (1) --- basic concepts and inode

Source: Internet
Author: User

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
  1. <PRE name = "code" class = "CPP"> <fs. h>
  2. Struct inode {
  3. Struct hlist_node I _hash;
  4. Struct list_head I _list;
  5. Struct list_head I _sb_list;
  6. Struct list_head I _dentry;
  7. Unsigned long I _ino; // unique ID of each inode
  8. Atomic_t I _count; <span style = "white-space: pre"> </span> // record the number of processes using this inode
  9. Unsigned int I _nlink; <span style = "white-space: pre"> </span> // number of hard connections using this inode
  10. Uid_t I _uid; <span style = "white-space: pre"> </span> // user of the file
  11. Gid_t I _gid; <span style = "white-space: pre"> </span> // The group of the object
  12. 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.
  13. Unsigned long I _version;
  14. Loff_t I _size; <span style = "white-space: pre"> </span> // file length, in bytes
  15. Struct timespec I _atime; // last file access time
  16. Struct timespec I _mtime; <span style = "white-space: pre"> </span> // last file modification time
  17. Struct timespec I _ctime; // The time when the inode structure itself was last modified
  18. Unsigned int I _blkbits;
  19. Blkcnt_t I _blocks; <span style = "white-space: pre"> </span> // block-based file length
  20. Umode_t I _mode; <span style = "white-space: pre"> </span> // File Permission
  21. 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
  22. Const struct file_operations * I _fop;/* former-> I _op-> default_file_ops * // operations on file content, setting file location pointers, etc.
  23. Struct super_block * I _sb;
  24. Struct address_space * I _mapping;
  25. Struct address_space I _data;
  26. Struct dquot * I _dquot [maxquotas];
  27. Struct list_head I _devices;
  28. Union {
  29. Struct pipe_inode_info * I _pipe; // Pipe
  30. Struct block_device * I _bdev; <span style = "white-space: pre"> </span> // block Device
  31. Struct cdev * I _cdev; <span style = "white-space: pre"> </span> // character device
  32. };
  33. Int I _cindex;
  34. _ U32 I _generation;
  35. Unsigned long I _state;
  36. Unsigned long dirtied_when;/* jiffies of first dirtying */
  37. Unsigned int I _flags;
  38. Atomic_t I _writecount;
  39. Void * I _security;
  40. };



 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.