aboutsummaryrefslogtreecommitdiff
path: root/bin/cp
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2015-05-05 13:23:03 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2015-05-05 13:23:03 +0000
commitc633f8dc046f6a9589887ef057374d034e7dac72 (patch)
tree42f105efb46ce7eea72410d6512b5d3c281bb519 /bin/cp
parentba993026d41ac50ec4cf60c70fa7482098b4d0aa (diff)
downloadsrc-c633f8dc046f6a9589887ef057374d034e7dac72.tar.gz
src-c633f8dc046f6a9589887ef057374d034e7dac72.zip
cp: Remove fts sorting.
In an attempt to improve performance, cp reordered directories first (although the comment says directories last). This is not effective with new UFS layout policies. The sorting reorders multiple arguments passed to cp, which may be undesirable. Additionally, the comparison function does not induce a total order. Per POSIX, this causes undefined behaviour in qsort(). NetBSD removed the sorting in 2009. On filesystems that return directory entries in hash/btree order, sorting by d_fileno before statting improves performance on large directories. However, this can only be implemented in fts(3). PR: 53475 Reviewed by: bde (in 2004) MFC after: 1 week
Notes
Notes: svn path=/head/; revision=282482
Diffstat (limited to 'bin/cp')
-rw-r--r--bin/cp/cp.c29
1 files changed, 1 insertions, 28 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index b83eeadc86ae..2ad5f4a43414 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -90,7 +90,6 @@ volatile sig_atomic_t info;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
static int copy(char *[], enum op, int);
-static int mastercmp(const FTSENT * const *, const FTSENT * const *);
static void siginfo(int __unused);
int
@@ -274,7 +273,7 @@ copy(char *argv[], enum op type, int fts_options)
mask = ~umask(0777);
umask(~mask);
- if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
+ if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL)
err(1, "fts_open");
for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) {
switch (curr->fts_info) {
@@ -488,32 +487,6 @@ copy(char *argv[], enum op type, int fts_options)
return (rval);
}
-/*
- * mastercmp --
- * The comparison function for the copy order. The order is to copy
- * non-directory files before directory files. The reason for this
- * is because files tend to be in the same cylinder group as their
- * parent directory, whereas directories tend not to be. Copying the
- * files first reduces seeking.
- */
-static int
-mastercmp(const FTSENT * const *a, const FTSENT * const *b)
-{
- int a_info, b_info;
-
- a_info = (*a)->fts_info;
- if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR)
- return (0);
- b_info = (*b)->fts_info;
- if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR)
- return (0);
- if (a_info == FTS_D)
- return (-1);
- if (b_info == FTS_D)
- return (1);
- return (0);
-}
-
static void
siginfo(int sig __unused)
{