Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a limit of number of hardlinks for one file? Is it specified anywhere? What are safe limits for Linux? And what for other POSIX systems?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

Posix requires that the operating system understand the concept of hard links but not that hard links can actually be used in any particular circumstance. You can find out how many hard links are permitted at a particular location (this can vary by filesystem type) by calling pathconf(filename, _PC_LINK_MAX). The minimum limit (_POSIX_LINK_MAX) is 8, but this is rather meaningless as link() can report many other errors anyway (permission denied, disk full, …).

The stat structure stores the link count in a field of type nlink_t, so the type of this field gives an upper limit on your system. But there's a good chance you'll never be able to reach that far: it's common to have a 32-bit nlink_t but only 16 bits in many filesystems (a quick grep in the Linux source shows that ext[234], NTFS, UFS and XFS use 16-bit link counts in the kernel data structures).

share|improve this answer
    
As a supplement: BTRFS seems to use 8 bit link count. –  Maciej Piechotka Jan 3 '12 at 17:15
add comment

Looking at the ext3 inode structure disk format in the linux kernel sources (*include/linux/ext3_fs.h*) that lists the links count as being a 16 bit number

struct ext3_inode {
    ... snip ...
    __le16  i_links_count;  /* Links count */

}

I guess that means that an ext3 filesystem can have up to 65535 links.

I haven't checked the values for other filesystems.

share|improve this answer
add comment

This is file system dependent.

ext2/3/4 limit is 65k links

ext4 source line 643, struct ext4_inode -> __le16 i_links_count

share|improve this answer
1  
The actual limit is 65534. The last counter entry is used for a transient in the rename() system call. –  Joshua Jan 11 '11 at 0:03
1  
Even less (found in same ext4.h): /* Maximal count of links to a file */ #define EXT4_LINK_MAX 65000 –  PoltoS Apr 23 '12 at 22:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.