LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 03-18-2013, 11:10 AM   #1
LeHibou2
LQ Newbie
 
Registered: Feb 2013
Posts: 20

Rep: Reputation: Disabled
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
 
Old 03-19-2013, 04:02 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,734

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
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
 
Old 03-19-2013, 12:48 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,434

Rep: Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599
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.
 
Old 03-19-2013, 01:01 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 2,195

Rep: Reputation: 567Reputation: 567Reputation: 567Reputation: 567Reputation: 567Reputation: 567
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)
 
Old 03-19-2013, 03:05 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,434

Rep: Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599Reputation: 599
Quote:
Originally Posted by jpollard View Post
[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
 
Old 03-19-2013, 04:11 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 2,195

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] "Lost space" for Ext3 and Ext4 file systems on hard drive Steve W Linux - Hardware 2 10-16-2012 01:20 PM
Creating a hard link using ln creates a copy of file jeffshen Linux - Newbie 7 03-12-2010 05:05 AM
[SOLVED] how to distinguish between a original file and a hard link bzlaskar Linux - Newbie 2 12-11-2007 08:58 AM
how do I know if a file has a hard link to it? granny Linux - Newbie 11 03-02-2004 11:56 PM


All times are GMT -5. The time now is 09:35 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration