在 Linux 中查找一个目录的最大深度
Find the maximum depth of one directory in Linux
最大深度是指最深的后代与该目录之间的距离。
有没有办法不用遍历所有文件系统树就可以得到目录的最大深度?或者我可以挖掘 Linux 内核代码的哪一部分来获得这个值?
Is there a way to obtain the maximum depth of a directory without traverse all the file system tree ?
user-space 中除了 readdir
/getdents
之外什么都没有 returns 单个目录的条目。
Or which part in Linux Kernel code I could dig in to get this value?
即使在内核中,VFS 也只需要每个文件系统的一个 "iterate" 函数。大多数文件系统都表示为一棵树,并且不会明确跟踪您请求的这个指标。没有意义。
你需要遍历树。
最大深度是指最深的后代与该目录之间的距离。
有没有办法不用遍历所有文件系统树就可以得到目录的最大深度?或者我可以挖掘 Linux 内核代码的哪一部分来获得这个值?
Is there a way to obtain the maximum depth of a directory without traverse all the file system tree ?
user-space 中除了 readdir
/getdents
之外什么都没有 returns 单个目录的条目。
Or which part in Linux Kernel code I could dig in to get this value?
即使在内核中,VFS 也只需要每个文件系统的一个 "iterate" 函数。大多数文件系统都表示为一棵树,并且不会明确跟踪您请求的这个指标。没有意义。
你需要遍历树。