为什么inode编号从1开始而不是从0开始?

发布于 2024-08-18 07:03:09 字数 92 浏览 4 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦过后 2024-08-25 07:03:09

0 用作 sentinel 值 来指示 null 或没有 inode。类似于 C 中指针可以为 NULL,没有哨兵,您需要额外的位来测试结构中的 inode 是否已设置。

更多信息在这里:

所有块和索引节点地址开始于
1、磁盘上的第一个块是块1。0用于表示没有
堵塞。 (稀疏文件可以有这些
在它们里面)

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:

All block and inode addresses start at
1. The first block on the disk is block 1. 0 is used to indicate no
block. (Sparse files can have these
inside them)

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.

花期渐远 2024-08-25 07:03:09

通常,inode 0 是保留的,因为返回值 0 通常表示错误。 Linux内核中的多种方法——尤其是所有文件系统共享的VFS层——返回一个ino_t,例如find_inode_number

保留的 inode 编号较多。例如在 ext2 中:

#define EXT2_BAD_INO             1      /* Bad blocks inode */
#define EXT2_ROOT_INO            2      /* Root inode */
#define EXT2_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT2_UNDEL_DIR_INO       6      /* Undelete directory inode */

ext3 具有:

#define EXT3_BAD_INO             1      /* Bad blocks inode */
#define EXT3_ROOT_INO            2      /* Root inode */
#define EXT3_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT3_UNDEL_DIR_INO       6      /* Undelete directory inode */
#define EXT3_RESIZE_INO          7      /* Reserved group descriptors inode */
#define EXT3_JOURNAL_INO         8      /* Journal inode */

ext4 具有:

#define EXT4_BAD_INO             1      /* Bad blocks inode */
#define EXT4_ROOT_INO            2      /* Root inode */
#define EXT4_USR_QUOTA_INO       3      /* User quota inode */
#define EXT4_GRP_QUOTA_INO       4      /* Group quota inode */
#define EXT4_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT4_UNDEL_DIR_INO       6      /* Undelete directory inode */
#define EXT4_RESIZE_INO          7      /* Reserved group descriptors inode */
#define EXT4_JOURNAL_INO         8      /* Journal inode */

其他文件系统使用 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:

#define EXT2_BAD_INO             1      /* Bad blocks inode */
#define EXT2_ROOT_INO            2      /* Root inode */
#define EXT2_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT2_UNDEL_DIR_INO       6      /* Undelete directory inode */

and ext3 has:

#define EXT3_BAD_INO             1      /* Bad blocks inode */
#define EXT3_ROOT_INO            2      /* Root inode */
#define EXT3_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT3_UNDEL_DIR_INO       6      /* Undelete directory inode */
#define EXT3_RESIZE_INO          7      /* Reserved group descriptors inode */
#define EXT3_JOURNAL_INO         8      /* Journal inode */

and ext4 has:

#define EXT4_BAD_INO             1      /* Bad blocks inode */
#define EXT4_ROOT_INO            2      /* Root inode */
#define EXT4_USR_QUOTA_INO       3      /* User quota inode */
#define EXT4_GRP_QUOTA_INO       4      /* Group quota inode */
#define EXT4_BOOT_LOADER_INO     5      /* Boot loader inode */
#define EXT4_UNDEL_DIR_INO       6      /* Undelete directory inode */
#define EXT4_RESIZE_INO          7      /* Reserved group descriptors inode */
#define EXT4_JOURNAL_INO         8      /* Journal inode */

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).

一世旳自豪 2024-08-25 07:03:09

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

冷月断魂刀 2024-08-25 07:03:09

当我很久以前编写文件系统时,我使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文