Base WG Resolution Ref: bwg97-003
Topic: nftw


This is an approved Base Working Group Resolution for XSH Issue 4 Version 2 & Issue 5.

Last update: 09 October,1997


								97 #003

 _____________________________________________________________________________

	Topic:			nftw
	Relevant Sections:	nftw
	Spec:			XSH Issue 4 Version 2 & Issue 5

Resolution Request:
-------------------

The test for nftw fails as follows:


TEST PURPOSE #3
A call to int nftw(const char *path, int (*fn)(const
char *, const struct stat *, int, struct FTW *), int
depth, int flags) when flags does not contain FTW_PHYS
shall follow links instead of reporting them and shall
not report the same file twice.
PREP: Set up the path
TEST: nftw without FTW_PHYS follows symbolic links
INFO: Call to fn() at ../tmp/data/dirl
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1/dir_left.2
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1/dir_left.2/left.3
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1/dir_left.2/left.3/dir_left.1
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1/dir_left.2/left.3/dir_left.1/dir_left.2
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1/dir_left.2/left.3/dir_left.1/dir_left.2/left.3
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1/dir_left.2/left.3/dir_right.1
INFO: Call to fn() at ../tmp/data/dirl/dir_left.1/dir_left.2/left.3/dir_right.1/dir_right.2
INFO: Call to fn() at 
../tmp/data/dirl/dir_left.1/dir_left.2/left.3/dir_right.1/dir_right.2/right.3
INFO: Call to fn() at ../tmp/data/dirl/dir_right.1
INFO: Call to fn() at ../tmp/data/dirl/dir_right.1/dir_right.2
INFO: Call to fn() at ../tmp/data/dirl/dir_right.1/dir_right.2/right.3
ERROR: Target of right.3 was already reported so this file should not be
3 FAIL

On looking at this result we see that the test does test what the specification
says and we feel that there is a specification error here. The previous test
tests what is established historical practice and is what the SVID III defines
as the functionality in this area. It appears that when the SVID was included 
to create the XPG4.2 specifications a rewrite of some of the words has changed
the meaning in a detrimental way.

The FTW_PHYS wording from the SVID, on which the nftw() entry is
based says "Physical walk, does not follow symbolic links.  Otherwise,
nftw() will follow links but will not walk down any path that crosses
itself."  Somehow, the XSH4.2 wording became "...  If clear, nftw()
will follow links instead of reporting them, and will not report the
same file twice."

The existing practice is to keep information about *directories*.
If one is about to start walking through the directory entries for
a directory with the same device/inode pair for one we've got "on
the stack", we instead immediately close the directory and skip it.
That's all.  This requires, for a recursive nftw() implementation,
exactly one item on the stack/directory-call.

To perform to the letter of the XSH4.2 words, the implementation
must record the device/inode pair for *every file* reported during
the entire call and for each new entry, check to see if it has the
same pair!  This forces an additional O(n) in space and at least
O(n log n) time for "n" files reported.  It doesn't even help if
the description is taken to mean that only files reached for a
second or subsequent time through only *symbolic* links are to be
checked for, since we still need to keep the device/inode pairs
for all the regular files in case a symbolic link comes later.

We believe this is an incorrect technical editorial modification to the 
nftw() functionality which in XPG4.2 was to standardise on existing 
practice as identified by the SVID.


This is referred to the Base WG to query if the change from
historical behaviour was the intent.

Resolution Response
-------------------

A future revision will replace the FTW_PHYS clause of nftw()
with the following text. For existing conforming either behaviour is
allowed.
 
FTW_PHYS 	If set, nftw() performs a physical walk and does not follow
		symbolic links.  

If FTW_PHYS is clear and FTW_DEPTH is set, 
nftw() will follow links instead of reporting them, 
but will not report any directory that would be a descendant 
of itself.  If FTW_PHYS is clear and FTW_DEPTH is clear, nftw() will follow
links instead of reporting them, but will not report the contents
of any directory that would be a descendant of itself.
 

Rationale
-------------
This matches historical behaviour.

Circulated for review: Jun 25 1997
Proposed for final review: Sep 19 1997
Approved: Sep 30 1997