From cbe239bf71e3d8e15ae71e64d6e11ea0c2d7bbf5 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 6 Nov 2019 15:58:07 +0100 Subject: [PATCH] btrfs-progs: fi usage: sort table by device id The result of 'btrfs fi usate -T' looks strange when the devices are sorted by path and not by id. It's harder to lookup and the device id reflects "the order of appearance" in the filesystem. Original output: Data Metadata System Id Path RAID0 RAID1 RAID1 Unallocated -- ---------- --------- --------- -------- ----------- 6 /dev/loop0 204.75MiB - - 1.80GiB 3 /dev/loop1 204.75MiB - - 1.80GiB 8 /dev/loop2 204.75MiB 256.00MiB 8.00MiB 1.54GiB 1 /dev/loop3 204.75MiB - - 1.80GiB 5 /dev/loop4 204.75MiB - - 1.80GiB 4 /dev/loop5 204.75MiB - - 1.80GiB 2 /dev/loop6 204.75MiB - - 1.80GiB 7 /dev/loop7 204.75MiB 256.00MiB 8.00MiB 1.54GiB -- ---------- --------- --------- -------- ----------- Total 1.60GiB 256.00MiB 8.00MiB 13.88GiB Used 0.00B 112.00KiB 16.00KiB New output: Data Metadata System Id Path RAID0 RAID1 RAID1 Unallocated -- ---------- --------- --------- -------- ----------- 1 /dev/loop3 204.75MiB - - 1.80GiB 2 /dev/loop6 204.75MiB - - 1.80GiB 3 /dev/loop1 204.75MiB - - 1.80GiB 4 /dev/loop5 204.75MiB - - 1.80GiB 5 /dev/loop4 204.75MiB - - 1.80GiB 6 /dev/loop0 204.75MiB - - 1.80GiB 7 /dev/loop7 204.75MiB 256.00MiB 8.00MiB 1.54GiB 8 /dev/loop2 204.75MiB 256.00MiB 8.00MiB 1.54GiB -- ---------- --------- --------- -------- ----------- Total 1.60GiB 256.00MiB 8.00MiB 13.88GiB Used 0.00B 112.00KiB 16.00KiB Signed-off-by: David Sterba --- cmds/filesystem-usage.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c index 21232218..9d8f263e 100644 --- a/cmds/filesystem-usage.c +++ b/cmds/filesystem-usage.c @@ -502,8 +502,15 @@ exit: */ static int cmp_device_info(const void *a, const void *b) { - return strcmp(((struct device_info *)a)->path, - ((struct device_info *)b)->path); + const struct device_info *deva = a; + const struct device_info *devb = b; + + if (deva->devid < devb->devid) + return -1; + if (deva->devid > devb->devid) + return 1; + + return 0; } int dev_to_fsid(const char *dev, u8 *fsid)