What is the connection and difference between Dentry and inode?

Source: Internet
Author: User

How are we going to describe a file in the process? We use directory entries (dentry) and Index nodes (inode). They are defined as follows :

struct Dentry {
struct Inode *d_inode; /* Where The name belongs To-null is
struct Dentry *d_parent; /* Parent Directory */
struct List_head d_child; /* Child of the parent list */
struct Dentry_operations *d_op;
struct Super_block *d_sb; /* The root of the dentry tree * *
void *d_fsdata; /* fs-specific Data */
unsigned char d_iname[dname_inline_len_min]; /* Small names */
......
};
struct Inode {
unsigned long I_ino;
atomic_t I_count;
umode_t I_mode;
unsigned int i_nlink;
uid_t I_uid;
gid_t I_gid;
dev_t I_rdev;
loff_t i_size;
struct Timespec i_atime;
unsigned long i_blocks;
unsigned short i_bytes;
unsigned char _sock;
12
struct Inode_operations *i_op;
struct File_operations *i_fop; /* Former->i_op->default_file_ops */
struct Super_block *i_sb;
......
};

so-called"file", is the information stored in a certain form on the media, so a file actually contains two aspects of information, one is the stored data itself, and the other is about the organization and management of the file information. In memory, each file has aDentry (Catalog Items)and theInode (Index Node)structure,Dentryrecord the file name, the parent directory and other information, it is the formation of the tree structure we see, and the Organization and management of the file information mainly storedInodeinside, it records the location and distribution of the file on the storage medium. AlsoDentry->d_inodepoint to the correspondingInodestructure. Dentrywith theInodeis a many-to-one relationship because it is possible that a file has several file names(Hard Links, hard link,You can refer to this pagehttp://www.ugrad.cs.ubc.ca/~cs219/CourseNotes/Unix/commands-links.html).

all the dentry are connected together with d_parent and d_child , forming a familiar tree structure.

Inoderepresents the physical meaning of the document, throughInodeyou can get an array that records the location of the contents of the file, if the file is located on the hard3,8,Tenblock, then the contents of this array are3,8,10. Its index node numberInode->i_inois unique in the same file system, and the kernel is simply based on theI_ino, it is possible to calculate the correspondingInodeThe position on the media. As far as the hard disk is concerned,I_inoIt is possible to calculate the correspondingInodewhich block belongs to(block)to find the appropriateInodestructure. But only withInodeIt is still not possible to describe all of the file systems, for a particular file system, such asext3, in memoryExt3_inode_infodescription. He is an inclusiveInodeof the"Container".

struct Ext3_inode_info {
__le32 i_data[15];
......
struct Inode vfs_inode;
};

Le32 I data[15] This array is the one mentioned in the previous paragraph.

Note that in the distant2.4Ancient, memory images of different file system index nodes(Ext3_inode_info,Reiserfs_inode_info,msdos_inode_info ...)It's all with aUnionembedded inInodein the data structure. butInodeas a very basic data structure, this is too large to facilitate the rapid allocation and recycling. But then it was invented.container_of (...)After this method, we putUnionmoved to the outside, we can use a similarcontainer of (inode, struct ext3_inode_info, Vfs_inode), fromInodeset out to get its"Container".

Dentry and inode are all in memory, and their original information must have a carrier. Otherwise, after the power outage is not finished? And listen to my slow way.

Files can be divided into disk files, device files, and special files of three kinds. The device file is not a table.

disk file
For disk files, dentry inode carrier in storage media ( . For disk files such as ext3
struct Ext3_inode {
__le16 i_mode;/* File mode */
__le16 i_uid;/* Low bits of OWN ER Uid */
__le32 i_size;/* Size in bytes */
__le32 i_atime;/* Access time */
__le32 i_ctime;/* Creation time * /
__le32 i_mtime;/* Modification time */

__le32 I_dtime; /* Deletion time */
__le16 I_gid; /* Low bits of Group Id */
__le16 I_links_count; /* Links count */
......
__le32 i_block[ext2_n_blocks];/* pointers to BLOCKS */
......
}
struct Ext3_dir_entry_2 {
__u32 Inode; /* Inode Number */
__u16 Rec_len; /* Directory Entry Length */
__u8 Name_len; /* Name Length */
__u8 File_type;
Char Name[ext3_name_len]; /* File Name */
};

Le32 i block[ext2 N blocks];/* pointers to BLOCKS * *
The I_block array indicates where the contents of the file reside ( on the hard disk ).

Ext3_inodeis placed in the index node area, andext3_dir_entry_2is stored in the data area in the form of a file content. We just need to know.Ino, sinceExt3_inodesize is known, we can calculate theExt3_inodeThe location of the index node area(Ino * sizeof (Ext3_inode)), and got theExt3_inode, we are based onI_blockyou can know where the data for this file is stored. On the diskExt3_inodethe content read into theExt3_inode_infothe function in isExt3_read_inode (). With aBlockhard drive, for example, a file system is organized in roughly the same layout. Each of the bitmap areas indicates that each corresponding object has not been used.

Special files
special files have inode and dentry data structures in memory, but do not necessarily have an " index node " on the storage medium , it really finished after power off, so do not need any carrier. When reading from a special file, the data read is generated by a certain rule within the system, or collected from memory, processed. Sysfs inside is a typical special document. The information it stores is generated dynamically by the system, which dynamically contains the hardware resources of the whole machine. reading and writing from Sysfs is equivalent to extracting data from the kobject hierarchy.

Please also note that,when we talk about catalog items and index nodes, there are two meanings. One is in storage media(HDD)in the(asExt3_inode), one is in memory, and the latter is based on the former. In-memory representations areDentryand theInode, it isVFSin the first layer, no matter what kind of file system, and finally in memory describes it isDentryand theInodestructure. We use different file systems to abstract their respective file information intoDentryand theInodeto the. So for the high-level, we can not care about the underlying implementation, we are using a series of standard function calls. This isVFSThe essence of this is actually object-oriented.

we open a file in the process F, in effect, is to build F 's dentry, and inode structures in memory, And let them relate to the process structure to connect the interfaces defined in the VFS. Let's take a look at this classic figure. This picture of the file system, like every day love you more than Jacky Cheung, tomato scrambled eggs in the Southern District of Fudan University canteen, unforgettable.

What is the connection and difference between Dentry 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.