2b3154
From 1328926a705fdb4728c1f255dd368de928736d39 Mon Sep 17 00:00:00 2001
2b3154
From: Kamil Dudka <kdudka@redhat.com>
2b3154
Date: Fri, 25 Sep 2015 16:09:39 +0200
2b3154
Subject: [PATCH 1/2] fts: introduce the FTS_NOLEAF flag
2b3154
2b3154
The flag is needed to implement the -noleaf option of find.
2b3154
* lib/fts.c (link_count_optimize_ok): Implement the FTS_NOLEAF flag.
2b3154
* lib/fts_.h (FTS_NOLEAF): New macro, shifted conflicting constants.
2b3154
---
2b3154
 gl/lib/fts.c  |  4 ++++
2b3154
 gl/lib/fts_.h | 12 +++++++++---
2b3154
 2 files changed, 13 insertions(+), 3 deletions(-)
2b3154
2b3154
diff --git a/gl/lib/fts.c b/gl/lib/fts.c
2b3154
index d2d404f..808466f 100644
2b3154
--- a/gl/lib/fts.c
2b3154
+++ b/gl/lib/fts.c
2b3154
@@ -736,6 +736,10 @@ filesystem_type (FTSENT const *p)
2b3154
   struct dev_type *ent;
2b3154
   struct statfs fs_buf;
2b3154
 
2b3154
+  if (ISSET(FTS_NOLEAF))
2b3154
+    /* leaf optimization explicitly disabled by the FTS_NOLEAF flag */
2b3154
+    return 0;
2b3154
+
2b3154
   /* If we're not in CWDFD mode, don't bother with this optimization,
2b3154
      since the caller is not serious about performance.  */
2b3154
   if (!ISSET (FTS_CWDFD))
2b3154
diff --git a/gl/lib/fts_.h b/gl/lib/fts_.h
2b3154
index 63d4b74..f1d519b 100644
2b3154
--- a/gl/lib/fts_.h
2b3154
+++ b/gl/lib/fts_.h
2b3154
@@ -155,10 +155,16 @@ typedef struct {
2b3154
      from input path names during fts_open initialization.  */
2b3154
 # define FTS_VERBATIM   0x1000
2b3154
 
2b3154
-# define FTS_OPTIONMASK 0x1fff          /* valid user option mask */
2b3154
+  /* Disable leaf optimization (which eliminates stat() calls during traversal,
2b3154
+     based on the count of nested directories stored in stat.st_nlink of each
2b3154
+     directory).  Note that the optimization is by default enabled only for
2b3154
+     selected file systems, and only if the FTS_CWDFD flag is set.  */
2b3154
+# define FTS_NOLEAF     0x2000
2b3154
 
2b3154
-# define FTS_NAMEONLY   0x2000          /* (private) child names only */
2b3154
-# define FTS_STOP       0x4000          /* (private) unrecoverable error */
2b3154
+# define FTS_OPTIONMASK 0x3fff          /* valid user option mask */
2b3154
+
2b3154
+# define FTS_NAMEONLY   0x4000          /* (private) child names only */
2b3154
+# define FTS_STOP       0x8000          /* (private) unrecoverable error */
2b3154
         int fts_options;                /* fts_open options, global flags */
2b3154
 
2b3154
         /* Map a directory's device number to a boolean.  The boolean is
2b3154
-- 
2b3154
2.5.0
2b3154
2b3154
2b3154
From c186934e6e37ddadf7511abb9b1045192757618e Mon Sep 17 00:00:00 2001
2b3154
From: Kamil Dudka <kdudka@redhat.com>
2b3154
Date: Fri, 25 Sep 2015 19:13:15 +0200
2b3154
Subject: [PATCH 2/2] ftsfind: propagate the -noleaf option to FTS
2b3154
2b3154
* find/ftsfind.c (find): Propagate the -noleaf option to FTS.
2b3154
---
2b3154
 find/ftsfind.c | 3 +++
2b3154
 1 file changed, 3 insertions(+)
2b3154
2b3154
diff --git a/find/ftsfind.c b/find/ftsfind.c
2b3154
index 5159470..e34b672 100644
2b3154
--- a/find/ftsfind.c
2b3154
+++ b/find/ftsfind.c
2b3154
@@ -559,6 +559,9 @@ find (char *arg)
2b3154
   if (options.stay_on_filesystem)
2b3154
     ftsoptions |= FTS_XDEV;
2b3154
 
2b3154
+  if (options.no_leaf_check)
2b3154
+    ftsoptions |= FTS_NOLEAF;
2b3154
+
2b3154
   p = fts_open (arglist, ftsoptions, NULL);
2b3154
   if (NULL == p)
2b3154
     {
2b3154
-- 
2b3154
2.5.0
2b3154