Handle BTRFS Subvolumes properly, fixes #1

This commit is contained in:
Martinez 2016-10-06 12:23:20 +02:00
parent 3358c807a0
commit 4b6a059f1d

View file

@ -546,10 +546,12 @@ class StatsPart(Part):
# mountpoints
names = []
first_mountpoint = True
btrfs_encountered_devices = set()
device_to_label = {os.path.join("/dev", os.path.basename(os.readlink(os.path.join("/dev/disk/by-label", x)))): x for x in os.listdir("/dev/disk/by-label")}
with open("/proc/self/mounts") as f:
for line in f:
_, dir, type, options, *rest = line.split()
device, dir, type, options, *rest = line.split()
# skip non-storage mounts
if type in MOUNT_IGNORE_FS:
@ -577,8 +579,14 @@ class StatsPart(Part):
else:
short_name = " /"
# handle btrfs separately
# handle btrfs subvolumes
if type == "btrfs":
if device in btrfs_encountered_devices:
continue
btrfs_encountered_devices.add(device)
short_name = " "+device_to_label[device][0]
btrfs_raw = command(["/sbin/btrfs", "fi", "usage", "-b", dir])
for line in btrfs_raw.split("\n"):