summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2014-01-25 01:14:29 +0000
committerPádraig Brady <P@draigBrady.com>2014-05-13 23:23:30 +0100
commit2dc5d044a88fd64e11e35886e78b54a4a9fc2b23 (patch)
treee1699a1ae50b966640a2af91510694a762a97c3f /src
parent6b3003a9da29c17324dd3ce395861b07fd7fa27d (diff)
downloadcoreutils-2dc5d044a88fd64e11e35886e78b54a4a9fc2b23.tar.xz
df: also deduplicate virtual file systems
* src/df.c (filter_mountlist): Remove the constraint that a '/' needs to be in the device name for a mount entry to be considered for deduplication. Virtual file systems also have storage associated with them (like tmpfs for example), and thus need to be deduplicated since they will be shown in the default df output and subject to --total processing also. * test/df/skip-duplicates.sh: Add a test to ensure we deduplicate all entries, even for virtual file systems. Also avoid possible length operations on many remote file systems in the initial check of df operation. Also avoid the assumption that "/root" is on the same file system as "/". * NEWS: Mention the change in behavior.
Diffstat (limited to 'src')
-rw-r--r--src/df.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/df.c b/src/df.c
index e7639434e..2b5a54e4a 100644
--- a/src/df.c
+++ b/src/df.c
@@ -630,26 +630,23 @@ filter_mount_list (void)
}
else
{
- /* If the device name is a real path name ... */
- if (strchr (me->me_devname, '/'))
+ /* If we've already seen this device... */
+ for (devlist = devlist_head; devlist; devlist = devlist->next)
+ if (devlist->dev_num == buf.st_dev)
+ break;
+
+ if (devlist)
{
- /* ... try to find its device number in the devlist. */
- for (devlist = devlist_head; devlist; devlist = devlist->next)
- if (devlist->dev_num == buf.st_dev)
- break;
+ discard_me = me;
- if (devlist)
+ /* ...let the shorter mountdir win. */
+ if ((strchr (me->me_devname, '/')
+ && ! strchr (devlist->me->me_devname, '/'))
+ || (strlen (devlist->me->me_mountdir)
+ > strlen (me->me_mountdir)))
{
- discard_me = me;
-
- /* Let the shorter mountdir win. */
- if (! strchr (devlist->me->me_devname, '/')
- || (strlen (devlist->me->me_mountdir)
- > strlen (me->me_mountdir)))
- {
- discard_me = devlist->me;
- devlist->me = me;
- }
+ discard_me = devlist->me;
+ devlist->me = me;
}
}
}