tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Filesystem limits



On Sun, Jan 17, 2010 at 2:17 PM, Sad Clouds
<cryintothebluesky%googlemail.com@localhost> wrote:
> On Sunday 17 January 2010 02:24:42 der Mouse wrote:
>> > Is there a portable way of finding out the limits for the maximum
>> > number of files and directories that can be created under a give
>> > directory?
>>
>> I doubt it.  Traditional Unix has no such limits, and at least some of
>> the more popular filesystems NetBSD supports don't.  There are (and
>> have been) per-mount-point limits, set at filesystem create time, but
>> that's not very closely related.  (If you do want them, look at
>> statfs(2) and/or fstatfs(2) for an API, or df -i for command-line.)
>
> Maybe I should have rephrased my question, i.e. not "filesystem limits", but
> "per directory limits".
>
> I can't create more than 32766 subdirectories in a given directory. If I run a
> test program, which creates subdirectories (1, 2, 3...N) in a loop, after
> 32766 it exits with:
>
> p3smp$ ./a.out
> mkdir() error: : Too many links
> i = 32766
>
> Where is this "Too many links" coming from? Is it a filesystem limit, or a
> dynamically adjustable sysctl limit? Is there a way to increase this limit, or
> maybe it will substantially decrease performance when doing directory lookups?

Per errno(2):

     31 EMLINK Too many links.  The number of hard links to a single file has
             exceeded the maximum.  (The system-wide maximum number of hard
             links is 32767.  Each file system may impose a lower limit for
             files contained within it).

A few greps in the source tree yield:

sys/syslimits.h:#define LINK_MAX                32767   /* max file
link count */

As to why this is restricted on a system basis, I don't know.  I'd
guess that the on-disk field for the link counter is 16 bits long and
the global constant is an artifact from the time when BSD only
supported a single file system?

-- 
Julio Merino


Home | Main Index | Thread Index | Old Index