LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Max hard link per file on ext4 (https://www.linuxquestions.org/questions/linux-kernel-70/max-hard-link-per-file-on-ext4-4175454538/)

LeHibou2 03-18-2013 11:10 AM

Max hard link per file on ext4
 
Hi,

I would like to know if there is a limit for a file to be hard linked on a ext4 system.

Example : /root/test.txt. How many times could I hardlink it in different folder across the whole system before it starts to complain ?

I read some figures saying approx 65000 but it was on the same folder.

My case is different since the folders are different ones.

Any thoughts ?

Thanks,

LeHibou2

pan64 03-19-2013 04:02 AM

I do not think there is a limit on this. probably the struct inode can hold only 32bit int. Also may depend on the os version.
http://lxr.free-electrons.com/source/include/linux/fs.h line 550

rknichols 03-19-2013 12:48 PM

The kernel's compiled-in EXT4_LINK_MAX is 65000 (file ext4.h in the kernel source). It's the same for an ordinary file or a directory.

jpollard 03-19-2013 01:01 PM

https://ext4.wiki.kernel.org/index.p...ut#Inode_Table

The indicated limit on hard link count is 16 bits - 65534 (2^16 -1, as 0 indicates an unused inode)

rknichols 03-19-2013 03:05 PM

Quote:

Originally Posted by jpollard (Post 4914631)
[url]
The indicated limit on hard link count is 16 bits - 65534 (2^16 -1, as 0 indicates an unused inode)

That's what a 16-bit variable could support, but again, the kernel has a compiled-in limit of 65000.
Code:

/var/tmp $ cat ltest.sh
#!/bin/bash
mkdir ltest
touch ltest/stuff
set -e
trap 'echo "n=$n"; ls -l ltest/stuff' 0
for ((n=0; n<100000; ++n)); do
    N=$(printf %06d $n)
    if [[ $((n%1000)) == 0 ]]; then
        M=$(printf %02d $((n/1000)))
        [[ $((n%10000)) == 0 ]] && echo $M
        mkdir ltest/$M
    fi
    ln ltest/stuff ltest/$M/$N
done
/var/tmp $ bash ltest.sh
00
10
20
30
40
50
60
ln: creating hard link to `ltest/stuff': Too many links
n=64999
-rw-rw-r--. 65000 rnichols rnichols 0 Mar 19 14:31 ltest/stuff


jpollard 03-19-2013 04:11 PM

Does appear to be an ext4 internal limit. Not sure why they imposed that, the comments don't say.


All times are GMT -5. The time now is 07:06 PM.