目录的 inode 处理
我试图了解目录和文件在文件系统级别如何相互关联,特别是像 FFS 或 EXT 这样的 *nix 文件系统。
我从概念上理解索引节点有一些元数据和指向文件位置的指针,但是它们如何保留目录信息并知道哪些文件位于哪个目录中?
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 metadata and pointers to a files location, but how do they keep the directory information and also know which files are in which directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
目录也有一个索引节点。但是,它不包含指向文件内容位置的指针(因为它不是文件),而是指向目录的文件/子目录的索引节点(因此它基本上是一个文件,但具有特殊内容/标志) 。此外,它还包含指向父目录及其自身的指针。
要到达某个文件,只需遍历目录结构,就像遍历树一样 - 为了找出文件的完整路径,伪代码如下所示:
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:
目录只是一种特殊的文件。它的索引节点在模式字段中设置了 S_IFDIR 位。它的内容是一些保存文件名和索引节点号的数据结构。
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.
你可以从阅读这篇文章开始
http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem -inodes.html
you might start by reading this
http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes.html