teddysun / across

Across the Great Wall we can reach every corner in the world
https://teddysun.com
Apache License 2.0
4.94k stars 2.22k forks source link

disk_total_size calculation error on btrfs with subvolumes #102

Open Schroedingersdoraemon opened 1 year ago

Schroedingersdoraemon commented 1 year ago

Dear teddysun,

I am using btrfs with subvolumes:

$ btrfs subvolume list / 
ID 256 gen 1430873 top level 5 path @
ID 257 gen 1430873 top level 5 path @home

The disk_total_size in the script will seemingly calculate the sum of all the subvolumes, producing a multiplied and redundant result.

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 119.2G  0 disk 
└─sda1        8:1    0 119.2G  0 part /var/lib/libvirt/images
nvme0n1     259:0    0 476.9G  0 disk 
├─nvme0n1p1 259:1    0   128M  0 part /boot
├─nvme0n1p2 259:2    0     8G  0 part 
└─nvme0n1p3 259:3    0 468.8G  0 part /home
                                      /
$ df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p3  469G  360G  107G  78% /
/dev/nvme0n1p1  127M   73M   54M  58% /boot
/dev/nvme0n1p3  469G  360G  107G  78% /home
/dev/sda1       117G  106G  5.7G  95% /var/lib/libvirt/images
total           1.1T  826G  219G  80% -

The correct answer should be 117 G + 469G + 127M $\approx$ 586 G, whilist here the unnecessary addition of a subvolume of 469G was added, the result became 586 G + 469 G $\approx$ 1.1 T