Buffer_head static struct * find_entry (struct m_inode * dir, const char * name, int namelen, struct dir_entry * * Res_dir)
Find_entry is a more puzzling function in the Linux file system. Let's analyze it below.
Its first parameter is the M_inode type, which indicates the Inode node of the root directory where the function operation is located. That is, the starting node of the relative path.
Name is naturally the directory path you want to find, and Namelen is the length of the directory name.
The Res_dir is returned as a pointer to the catalog item you want to find.
The function return value is the buffer_head corresponding to the block that contains the catalog entry.
Why is there a two return value? We know that, under the Ext2 file system, directories exist as files, and the Inode is the index of the directory.
The Inode-directed block stores information about the files and subdirectories contained in the directory. It exists in the following structure.
dir_entry struct {141 unsigned short inode;142
The name array stores the file name, and the Inode stores the inode number. So the directory file is actually a file, but the content of the file is a
Dir_entry structure, therefore, it may occupy a block or occupy multiple blocks as well as ordinary files.
The function of the Find_entry function is to find the block that stores the dir_entry of the name parameter corresponding to the file, and return it in buffer_head form, and
Returns the corresponding dir_entry of the file as a pointer.
Linux Source code reading note Find_entry Analysis