I am reading The Linux Programming Interface, this book says:
SUSv3 requires that an implementation allow at least
_POSIX_SYMLOOP_MAXdereferences of each symbolic link component of a pathname. The specified value for_POSIX_SYMLOOP_MAXis8. However, before kernel 2.6.18, Linux imposed a limit of 5 dereferences when following a chain of symbolic links. Starting with kernel 2.6.18, Linux implements the SUSv3-specified minimum of 8 dereferences. Linux also imposes a total of 40 dereferences for an entire pathname.
I didn't quite understand the last two sentences, what is the difference between these 8 and 40 limitations? I tested myself, creating a bunch of symlinks in my machine to try to reach the limitation:
$ l Permissions Links Size User Group Date Modified Name .rw-r--r--@ 1 12 steve steve 20 Oct 16:35 a lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:34 b -> a lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:35 c -> b lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:35 d -> c lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:35 e -> d lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 f -> e lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 g -> f lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 h -> g lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 i -> h lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:36 j -> i lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 k -> i lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 l -> k lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 m -> l lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:37 n -> m lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:38 o -> n lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:38 p -> o lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:40 q -> p lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 r -> q lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 s -> r lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 t -> s lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 u -> t lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 v -> u lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 w -> v lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 x -> w lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 y -> x lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:41 z -> y lrwxrwxrwx@ 1 1 steve steve 20 Oct 16:42 z1 -> z lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:42 z2 -> z1 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:42 z3 -> z2 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:42 z4 -> z3 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z5 -> z4 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z6 -> z5 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z7 -> z6 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z8 -> z7 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z9 -> z8 lrwxrwxrwx@ 1 2 steve steve 20 Oct 16:43 z10 -> z9 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:43 z11 -> z10 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:43 z12 -> z11 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:43 z13 -> z12 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:44 z14 -> z13 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:44 z15 -> z14 lrwxrwxrwx@ 1 3 steve steve 20 Oct 16:44 z16 -> z15 lrwxrwxrwx 1 3 steve steve 20 Oct 16:45 z17 -> z16 $ cat a You did it. $ cat z17 cat: z17: Too many levels of symbolic links $ cat z16 You did it. Seems that I have triggered that 40 limitation, then what is that 8 one?
8is the POSIX minimal limit that any implementations must follow, and40is the limit defined by Linux.40is technically NOT the upper limit of symlink resolving, it is the maximumpath resolutionwe can use for a single path.