Linux file system problems

Source: Internet
Author: User
Article title: linux file system issues. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Question 1: How does the kernel handle a specific file?

Answer:

(1) search in the directory item cache. Note that the query is performed through the Hasse function, and the query order is from right to left.

E.g.

Processing/usr/src/jiawei. c will start from jiawei. c and go up until the root directory, which is very efficient.

(2) if the cache does not exist, the file system will start from the root directory and start searching step by step.

In this case, first find the/Directory (root directory)'s dentry (directory item) and then its inode. its inode will have a special record for all the dentry at its next level, find the corresponding dentry and proceed as above. Then, find the file you want to find (note that there is no directory under linux, because the directory is also a file ).

Question 2: which inode does the d_inode in the dentry struct point?

Answer:

Remember to point to the inode of this dentry, rather than the inode of the next level.

Question 3: What is the vunsigned type in the dentry struct in vfs?

Answer:

The following is the source code downloaded from the Internet (with our own explanation ):

Struct dentry {

Atomic_t d_count; // counter used by the directory item object

Unsigned int d_flags; // Directory entry flag

Struct inode * d_inode; // The Index node associated with the file name. locate the inode from the pointer and find the file to be searched (this should be the case)

Struct dentry * d_parent; // Directory item object of the parent directory

Struct list_head d_hash; // pointer of the hash table item

Struct list_head d_lru; // A pointer that does not use a linked list

Struct list_head d_child; // chain of directory item objects in parent directory

Struct list_head d_subdirs; // for a directory, it indicates the linked list of the sub-directory item object.

Struct list_head d_alias; // linked list of the related index node (alias)

Int d_mounted; // indicates the root entry of the installed file system.

Struct qstr d_name; // file name

Unsigned long d_time;/* used by d_revalidate */

Struct dentry_operations * d_op; // Directory item method

Struct super_block * d_sb; // Super block object of the file

Vunsigned long d_vfs_flags;

Void * d_fsdata; // file system-related data

Unsigned char d_iname [DNAME_INLINE_LEN]; // Save the short file name

};

As a matter of fact, the data type is not used by kernel. you can find the latest version 2.6 and cannot find it. below is the dentry source code of 2.6.34.4.

Struct dentry {

Atomic_t d_count;

Unsigned int d_flags;/* protected by d_lock */

Spinlock_t d_lock;/* per dentry lock */

Int d_mounted;

Struct inode * d_inode;/* Where the name belongs

To-NULL is

* Negative */

/*

* The next three fields are touched

_ D_lookup.Place them here

* So they all fit in a cache line.

*/

Struct hlist_node d_hash;/* lookup hash list */

Struct dentry * d_parent;/* parent directory */

Struct qstr d_name;

Struct list_head d_lru;/* LRU list */

/*

* D_child and d_rcu can share memory

*/

Union {

Struct list_head d_child/* child of parent list */

Truct rcu_head d_rcu;

} D_u;

Struct list_head d_subdirs;/* our children */

Struct list_head d_alias;/* inode alias list */

Unsigned long d_time;/* used by d_revalidate */

Const 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 */

};

The above are some of the questions discussed by the fs team in our Xiyou linux interest group. let's talk about the results of our discussion. If you have any objection, please submit it. thank you!

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.