ftw/nftw -- filesystem tree walk


 
Thread Tools Search this Thread
Top Forums Programming ftw/nftw -- filesystem tree walk
# 1  
Old 03-18-2008
ftw/nftw -- filesystem tree walk

Hi,

I recently experimented with ftw() and nftw(). These are function for calling some function for every
file in a subtree.
I need to get full information about type of file.
Almost everything is working according to documentation
but I noticed following problem:

With a value FTW_PHYS as 4th arg. for nftw() the callback should obtain FTW_SL for proper symbolic links and FTW_SLN for dangling ones. I always obtain FTW_SL - this is bug in my opinion.

So I need to supply 0 as 4th arg. Then callbacks [correctly] obtain FTW_F for proper symbolic links and FTW_SLN for dangling ones. Unfortunately 'struct stat' callback obtains also returns same 'st_mode' value for regular files and symbolic links (due to stat() instead of lstat() in implementation probably) and I need to call lstat() additionally. This workaround works.

Have anybody obtained FTW_SLN in FTW_PHYS mode?
I am using glibc 2.3.5 and have not found any information about bugs.

thanks,
# 2  
Old 03-18-2008
What hardware platform and OS are you talking about? Otherwise your program is reporting the correct thing. If the FTW_PHYS flag is given as the 4th argument...FTW_SL files will be reported but not FTW_SLN types unless the 4th arg is not FTW_PHYS.
# 3  
Old 03-18-2008
I am using Slackware Linux 10.2 / glibc 2.3.5 (PC machine).

From the 'info' documentation:

>`FTW_PHYS'
>While traversing the directory symbolic links are not
>followed. Instead symbolic links are reported using the
>`FTW_SL' value for the type parameter to the callback
>function. If the file referenced by a symbolic link does not
>exist `FTW_SLN' is returned instead.

Therefore I understand with FTW_PHYS I will have FTW_SL or FTW_SLN given correctly, and FTW_F cannot happen for links.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. HP-UX

SNMP Walk need to enable

We are using a third party to monitor unix servers performance since last 60 days, since last 3 days we are not able to get the performance alarms on our tool. When we check the same with the tool team, they said "SNMP walk is not happening for all the servers." Performance we mean... (9 Replies)
Discussion started by: marunmeera
9 Replies

2. UNIX for Advanced & Expert Users

"Walk" apache installs and do a tar on them...

Hello unix.com Community: I need help with writing a "common" script that can get the httpd installs by name and install directory|ies and tar.gz them up by name and point that tar operation to the matching install directory. I have 2 Distros that I am concerned with for this task: CentOS and... (3 Replies)
Discussion started by: Habitual
3 Replies

3. AIX

Mount Filesystem in AIX Unable to read /etc/filesystem

Dear all, We are facing prolem when we are going to mount AIX filesystem, the system returned the following error 0506-307The AFopen call failed : A file or directory in the path name does not exist. But when we ls filesystems in the /etc/ directory it show -rw-r--r-- 0 root ... (2 Replies)
Discussion started by: m_raheelahmed
2 Replies

4. UNIX for Dummies Questions & Answers

hwo to find shared filesystem and local filesystem in AIX

Hi, I wanted to find out that in my database server which filesystems are shared storage and which filesystems are local. Like when I use df -k, it shows "filesystem" and "mounted on" but I want to know which one is shared and which one is local. Please tell me the commands which I can run... (2 Replies)
Discussion started by: kamranjalal
2 Replies

5. Shell Programming and Scripting

How to walk through a config file with /bin/sh

Hi there, i tried a lot of things actually to get my script running as expected. Situation: I have a config file with several parameters in the form FFF.thisIsaParam=Value FFF.included.AnotherPortofParam=Value Additionally there are some comments in it. Script should... (8 Replies)
Discussion started by: smhaller
8 Replies

6. Programming

find depth using ftw

Hello, I am looking for specific files in my tree directory using ftw(3). How do I know how deep I am in the file structure.. in other words, say I am looking for config.txt files, and my structure looks like this.. /some/directory/user1/config.txt /some/directory/user2/config.txt ....... (2 Replies)
Discussion started by: germallon
2 Replies

7. Programming

using ftw()

hello im trying to find more information about the function: ftw() however it seems every resource has the same thing how to declare it and what it is supposed to do does anyone know of a resource that actually has ftw used within a program, so i can get an idea of how to actually use it?... (0 Replies)
Discussion started by: runawayNinja
0 Replies

8. Programming

ftw function

int ftw(const char *path, int(*func)(), int depth); what does the third parameter(depth) mean? the book said that the larger the value of depth, the fewer directories have to be reopened, therefore increasing the speed of the call. how so? thanks (1 Reply)
Discussion started by: bb00y
1 Replies
Login or Register to Ask a Question