How does the UNIX kernel get an inode from a filename?
I am confused as to how the UNIX kernel gets an inode from a filename. Say I have the fi开发者_StackOverflowle "/usr/data/tmp/testme.txt". How would the kernel locate the inode for it?
Essentially, the whole path is taken apart into components and then walked from top down resolving directory entries and mount points. Cases of absolute and relative path differ slightly. This seems slow but kernel does a fair bit of caching for name lookup. Traditionally this was the namei()
function in the VFS. You can try following the (admittedly pretty hairy) code for example here.
Each directory is stored as a file of records, and in that record there is the directory-local file name ("testme.txt") and the number of the inode.
[http://www.linuxquestions.org/questions/blog/mr-ameya-sathe-352399/inode-and-its-corresponding-filename-2126/]
ls -i [http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes.html]
the above is the link.. this post can be deleted or consolidated. sorry for the duplicate question.
精彩评论