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

标签 c linux filesystems inode superblock

C 语言约定从 0 开始计算数组索引。为什么 inode 编号从 1 而不是 0 开始?

如果保留inode 0是为了一些特殊用途,那么inode 0有什么意义呢?

最佳答案

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

更多信息在这里:

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

例如,在旧文件系统中,目录表示为文件条目的固定数组,删除文件会导致将该条目的 inode val 设置为 0。遍历目录时,inode 为 0 的任何条目都将被忽略.

关于c - 为什么 inode 编号从 1 而不是 0 开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2099121/

相关文章:

c++ - 我们可以减少现有文件的大小吗?

linux - Shell Scripting ssh 执行命令

linux - mongoDB (result= signal , code = killed , signal = ill

动态lib(.so)版本的兼容性

powershell - 有什么方法可以在指定时间过滤所有文件吗?

c++ - 如何在 C++ 程序中使用参数为 "this"的 C 函数?

c - 如何对齐内存地址?

c - 在 udp 服务器中实现并发

powershell - 在远程命令中使用局部变量的问题

docker - Docker 将运行容器的内容存储在哪里?