]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
df: fix handling of symlinks in mount list
authorPádraig Brady <P@draigBrady.com>
Mon, 12 May 2014 12:29:01 +0000 (13:29 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 13 May 2014 22:23:30 +0000 (23:23 +0100)
The symlink handling in commit v8.21-172-g33660b4 was incomplete
in the case where there were symlinks in the mount list itself.
For example, in the case where /dev/mapper/fedora-home was in the
mount list and that in turn was a symlink to /dev/dm-2, we have:

  before> df --out=source /dev/mapper/fedora-home
          devtmpfs

  after > df --out=source /dev/mapper/fedora-home
          /dev/mapper/fedora-home

* src/df.c (get_disk): Compare canonicalized device names from
the mount list.  Note we still display the non canonicalized name,
even if longer, as we assume that is the most representative.
* tests/df/df-symlink.sh: This could theoretically fail on some systems
depending on the content of the mount list, but adjust to fail on any
system where symlinks are present in the mount list for the current dir.

src/df.c
tests/df/df-symlink.sh

index 2b5a54e4a1beaf3f5ec4adadc7177cfd99858c85..24897a33f153a83a19d2fc3697d6d1d010e84e40 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -1056,13 +1056,19 @@ get_disk (char const *disk)
   char const *file = disk;
 
   char *resolved = canonicalize_file_name (disk);
-  if (resolved && resolved[0] == '/')
+  if (resolved && IS_ABSOLUTE_FILE_NAME (resolved))
     disk = resolved;
 
   size_t best_match_len = SIZE_MAX;
   for (me = mount_list; me; me = me->me_next)
     {
-      if (STREQ (disk, me->me_devname))
+      /* TODO: Should cache canon_dev in the mount_entry struct.  */
+      char *devname = me->me_devname;
+      char *canon_dev = canonicalize_file_name (me->me_devname);
+      if (canon_dev && IS_ABSOLUTE_FILE_NAME (canon_dev))
+        devname = canon_dev;
+
+      if (STREQ (disk, devname))
         {
           size_t len = strlen (me->me_mountdir);
           if (len < best_match_len)
@@ -1074,6 +1080,8 @@ get_disk (char const *disk)
                 best_match_len = len;
             }
         }
+
+      free (canon_dev);
     }
 
   free (resolved);
index aaed8108b3b4944fabc7eb47235f681eb258c55e..6d96bd2aaa1720e32bf81c5f566de55e4cd67b19 100755 (executable)
@@ -28,4 +28,11 @@ df --out=source,target "$disk" > exp || skip_ "cannot get info for $disk"
 df --out=source,target symlink > out || fail=1
 compare exp out || fail=1
 
+# Ensure we output the same values for device nodes and '.'
+# This was not the case in coreutil-8.22 on systems
+# where the device in the mount list was a symlink itself.
+# I.E. '.' => /dev/mapper/fedora-home -> /dev/dm-2
+df --out=source,target '.' > out || fail=1
+compare exp out || fail=1
+
 Exit $fail