shirou / gopsutil

psutil for golang
Other
10.6k stars 1.59k forks source link

Different file system types from Partitions() and Usage() #1046

Open sebstyle opened 3 years ago

sebstyle commented 3 years ago

Describe the bug On my Linux machine Partitions() reports ext4 correctly but Usage() reports ext2/ext3 incorrectly To Reproduce

// Loop devices (snap) filtered out

disk.Partitions(false): [{"device":"/dev/nvme0n1p2","mountpoint":"/","fstype":"ext4","opts":["rw","relatime"]} {"device":"/dev/nvme0n1p1","mountpoint":"/boot/efi","fstype":"vfat","opts":["rw","relatime"]} {"device":"/dev/nvme0n1p3","mountpoint":"/mnt/storage","fstype":"ext4","opts":["rw","relatime"]}]

// Paths obtained from disk.Partitions()

disk.Usage(/): {"path":"/","fstype":"ext2/ext3","total":97891741696,"free":32866172928,"used":60008792064,"usedPercent":64.6124518799754,"inodesTotal":6111232,"inodesUsed":364489,"inodesFree":5746743,"inodesUsedPercent":5.964247470886394}
disk.Usage(/boot/efi): {"path":"/boot/efi","fstype":"msdos","total":535805952,"free":527626240,"used":8179712,"usedPercent":1.5266183530562945,"inodesTotal":0,"inodesUsed":0,"inodesFree":0,"inodesUsedPercent":0}
disk.Usage(/mnt/storage): {"path":"/mnt/storage","fstype":"ext2/ext3","total":368039882752,"free":262375129088,"used":86898024448,"usedPercent":24.87967470968058,"inodesTotal":22888448,"inodesUsed":53410,"inodesFree":22835038,"inodesUsedPercent":0.23334915499731568}

Expected behavior I would expect them to be the same

Environment (please complete the following information):

Ubuntu 20.04.2 LTS (Focal Fossa)
5.8.0-44-generic #50~20.04.1-Ubuntu SMP
go1.13.8 linux/amd64
github.com/shirou/gopsutil/v3/disk
bt90 commented 3 years ago

This looks like a known limitation of statfs: https://unix.stackexchange.com/a/274030