DragonFly-2.3.0.637.g59b61 master bin/cp cp.c bin/ls ls.c include fts.h lib/libc/gen fts.3 fts.c usr.bin/find find.c usr.sbin/mtree create.c
Peter Avalos
pavalos at crater.dragonflybsd.org
Tue Apr 7 00:13:48 PDT 2009
commit 59b616d3950abca6b6dbb402817f7beb7bb084a5
Author: Peter Avalos <pavalos at theshell.com>
Date: Fri Feb 27 03:26:46 2009 -0500
Sync fts(3) with FreeBSD.
Here's some of the relevant commit logs from FreeBSD:
FTSENT now avoids the use of the struct hack, thereby allowing future
extensions to the structure (e.g., for extended attributes) without
rebreaking the ABI. FTSENT now contains a pointer to the parent stream,
which fts_compar() can then take advantage of, avoiding the undefined
behavior previously warned about. As a consequence of this change, the
prototype of the comparison function passed to fts_open() has changed
to reflect the required amount of constness for its use. All callers
in the tree are updated to use the correct prototype.
Comparison functions can now make use of the new parent pointer to
access the new stream-specific private data pointer, which is intended
to assist creation of reentrant library routines which use fts(3)
internally.
The FTS_NOSTAT option is an optimisation that reduces the number
of stat(2) calls by keeping an eye of the number of links a directory
has. It assumes that each subdirectory will have a hard link to its
parent, to represent the ".." node, and stops calling stat(2) when
all links are accounted for in a given directory.
This assumption is really only valid for UNIX-like filesystems: A
concrete example is NTFS. The NTFS "i-node" does contain a link
count, but most/all directories have a link count between 0 and 2
inclusive. The end result is that find on an NTFS volume won't
actually traverse the entire hierarchy of the directories passed
to it. (Those with a link count of two are not traversed at all)
The fix checks the "UFSness" of the filesystem before enabling the
optimisation.
In fts_build(), if we try to chdir and fail (e.g. due to lack of search
permission), try to continue in FTS_DONTCHDIR mode. Of course this
won't work for long paths, but we can't descend more than one pathname
component beyond the directory anyway if we lack search permission.
Our fts(3) API, as inherited from 4.4BSD, suffers from integer
fields in FTS and FTSENT structs being too narrow. In addition,
the narrow types creep from there into fts.c. As a result, fts(3)
consumers, e.g., find(1) or rm(1), can't handle file trees an ordinary
user can create, which can have security implications.
Fix a file descriptor leak.
Summary of changes:
bin/cp/cp.c | 4 +-
bin/ls/ls.c | 4 +-
include/fts.h | 46 +++++----
lib/libc/gen/fts.3 | 88 +++++++++++++-----
lib/libc/gen/fts.c | 241 ++++++++++++++++++++++++++++++++---------------
usr.bin/find/find.c | 4 +-
usr.sbin/mtree/create.c | 4 +-
7 files changed, 265 insertions(+), 126 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/59b616d3950abca6b6dbb402817f7beb7bb084a5
--
DragonFly BSD source repository
More information about the Commits
mailing list