summaryrefslogtreecommitdiff
path: root/src/df.c
diff options
context:
space:
mode:
authorDave Chiluk <chiluk@canonical.com>2015-09-21 15:04:11 -0500
committerPádraig Brady <P@draigBrady.com>2015-09-23 01:02:44 +0100
commit3babaf83875ceac896c8dd3a64248e955dfecef9 (patch)
tree79d404622b9cd89b2825c14195b06b88fd3982c5 /src/df.c
parent982c79fa14853040d6bd10ad6f001791408e2441 (diff)
downloadcoreutils-3babaf83875ceac896c8dd3a64248e955dfecef9.tar.xz
df: prioritize mounts nearer the device root
In the presence of bind mounts of a device, the 4th "mount root" field from /proc/self/mountinfo is now considered, so as to prefer mount points closer to the root of the device. Note on older systems with an /etc/mtab file, the source device was listed as the originating directory, and so this was not an issue. Details at http://pad.lv/1432871 * src/df.c (filter_mount_list): When deduplicating mount entries, only prefer sources nearer or at the root of the device, when the target is nearer the root of the device. * NEWS: Mention the change in behavior.
Diffstat (limited to 'src/df.c')
-rw-r--r--src/df.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/df.c b/src/df.c
index 2e541b952..17a2de437 100644
--- a/src/df.c
+++ b/src/df.c
@@ -641,6 +641,13 @@ filter_mount_list (bool devices_only)
if (devlist)
{
+ bool target_nearer_root = strlen (devlist->me->me_mountdir)
+ > strlen (me->me_mountdir);
+ /* With bind mounts, prefer items nearer the root of the source */
+ bool source_below_root = devlist->me->me_mntroot != NULL
+ && me->me_mntroot != NULL
+ && (strlen (devlist->me->me_mntroot)
+ < strlen (me->me_mntroot));
if (! print_grand_total && me->me_remote && devlist->me->me_remote
&& ! STREQ (devlist->me->me_devname, me->me_devname))
{
@@ -652,9 +659,8 @@ filter_mount_list (bool devices_only)
else if ((strchr (me->me_devname, '/')
/* let "real" devices with '/' in the name win. */
&& ! strchr (devlist->me->me_devname, '/'))
- /* let a shorter mountdir win. */
- || (strlen (devlist->me->me_mountdir)
- > strlen (me->me_mountdir))
+ /* let points towards the root of the device win. */
+ || (target_nearer_root && ! source_below_root)
/* let an entry overmounted on a new device win... */
|| (! STREQ (devlist->me->me_devname, me->me_devname)
/* ... but only when matching an existing mnt point,