linux - 实现 FUSE 时,为 st_nlink 设置什么属性?

标签 linux fs fuse

在实现 FUSE 库时,应通过 getattr() 回调定义目录的属性。

但是要为这个 st_nlink 设置什么?

在这个例子中,他们将其设置为2,但我不知道确切的原因。

https://github.com/lxc/lxcfs/blob/2ed933d959f54bee70985e260660a468ef9d21a1/src/proc_fuse.c#L87

st_nlink 是做什么用的?我的用户空间 FUSE 目录的默认值应该是 1 还是 2?

例如,如果我定义了一个名为“/dev”的目录,并且其中有“.”、“..”和“snd”子条目,那么“/dev”的st_nlink应该为2吗? 因为硬链接(hard link)(条目)是/dev/snd和/dev/snd/./

最佳答案

有趣,我确实阅读了以下内容。

st_nlink is the number of hard links to the file. This count keeps track of how many directories have entries for this file. If the count is ever decremented to zero, then the file itself is discarded as soon as no process still holds it open. Symbolic links are not counted in the total.

https://www.gnu.org/software/libc/manual/html_node/Attribute-Meanings.html

我假设"file"被使用了两次,并且它的 st_nlink 被设置为两次。

我还假设它用于重新计数设计 https://en.wikipedia.org/wiki/Reference_counting

关于linux - 实现 FUSE 时,为 st_nlink 设置什么属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62264562/

相关文章:

linux - fuse2 和 fuse3 到底有什么区别?

java - response.setContentType() 总是修剪 "; charset"之间的空间?

javascript - 使用 Nodejs 创建/更新 JavaScript 文件/代码

javascript - 使用 Node 搜索高于 X 的文件夹名称

node.js - axios 文件下载和存储导致文件损坏(编码问题)?

c - fuse 更改为?

linux - 如果未禁用,则禁用它并再次选择启用

linux - 如何从多线程 C++ Linux 应用程序安全地运行 shell 脚本?

Linux Makefile 项目调试最佳实践和工具

php - 如何将 S3 存储桶挂载到 EC2 实例并使用 PHP 写入?