为什么inode编号从1开始而不是从0开始?
C语言约定从0开始计算数组索引。为什么inode编号从1开始而不是从0开始?
如果inode 0被保留是为了某些特殊用途,那么inode 0有什么意义呢?
The C language convention counts array indices from 0. Why do inode numbers start from 1 and not 0?
If inode 0 is reserved is for some special use, then what is the significance of inode 0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
0 用作 sentinel 值 来指示 null 或没有 inode。类似于 C 中指针可以为 NULL,没有哨兵,您需要额外的位来测试结构中的 inode 是否已设置。
更多信息在这里:
http://uranus.chrysocome.net/explore2fs/es2fs.htm
例如,在旧的文件系统中,目录被表示为固定的文件条目数组,删除文件将导致将该条目的 inode val 设置为 0。遍历目录时,任何 inode 为 0 的条目都将被忽略。
0 is used as a sentinel value to indicate null or no inode. similar to how pointers can be NULL in C. without a sentinel, you'd need an extra bit to test if an inode in a struct was set or not.
more info here:
http://uranus.chrysocome.net/explore2fs/es2fs.htm
for instance, in old filesystems where directories were represented as a fixed array of file entries, deleting a file would result in setting that entry's inode val to 0. when traversing the directory, any entry with an inode of 0 would be ignored.
通常,inode 0 是保留的,因为返回值 0 通常表示错误。 Linux内核中的多种方法——尤其是所有文件系统共享的VFS层——返回一个ino_t,例如find_inode_number。
保留的 inode 编号较多。例如在 ext2 中:
和 ext3 具有:
和 ext4 具有:
其他文件系统使用 ino 1 作为根 inode 号。一般来说,文件系统可以自由选择其 inode 号及其保留 ino 值(0 除外)。
Usually, the inode 0 is reserved because a return value of 0 usually signals an error. Multiple method in the Linux kernel -- especially in the VFS layer shared by all file systems -- return an ino_t, e.g. find_inode_number.
There are more reserved inode numbers. For example in ext2:
and ext3 has:
and ext4 has:
Other fileystems use the ino 1 as root inode number. In general, a file system is free to choose its inode numbers and its reserved ino values (with the exception of 0).
OSX指定inode 0表示已删除文件,尚未删除;这可能也被用在其他文件系统中,因为 OSX 是 BSD 派生的,尽管至少 NetBSD 现在似乎已经删除了这种用法。
请参阅 getdirentries 的 OSX 联机帮助页 http: //developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man2/getdirentries.2.html
OSX specifies that inode 0 signifies a deleted file that has not yet been deleted; this may have also been used in other filesystems, as OSX is BSD-derived, although at least NetBSD seems to have now removed this usage.
See the OSX manpage for getdirentries http://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man2/getdirentries.2.html
当我很久以前编写文件系统时,我使用 inode 0 作为
.badblocks
伪文件。在某些文件系统上,
.badblocks
实际上作为 root 拥有的常规文件和模式 0 存在于根目录中。root 可以打开它,但读取或写入它是未定义的。有一些古老的传统,索引节点从1开始,#1是
.badblocks
,#2是根目录。尽管.badblocks
没有得到特别好的保证,但许多文件系统还是不遗余力地使 root #2。When I wrote a filesystem ages ago, I used inode 0 for the
.badblocks
pseudo-file.On some filesystems
.badblocks
is actually present in the root directory as a regular file owned by root and mode 0. root can open it but reading or writing it is undefined.There is some ancient tradition that inodes start from 1, #1 is
.badblocks
, and #2 is the root directory. Even though.badblocks
is not particularly well-guaranteed, many filesystems go out of their way to make root #2.