Subject: df: wrong output when a FS masks another one

From: Stephane Chazelas <[email-masked]>
Date: Wed, 25 Oct 2017 15:57:15 +0100

Test case:

/tmp$ mkdir -p 1/2
/tmp$ sudo mount -o size=1M -t tmpfs x 1/2
/tmp$ sudo mount -o size=2M -t tmpfs y 1
/tmp$ mkdir 1/2
/tmp$ df -h 1/2
Filesystem      Size  Used Avail Use% Mounted on
x               2.0M     0  2.0M   0% /tmp/1/2

The Size is correct as that's obtained from statfs() on the
file. But when it comes to finding the corresponding mount
source and mountpoint, it fails.

/tmp$ grep /tmp/ /proc/mounts
x /tmp/1/2 tmpfs rw,relatime,size=1024k 0 0
y /tmp/1 tmpfs rw,relatime,size=2048k 0 0

df should walk /proc/self/mounts or /etc/mtab from the bottom up
until it finds the first mount point that is a parent of the
realpath of the file.

/tmp$ df --version
df (GNU coreutils) 8.28

(on Debian testing amd64)

Related: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=15955

That's just been discussed on the austin group mailing list:
https://www.mail-archive.com/[email-masked]/msg01715.html
https://www.mail-archive.com/[email-masked]/msg01720.html

Not critical as that could be considered as a pathological test
case.

-- 
Stephane