bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Take the last matching entry in /etc/mtab, not the first.


From: James Youngman
Subject: [PATCH] Take the last matching entry in /etc/mtab, not the first.
Date: Wed, 1 Jun 2011 11:14:26 +0100

* find/fstype.c (file_system_type_uncached): Instead of taking the
first match, take the last match.  This deals better with mtab
implementations in which there can be duplicate entries, for
example Linux-based systems in which /etc/mtab is a symlink to
/proc/mounts) can have duplicate entries in the file system list.
This happens most frequently for /.
* NEWS: Mention this change.
---
 ChangeLog     |   11 +++++++++++
 NEWS          |    7 +++++++
 find/fstype.c |   15 ++++++++++++---
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 24b3472..934ba90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-06-01  James Youngman  <address@hidden>
+
+       Take the last matching entry in /etc/mtab, not the first.
+       * find/fstype.c (file_system_type_uncached): Instead of taking the
+       first match, take the last match.  This deals better with mtab
+       implementations in which there can be duplicate entries, for
+       example Linux-based systems in which /etc/mtab is a symlink to
+       /proc/mounts) can have duplicate entries in the file system list.
+       This happens most frequently for /.
+       * NEWS: Mention this change.
+
 2011-05-31  James Youngman  <address@hidden>
 
        import-gnulib.sh now stops if it sees the old directory layout.
diff --git a/NEWS b/NEWS
index ee0792f..9912045 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,13 @@ are re-used, but no executing child process will have the 
same value
 as another executing child process.  This wishlist item was Savannah
 bug #29512.
 
+** Functional Changes to find
+
+When expanding "-printf '%F'", find reads /etc/mtab.  We now take the
+last match found in this file, rather than the first, to better deal
+with implementations which have duplicate entries (for example
+/proc/mounts on systems running the Linux kernel).
+
 * Major changes in release 4.5.10, 2011-05-11
 
 ** Documentation Changes
diff --git a/find/fstype.c b/find/fstype.c
index 3a3985f..8787773 100644
--- a/find/fstype.c
+++ b/find/fstype.c
@@ -215,7 +215,7 @@ must_read_fs_list (bool need_fs_type)
 static char *
 file_system_type_uncached (const struct stat *statp, const char *path)
 {
-  struct mount_entry *entries, *entry;
+  struct mount_entry *entries, *entry, *best;
   char *type;
 
   (void) path;
@@ -228,6 +228,7 @@ file_system_type_uncached (const struct stat *statp, const 
char *path)
     }
 #endif
 
+  best = NULL;
   entries = must_read_fs_list (true);
   for (type=NULL, entry=entries; entry; entry=entry->me_next)
     {
@@ -238,10 +239,18 @@ file_system_type_uncached (const struct stat *statp, 
const char *path)
       set_fstype_devno (entry);
       if (entry->me_dev == statp->st_dev)
        {
-         type = xstrdup (entry->me_type);
-         break;
+         best = entry;
+         /* Don't exit the loop, because some systems (for example Linux-based
+            systems in which /etc/mtab is a symlink to /proc/mounts) can have
+            duplicate entries in the filesystem list.  This happens most
+            frequently for /.
+         */
        }
     }
+  if (best)
+    {
+      type = xstrdup (best->me_type);
+    }
   free_file_system_list (entries);
 
   /* Don't cache unknown values. */
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]