如下图所示,创建一个tempdir文件夹,然后批量创建子文件夹:
先创建64998个子文件夹,可以看到link_count从2增加到65000个,符合预期;
再创建1个文件夹,查看link_count竟然变成了1;并且将子文件夹数量删掉一些,保持在64998个以内,link_count也没恢复至正确的数值。
查看文件系统类型,是ext4
原理
0x1A | __le16 | i_links_count | Hard link count. Normally, ext4 does not permit an inode to have more than 65,000 hard links. This applies to files as well as directories, which means that there cannot be more than 64,998 subdirectories in a directory (each subdirectory's '..' entry counts as a hard link, as does the '.' entry in the directory itself). With the DIR_NLINK feature enabled, ext4 supports more than 64,998 subdirectories by setting this field to 1 to indicate that the number of hard links is not known. |
参考资料
196405 – mkdir mishandles st_nlink in ext4 directory with 64997 subdirectories