LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ftw : file tree walk recursion level problem (https://www.linuxquestions.org/questions/programming-9/ftw-file-tree-walk-recursion-level-problem-721129/)

shashank929 04-23-2009 06:28 AM

ftw : file tree walk recursion level problem
 
ftw function of ftw.h is a recursive implementation for recursively walking down a directory tree. I want to know how deep can the recursion level be.
I am making a program using ftw in which I may have to give the root directory also for traversing. So how can I know that at what level of subdirectories the function will fail?? TIA

Guttorm 04-23-2009 08:31 AM

Hi

I'm not 100% sure about this, but the stack is usually megabytes in size (8Mb size is default, but it can be set with "ulimit -s"). So unless it's set very low, or other parts of the program uses a lot of stack space, you can't reach that limit. MAX_PATH is usually 256 bytes, which means you can't go deeper than about 128 directories, and that doesn't take much stack space.

Edit: I was mistaken, directories can be a lot deeper than I thought. But the stack still has a lot of space and can hold directories thousands of levels deep..

Hko 04-23-2009 10:52 AM

Quote:

Originally Posted by Guttorm (Post 3518378)
[...] MAX_PATH is usually 256 bytes

256 sounds low...
So I tried it (on ubuntu 8.10 i386):
Code:

hko:/tmp$ cat path_max.c
#include <stdio.h>
#include <limits.h>

int main()
{
    printf("PATH_MAX = %d\n", PATH_MAX);
    return 0;
}
hko:/tmp$ gcc -Wall -o path_max path_max.c
hko:/tmp$ ./path_max
PATH_MAX = 4096

This is just as a side note. Even with this much bigger number for PATH_MAX, the point you want to make is still valid I think.

shashank929 04-24-2009 01:04 AM

thanks
 
thanks a lot guys.... that answered my question
I need to understand one more thing
PATH_MAX is the maximum path length allowed on the system....can anyone change it on the system and if he does then what will be the maximum limit of the directory level.
On my system also PATH_MAX is 4096

Hko 04-24-2009 01:23 AM

That would probably require modifying the C-code of fundamental parts of the operating system like libc and/or the kernel.

So, pretty unlikely that your program will be run on such a system. I suppose the find program also depends on this max directory tree recursion limit.

shashank929 04-24-2009 05:00 AM

okk...thanks...

Also, since PATH_MAX is 4096 on my system... so how much maximum level of the directories on my system can be


All times are GMT -5. The time now is 08:27 PM.