Since this bug was making my life miserable, I patched df to fix its
output. The attached patch hides "rootfs" type mount points, and
canonicalizes device paths when displaying them.

Result:

Filesystem      Size  Used Avail Use% Mounted on
udev            495M     0  495M   0% /dev
tmpfs           100M  696K  100M   1% /run
/dev/sda1        29G   27G  1.4G  96% /
tmpfs           200M  340K  200M   1% /run/shm

The rootfs part of the patch is about as good a fix as I think we're going
to get. There's nothing wrong with the device path canonicalization
(it will handle correctly all cases including remote devices, special devices, 
deleted or inaccessible device files, even relative devices), but
df is not the best place to put it; fixing klibc would be better.

-- 
see shy jo
diff -ur old/coreutils-8.13/lib/mountlist.c coreutils-8.13/lib/mountlist.c
--- old/coreutils-8.13/lib/mountlist.c	2011-04-24 13:21:45.000000000 -0400
+++ coreutils-8.13/lib/mountlist.c	2012-01-04 14:30:08.178037951 -0400
@@ -154,6 +154,7 @@
     (strcmp (Fs_type, "autofs") == 0            \
      || strcmp (Fs_type, "none") == 0           \
      || strcmp (Fs_type, "proc") == 0           \
+     || strcmp (Fs_type, "rootfs") == 0         \
      || strcmp (Fs_type, "subfs") == 0          \
      /* for NetBSD 3.0 */                       \
      || strcmp (Fs_type, "kernfs") == 0         \
diff -ur old/coreutils-8.13/src/df.c coreutils-8.13/src/df.c
--- old/coreutils-8.13/src/df.c	2011-07-28 06:38:27.000000000 -0400
+++ coreutils-8.13/src/df.c	2012-01-04 14:45:08.393554354 -0400
@@ -447,7 +447,7 @@
   uintmax_t used;
   bool negate_used;
   double pct = -1;
-  char* cell;
+  char* cell = NULL;
   size_t field;
 
   if (me_remote && show_local_fs)
@@ -486,8 +486,6 @@
 
   alloc_table_row ();
 
-  if (! disk)
-    disk = "-";			/* unknown */
   if (! fstype)
     fstype = "-";		/* unknown */
 
@@ -537,7 +535,16 @@
       switch (field)
         {
         case DEV_FIELD:
-          cell = xstrdup (disk);
+	  if (! disk) {
+	    cell = xstrdup ("-"); /* unknown */
+	  }
+	  else if (! me_remote && disk[0] == '/') {
+	    /* Avoid long disk paths like /dev/disk/by-uuid/UUID by
+	     * canonicalizing if possible. */
+            cell = canonicalize_file_name (disk);
+	  }
+	  if (! cell)
+            cell = xstrdup (disk);
           break;
 
         case TYPE_FIELD:

Attachment: signature.asc
Description: Digital signature

Reply via email to