Author: Unknown
Source: http://www.i170.com/user/grip2/Article_8613
I will call the inode structure in the memory as VFS inode in the case of confusion, while the file
The system uses ext2 as the representative and uses ext2 inode as the inode of the disk.
First, we need to describe the inode in the memory and the inode on the disk separately:
<Inode structure in memory:>
VFS inode includes file access permissions, owner, group, size, generation time, access time,
Last modification time and other information. It is the most basic unit for Linux to manage file systems and also the file system.
Connect any sub-directories and files. The static information in the inode structure is taken from the physical device.
File System, which is filled in by the function specified by the file system. It only exists in the memory and can be entered through
Inode cache access. Although each file has an inode node
The system will establish an inode data structure for it in the memory.
As a linked list, we can traverse the linked list to get the file node we need.
Construct cache and hash table for allocated inode to improve system performance. In the inode structure
Struct inode_operations * IOP provides a list of inode operations.
The list provides functions that we can perform various operations on VFS inode nodes. Each inode structure has
There is an I node number I _ino, which is unique in the same file system.
<Inode on disk:>
Ext2 uses inode to define the structure of the file system and describe the structure of each file in the system
Management information. Each file has only one inode. Even if there is no data in the file
The index Node also exists. Each file is described using a separate ext2 inode structure, and
Each inode has a unique identifier. Ext2 inode provides the description for the inode structure in the memory.
As the inode structure in the memory changes, the system will also update the inode in the ext2
The corresponding content. Ext2 inode corresponds to the ext2_inode structure.
As described above, we can compare inode in memory with inode in Disk:
Location: The VFS inode structure is in the memory, while the ext2_inode structure is in the disk.
Lifetime: VFS inode is created only when needed. If the system is powered off, the structure disappears.
The existence of ext2_inode is irrelevant to whether the system is powered on, and whether or not the file contains
Data and ext2_inode all exist.
Uniqueness: the two are unique in their own scopes.
Relationship: VFS inode is the abstraction, ing, and expansion of ext2 inode, while the latter is the static
Information is also the embodiment, instantiation, and persistence of the former.
Operation: VFS inode operations are universal. inode operations on file systems are file systems.
Depends on specific implementations.
Organization Management: The system organizes VFS inode linked lists to improve access efficiency.
Correspondingly, inode is constructed to construct the cache and hash table.
The ext2 inode information is located in the block group of the ext2 file system.
Contains the corresponding inode bitmap and inode information specified by the inode table.
Inode corresponds to the ext2_inode structure.
In principle, the inode in the memory is compared with the inode in the disk. In fact, it is also reflected in the Code.
They are different. Below I will post the structure code corresponding to the two in the kernel, although long
Some, but it is very good for further comparison.
Struct inode {
Struct list_headi_hash;
Struct list_headi_list;
Struct list_headi_dentry;
Struct list_headi_dirty_buffers;
Unsigned longi_ino;
Atomic_ti_count;
Kdev_ti_dev;
Umode_ti_mode;
Nlink_ti_nlink;
Uid_ti_uid;
Gid_ti_gid;
Kdev_ti_rdev;
Loff_ti_size;
Time_ti_atime;
Time_ti_mtime;
Time_ti_ctime;
Unsigned longi_blksize;
Unsigned longi_blocks;
Unsigned longi_version;
Unsigned shorti_bytes;
Struct semaphorei_sem;
Struct rw_semaphorei_truncate_sem;
Struct semaphorei_zombie;
Struct inode_operations * I _op;
Struct file_operations * I _fop;/* former-> I _op-> default_file_ops */
Struct super_block * I _sb;
Wait_queue_head_ti_wait;
Struct file_lock * I _flock;
Struct address_space * I _mapping;
Struct address_spacei_data;
Struct dquot * I _dquot [maxquotas];
/* These three shoshould probably be a Union */
Struct pipe_inode_info * I _pipe;
Struct block_device * I _bdev;
Struct char_device * I _cdev;
Unsigned longi_dpolicy_mask;/* Directory Policy events */
Struct dnotify_struct * I _dnotify;/* for directory Communications */
Unsigned longi_state;
Unsigned inti_flags;
Unsigned chari_sock;
Atomic_ti_writecount;
Unsigned inti_attr_flags;
_ U32i_generation;
Union {
Struct minix_inode_infominix_ I;
Struct ext2_inode_infoext2_ I;
Struct ext3_inode_infoext3_ I;
Struct hpfs_inode_infohpfs_ I;
Struct ntfs_inode_infontfs_ I;
Struct msdos_inode_infomsdos_ I;
Struct umsdos_inode_infoumsdos_ I;
Struct iso_inode_infoisofs_ I;
Struct sysv_inode_infosysv_ I;
Struct affs_inode_infoaffs_ I;
Struct ufs_inode_infoufs_ I;
Struct efs_inode_infoefs_ I;
Struct romfs_inode_inforomfs_ I;
Struct shmem_inode_infoshmem_ I;
Struct coda_inode_infocoda_ I;
Struct smb_inode_infosmbfs_ I;
Struct hfs_inode_infohfs_ I;
Struct adfs_inode_infoadfs_ I;
Struct qnx4_inode_infoqnx4_ I;
Struct reiserfs_inode_inforeiserfs_ I;
Struct bfs_inode_infobfs_ I;
Struct udf_inode_infoudf_ I;
Struct ncp_inode_infoncpfs_ I;
Struct proc_inode_infoproc_ I;
Struct socketsocket_ I;
Struct usbdev_inode_info usbdev_ I;
Struct jffs2_inode_infojffs2_ I;
Void * generic_ip;
} U;
};
Struct ext2_inode {
_ U16i_mode;/* file mode */
_ U16i_uid;/* low 16 bits of owner uid */
_ U32i_size;/* size in bytes */
_ U32i_atime;/* Access time */
_ U32i_ctime;/* creation time */
_ U32i_mtime;/* modification time */
_ U32i_dtime;/* Deletion time */
_ U16i_gid;/* low 16 bits of group ID */
_ U16i_links_count;/* links count */
_ U32i_blocks;/* blocks count */
_ U32i_flags;/* file flags */
Union {
Struct {
_ U32 l_ I _reserved1;
} Linux1;
Struct {
_ U32 h_ I _translator;
} Hurd1;
Struct {
_ U32 m_ I _reserved1;
} Masix1;
} Osd1;/* OS dependent 1 */
_ U32i_block [ext2_n_blocks];/* pointers to blocks */
_ U32i_generation;/* file version (for NFS )*/
_ U32i_file_acl;/* File ACL */
_ U32i_dir_acl;/* directory ACL */
_ U32i_faddr;/* fragment address */
Union {
Struct {
_ U8l_ I _frag;/* fragment Number */
_ U8l_ I _fsize;/* fragment size */
_ U16i_pad1;
_ U16l_ I _uid_high;/* These 2 fields */
_ U16l_ I _gid_high;/* were reserved2 [0] */
_ U32l_ I _reserved2;
} Linux2;
Struct {
_ U8h_ I _frag;/* fragment Number */
_ U8h_ I _fsize;/* fragment size */
_ U16h_ I _mode_high;
_ U16h_ I _uid_high;
_ U16h_ I _gid_high;
_ U32h_ I _author;
} Hurd2;
Struct {
_ U8m_ I _frag;/* fragment Number */
_ U8m_ I _fsize;/* fragment size */
_ U16m_pad1;
_ U32m_ I _reserved2 [2];
} Masix2;
} Osd2;/* OS dependent 2 */
};
From the definition of the structure, we can see that inode (VFS inode) and ext2_inode are very different,
Except for the same, they are all different. They both contain dynamic and static information.
It is dynamic. The Union u in the inode structure actually reflects the file systems supported by VFS.
It can be seen that the inode structure is similar to the ext2_inode structure, for example, the inode-defined
Unsigned longi_ino;
Umode_ti_mode;
Nlink_ti_nlink;
Uid_ti_uid;
Gid_ti_gid;
Loff_ti_size;
Time_ti_atime;
Time_ti_mtime;
Time_ti_ctime;
Unsigned longi_blksize;
Unsigned longi_blocks;
And ext2_inode definition section
_ U16i_mode;/* file mode */
_ U16i_uid;/* low 16 bits of owner uid */
_ U32i_size;/* size in bytes */
_ U32i_atime;/* Access time */
_ U32i_ctime;/* creation time */
_ U32i_mtime;/* modification time */
_ U32i_dtime;/* Deletion time */
_ U16i_gid;/* low 16 bits of group ID */
_ U16i_links_count;/* links count */
_ U32i_blocks;/* blocks count */
_ U32i_flags;/* file flags */
These can correspond to, of course, there are some differences, such as
Kdev_ti_rdev;
Kdev_ti_dev;
Kdev_ti_dev;
Unsigned shorti_bytes;
Struct semaphorei_sem;
Ext2_inode is not reflected, but this part is useless for ext2_inode and cannot be determined.
Similarly, it can be extended to the rest of the two structures, and the difference in the Code is analyzed with the principle.
The difference is also a concrete embodiment of the principle.