Home > Blockchain >  How to obtain the maximum number of subdirectories in a directory from a C program on Linux?
How to obtain the maximum number of subdirectories in a directory from a C program on Linux?

Time:12-04

I know the maximum number of files or directories in a directory, varies depending on the filesystem.

From within a C program on Linux, how to obtain the maximum number of directory files in a directory below the current working directory (or determine there is no maximum other than the size of the universe/computer)?

There is probably some #define constant somewhere, or perhaps, some entry in some configuration file, but I can't find either. Do I have to find out what filesystem is for my current directory, and then use the knowledge of that filesystem?

CodePudding user response:

There is no specific limit on the number of files or subdirectories within a given directory. There are limits on the total number of inodes in a file system depending on how the file system was built and (mostly) how much space there is in total in the file system. Each named object requires an inode (but, thanks to hard links, a single inode can have multiple names). Thus, the limit is primarily controlled by the space available in the file system.

There are usually limits on how deep a directory hierarchy can be — that's the POSIX constant {PATH_MAX} defined (or not) in <limits.h>, and the related lower-bounds on the minimum acceptable value for {PATH_MAX}{_XOPEN_PATH_MAX} (1024) and {_POSIX_PATH_MAX} (256).

You can use the functions fpathconf() and pathconf() to find properties of file systems at run-time. The related function sysconf() handles other configuration properties.

  • Related