Max Files Per Directory

Deron Meranda deron.meranda at gmail.com
Sun Jul 17 04:15:36 UTC 2005


It's basically unlimited for files only!

There IS a maximum number of subdirectories you can have per
any single directory.  For Linux kernels this is capped at 31999
subdirectories.  For comparison with some commercial Unixes:
HP-UX is 32767 and AIX is also 32767.

I actually hit this limit in a commercial application I helped develop,
so I'm well aware of it.

When you go over with the mkdir(1) command you'll get an error like:
   mkdir: cannot create directory `/tmp/x/31999': Too many links
or with the mkdir(2) system call you'll get errno = EMLINK.

The reason for this is that each subdirectory contains a ".."
entry, which increases the inode link count on its parent directory.
This is artifically capped at 32000 inside the Linux source code
(even though the field is a full 32-bit unsigned integer).

This is controled by these kernel include file lines:
  include/linux/ext2_fs.h:#define EXT2_LINK_MAX           32000
  include/linux/ext3_fs.h:#define EXT3_LINK_MAX           32000
  include/linux/ufs_fs.h:#define UFS_LINK_MAX 32000

Supposedly you could recompile the kernel yourself with these
increased if you wanted to go beyond 32000.

Do note though that for portability with other systems (Unixes,
NFS, tar command, etc.) you will want to stick to a 16-bit
integer because most other software besides the Linux kernel
only allocates a 16-bit field for the inode link count.

Deron Meranda




More information about the fedora-list mailing list