When implementing FUSE library, attributes for the directories should be defined by getattr() callback.
But what to set for this st_nlink?
In this example, they set it to 2, but I don't know the exact reason.
https://github.com/lxc/lxcfs/blob/2ed933d959f54bee70985e260660a468ef9d21a1/src/proc_fuse.c#L87
What is st_nlink for? And should it be 1 or 2 as default for my user-space FUSE directories?
For example, if I define a directory called "/dev", and there are ".", ".." and "snd" sub-entries in it, should the st_nlink for "/dev" be 2? Because the hard link (entry) are /dev/snd and /dev/snd/./
Interesting, I did read the following.
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
I assume the "file" is being used twice, and there for it's st_nlink is being set to two.
I also assume it is used for a reface counting design https://en.wikipedia.org/wiki/Reference_counting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With