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,
8 More Discussions You Might Find Interesting
1. Programming
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
2. Programming
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
3. Programming
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
4. Shell Programming and Scripting
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
5. UNIX for Dummies Questions & Answers
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
6. AIX
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
7. UNIX for Advanced & Expert Users
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
8. HP-UX
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
<ftw.h>(P) POSIX Programmer's Manual <ftw.h>(P)
NAME
ftw.h - file tree traversal
SYNOPSIS
#include <ftw.h>
DESCRIPTION
The <ftw.h> header shall define the FTW structure that includes at least the following members:
int base
int level
The <ftw.h> header shall define macros for use as values of the third argument to the application-supplied function that is passed as the
second argument to ftw() and nftw():
FTW_F File.
FTW_D Directory.
FTW_DNR
Directory without read permission.
FTW_DP Directory with subdirectories visited.
FTW_NS Unknown type; stat() failed.
FTW_SL Symbolic link.
FTW_SLN
Symbolic link that names a nonexistent file.
The <ftw.h> header shall define macros for use as values of the fourth argument to nftw():
FTW_PHYS
Physical walk, does not follow symbolic links. Otherwise, nftw() follows links but does not walk down any path that crosses itself.
FTW_MOUNT
The walk does not cross a mount point.
FTW_DEPTH
All subdirectories are visited before the directory itself.
FTW_CHDIR
The walk changes to each directory before reading it.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
int ftw(const char *, int (*)(const char *, const struct stat *,
int), int);
int nftw(const char *, int (*)(const char *, const struct stat *,
int, struct FTW*), int, int);
The <ftw.h> header shall define the stat structure and the symbolic names for st_mode and the file type test macros as described in
<sys/stat.h> .
Inclusion of the <ftw.h> header may also make visible all symbols from <sys/stat.h>.
The following sections are informative.
APPLICATION USAGE
None.
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
<sys/stat.h> , the System Interfaces volume of IEEE Std 1003.1-2001, ftw(), nftw()
COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol-
ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE
and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained
online at http://www.opengroup.org/unix/online.html .
IEEE
/The Open Group 2003 <ftw.h>(P)