bug-coreutils
[Top][All Lists]
Advanced

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

Re: coreutils-4.5.7: df broken on unmounted devices


From: Jim Meyering
Subject: Re: coreutils-4.5.7: df broken on unmounted devices
Date: Thu, 20 Feb 2003 11:27:25 +0100

Hi Bruno,

Thank you for reporting that!
Although I wouldn't go so far as to say that df is broken in that case :-),
I agree that it is misleading now that it displays the `Mounted on'
directory for such files.

So I've changed it as you suggest, so that now the `Filesystem' part
is always the file name of the special device corresponding to the
mount point, rather than the specified block- or character-special
file given on the command line.

        Now, df always displays the device file name corresponding to the
        listed mount point under `Filesystem'.  Before, for an unmounted
        block- or character-special file argument, it would display the
        command-line argument instead.
        * src/df.c (show_disk): Return a value indicating whether
        there was a match.  Don't try to find a mount point here.
        (show_entry): If show_disk doesn't find a match, call show_point.


Index: df.c
===================================================================
RCS file: /fetish/cu/src/df.c,v
retrieving revision 1.140
diff -u -p -u -p -r1.140 df.c
--- df.c        19 Feb 2003 16:05:07 -0000      1.140
+++ df.c        20 Feb 2003 09:24:57 -0000
@@ -506,35 +506,23 @@ done:
   return mp;
 }
 
-/* Identify the directory, if any, that device
-   DISK is mounted on, and show its disk usage.
+/* If DISK corresponds to a mount point, show its usage
+   and return nonzero.  Otherwise, return zero.
    STATP must be the result of `stat (DISK, STATP)'.  */
-
-static void
+static int
 show_disk (const char *disk, const struct stat *statp)
 {
   struct mount_entry *me;
-  char *mount_point;
 
   for (me = mount_list; me; me = me->me_next)
     if (STREQ (disk, me->me_devname))
       {
        show_dev (me->me_devname, me->me_mountdir, me->me_type,
                  me->me_dummy, me->me_remote);
-       return;
+       return 1;
       }
 
-  mount_point = find_mount_point (disk, statp);
-  if (!mount_point)
-    {
-      error (0, errno, "%s", quote (disk));
-      exit_status = EXIT_FAILURE;
-    }
-
-  /* No filesystem is mounted on DISK. */
-  show_dev (disk, mount_point, NULL, 0, 0);
-  if (mount_point)
-    free (mount_point);
+  return 0;
 }
 
 /* Figure out which device file or directory POINT is mounted on
@@ -670,10 +658,11 @@ show_point (const char *point, const str
 static void
 show_entry (const char *path, const struct stat *statp)
 {
-  if (S_ISBLK (statp->st_mode) || S_ISCHR (statp->st_mode))
-    show_disk (path, statp);
-  else
-    show_point (path, statp);
+  if ((S_ISBLK (statp->st_mode) || S_ISCHR (statp->st_mode))
+      && show_disk (path, statp))
+    return;
+
+  show_point (path, statp);
 }
 
 /* Show all mounted filesystems, except perhaps those that are of

Bruno Haible <address@hidden> wrote:
> This change:
>   * df now displays a mount point (usually `/') for non-mounted
>     character-special and block files
> is counter-intuitive, because it produces
>
> $ df /dev/hda
> Filesystem           1K-blocks      Used Available Use% Mounted on
> /dev/hda               2208864   2127604     81260  97% /
> $ df /
> Filesystem           1K-blocks      Used Available Use% Mounted on
> /dev/hda3              2208864   2127604     81260  97% /
>
> leaving the user puzzled about which device / corresponds to. It also
> violates the spirit of POSIX:2001, which says:
...




reply via email to

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