开发者

inodes handling of directories

开发者 https://www.devze.com 2023-01-25 21:17 出处:网络
I am trying to understand how directories and files relate to one another at the file system level, specifically *nix file systems like FFS or EXT.

I am trying to understand how directories and files relate to one another at the file system level, specifically *nix file systems like FFS or EXT.

I understand conceptually that an inode has some开发者_如何学Go metadata and pointers to a files location, but how do they keep the directory information and also know which files are in which directory?


A directory also has an inode. However, it does not contain pointers to the locations of the file's contents (as it isn't a file) but pointers to the inodes of the files/subdirs of the directory (so it's basically a file, buth with special contents/flags). Additionally it contains pointers to the parent directory and itself.

To reach a certain file the directory structure is simply traversed, much like when traversing a tree - to find out the full path of a file, the pseudocode looks like that:

parts = []
inode = inode_of(file);
parts.add(inode.name);
while(inode.parent):
    parts.add(inode.parent.name)
    inode = inode.parent
path = parts.reverse.join('/')


A directory is just a special kind of file. Its inode has the S_IFDIR bit set in the mode field. Its content is some data structure that holds filenames and inode numbers.


you might start by reading this http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes.html

0

精彩评论

暂无评论...
验证码 换一张
取 消