3

I would like to get the number of maximum possible symlink level in the system. I found that it is hardcoded in the kernel to be 40. But I would like to get this number dynamically, in case someone changes this in the source code and recompiles the kernel. Is this even possible? And if not, how bad idea it is to assume this number to be always 40?

Thanks.

karlosss
  • 507

1 Answers1

1
touch file
test_max=45
for ((j=2,i=3;i<test_max;i++,j++)) ; do ln -s $j $i; done
for ((i=1;i<test_max;i++)) ; do if ! [ -f "$i" ]; then echo "$i"; break; fi ; done
41
Hauke Laging
  • 90,279
  • Is this really the only option? – karlosss Nov 04 '17 at 17:46
  • 1
    @karlosss That is not my claim. I wasn't even aware of the problem until I read your question. That was my spontaneous idea how to get that information. But it may be available somewhere explicitly (I didn't find anything in /proc/sys/kernel/, though). – Hauke Laging Nov 04 '17 at 18:32
  • 1
    The closest you can get is echo -n "#include <sys/param.h>\nMAXSYMLINKS" | gcc -E -, but that gives the C library’s version, not the kernel’s (20 v. 40). There’s nothing in getconf. Some Unix systems had this as a kernel tunable (fs_symlinks IIRC on HP-UX). – Stephen Kitt Nov 04 '17 at 18:53
  • I am still hoping (yeah, the probability is very low) that we are all missing something and somebody will come with a shell variable or a file containing this value. I would like to avoid the gcc solution as well. – karlosss Nov 04 '17 at 19:03
  • On my OpenBSD system, I can do getconf SYMLOOP_MAX to get back "32". – Kusalananda Nov 04 '17 at 19:47
  • On ArchLinux, I get undefined from this, whatever it means. – karlosss Nov 04 '17 at 20:10
  • Yes, SYMLOOP_MAX is undefined on Linux (sysconf knows about the name but returns -1). The documentation says this means that “there is no definite limit”. (Funnily enough, when I wrote ”There’s nothing in getconf” earlier I was staring at the “undefined” output...) – Stephen Kitt Nov 04 '17 at 22:08