Moh*_*hit 8 filesystems directory
I have to use the dirent.h in some of my C projects. According to various different descriptions found online, I have come to a vague idea that directory entry is a data structure, which tells us everything about a file. What exactly is a directory entry?
Not everything about the file, most of the metadata about the file is stored within the file inode, not the directory entry. The directory entry is just a struct of inode and filename - just enough information to translate from a filename to an inode and get to the actual file.
You can safely imagine a directory as a dictionary:
filename1 :> inode1
filename2 :> inode2
....
Run Code Online (Sandbox Code Playgroud)
然后您只需按照 inode 编号(基本上是 inode 的唯一地址——一种指针)并找到所有权限、所有权数据、日期、扩展属性,当然还有文件的内容(如果它是一个文件) . 当然,目录条目也可以是另一个目录、符号链接、设备节点或类似的东西。你必须去那里弄清楚。
目录项基本上是文件名到其索引节点的映射。用户通常通过文件名访问文件,但是内核无法理解此类文件名。
内核使用文件唯一的索引节点来识别文件。
这个inode基本上包含了文件除了文件名和文件中的实际数据之外的所有数据。文件名到索引节点的这种映射是在称为目录项的数据结构中维护的。
请记住,许多条目(在相同或不同的目录中)可能标识相同的文件(相同的 inode)。所以,给定一个名字,你就可以很容易地获得它的inode;给定一个索引节点,查找名称要困难得多(find
实用程序就是实现此目的的工具)。