After the kernel unlocks rootfs. initramfs, VFS builds a tree in the kernel. We write a simple code to traverse the tree:
Static void vfswalk (cvfswalk * pwalk, void * pparent, dentry * pentry)
{
// Insert all child nodes
Struct dentry * pnode;
Void * plast = NULL;
List_for_each_entry (struct dentry, pnode, & pentry-> d_subdirs, d_u.d_child)
{
Plast = pwalk-> insert (char *) pnode-> d_name.name, pparent, plast );
Vfswalk (pwalk, plast, pnode );
}
}
Void vfswalk (cvfswalk * pwalk)
{
// Insert all nodes
Struct dentry * pentry = Current-> nsproxy-> mnt_ns-> root-> mnt_root;
Void * proot = pwalk-> insert ("/", null, null );
Vfswalk (pwalk, proot, pentry );
}
Cvfswalk encapsulates the insertitem function of ctreectrl, so that each node found in VFS will be created on the tree control accordingly.
Traverse the dentry from the root file system and use only the d_subdirs Member of the struct dentry struct.
The experiment results show that:
1. Each common file or directory is represented by a dentry struct.
2. For the symbolic file linked to the directory, the dentry subnode is empty.
Well, continue learning about the kernel ~~~
Recently, my 6-year-old girl took part in the sixth pop National Children's English style competition, canvassing in progress (Before ).
Click the link of the New Oriental Website:
Http://popdasai.xdf.cn/toupiao.php? Do = Space & UUID = 4237
Vote for her. Thank you!