As every child in kindergarten knows, a file path in Linux cannot be longer than PATH_MAX
characters.
But experimenting on my system, the command
ln -s $(for i in {0..1024}; do printf dir/../; done)foobar foobar1
fails with the error message File name too long
.
I don't quite understand why. There is no long file name here, it is only the intended contents of the file foobar1
that are very long. Nobody is even yet trying to traverse the contents of the symbolic link to get to the target. Certainly I can have a file whose contents is much larger than PATH_MAX
.
On the other hand, a command such as
for i in {0..4096}; do ln -s $i $(expr $i + 1); done
succeeds. Only if I tried to traverse the chain, does the system complain.
But I am not interested in traversing anything. I am writing software that has to read the value of a symbolic link (without traversing) and I want to know if I need to account for very long values.
Where is it documented in Linux that this is not allowed? Or is it file-system implementation dependent and can change?
l
file-type in its inode, but otherwise its contents are the target of the link. – Decurrentopen
but notremove
) happen. – Decurrent