shirou / gopsutil

psutil for golang
Other
10.36k stars 1.57k forks source link

Calling disk.Partitions(false) produces different list on Linux to "df" #1617

Open tomqwpl opened 4 months ago

tomqwpl commented 4 months ago

This is actually prompted by this use within Hashicorp Nomad.

This is for the Linux platform.

Calling "Partitions" reads /proc/1/mountinfo and then correlates the filesystem type to what is returned from /proc/filesystem. Things that are marked as "nodev" in that file are not considered.

This is not what df is doing though.

My test environment here is a docker image. df shows:

 df
Filesystem      1K-blocks       Used Available Use% Mounted on
overlay        1055762868  393449744 608609652  40% /
tmpfs               65536          0     65536   0% /dev
tmpfs            16354108          0  16354108   0% /sys/fs/cgroup
shm                 65536         32     65504   1% /dev/shm
C:\            1999902716 1389904944 609997772  70% /home
/dev/sdd       1055762868  393449744 608609652  40% /etc/hosts
tmpfs            16354108       8320  16345788   1% /run

This is what I would class as the expected behaviour

Output from calling "partitions(false)" (printing filesystem and mountpoint):

ext4 /etc/resolv.conf
ext4 /etc/hostname
ext4 /etc/hosts

This is what I would class as the current behaviour

The contents of /proc/filesystems shows:

nodev   overlay
nodev   tmpfs

So whatever filtering df does by default is different to what gopsutil does.

This isn't just in docker environment, I've also got test environments in WSL and standard Linux VM and I equally get different results.

shirou commented 4 months ago

I'm sorry, but could you please describe the Current behavior and Expected behavior according to the Issue Template?