11

In a python script, I am creating a bunch of symbolic links chained together.

example: link1->link2->link3->.......->somefile.txt

I was wondering how you can change the max number of symlinks to be greater than 20?

grebwerd
  • 145
  • 1
  • 8
  • 5
    Why would you want to do this? MAXSYMLINKS is defined in system headers (e.g. /usr/include/x86_64-linux-gnu/sys/param.h on my system), and is not intended to be modified by users. – ire_and_curses Oct 28 '12 at 05:57
  • 1
    Having to call readlink() over 20 times to get to a real file is not going to be good for performance. – jordanm Oct 28 '12 at 13:55
  • 5
    I am taking an ethical hacking class at school, which is pretty cool.One of the HACKS is called TOCTTOU, where you want to impact the performance by creating an elaborate directory/symbolic link maze. – grebwerd Nov 01 '12 at 21:23

1 Answers1

17

On Linux (3.5 at least), it's hardcoded to 40 (see follow_link() in fs/namei.c), and note that it's the number of links followed when resolving all the components of a path, you can only change it by recompiling the kernel.

$ ln -s . 0
$ n=0; repeat 50 ln -s $((n++)) $n
$ ls -LdF 39
39/
$ ls -LdF 40
ls: cannot access 40: Too many levels of symbolic links
$ ls -LdF 20/18 10/10/10/6
10/10/10/6/  20/18/
$ ls -LdF 20/19 10/10/10/7
ls: cannot access 20/19: Too many levels of symbolic links
ls: cannot access 10/10/10/7: Too many levels of symbolic links