commit 4d8e470cd10c08b876c3e336e9b0cf7fd4886b4d from: Benjamin Stürz date: Mon May 15 20:59:37 2023 UTC Sort drives by name commit - 11bd43812906ccb05e702db8020074db24d9b965 commit + 4d8e470cd10c08b876c3e336e9b0cf7fd4886b4d blob - 21907b7b862acc36432e04968bc6798b2a865704 blob + 52ac4241cf3ded520b6b444b6c6b3f43c09a3784 --- ChangeLog.md +++ ChangeLog.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http - Print fancy unicode characters by default. - Use err(3) instead of die() - Use opendev(3) instead of open(2) +- Sort drives by name ### Removed - Options: blob - fa54390ed813718a243f6dfe0ff8499742bad3d4 blob + 084ec3cda9ac1b0305f463d7195f892c976d7abf --- README.md +++ README.md @@ -21,7 +21,9 @@ doas make unroot - [x] `lsblk sd0` - [ ] `lsblk sd0a` - [ ] `lsblk -f duid,size` -- [ ] Sort drives by name +- [ ] Don't use manual padding. +- [ ] Support disks that have more than 2 letters, like `vnd0` +- [x] Sort drives by name - [ ] Add an option to make the output script-friendly (like -c for CSV). - [x] Maybe: Display the child device of a RAID partition - [x] Show the DUID blob - 0b44817852780b41c6aeaf88eb235a5eee5b675c blob + ca98c5850b44dfca7a1c2ae4c5d66f80a9431e72 --- lsblk.c +++ lsblk.c @@ -480,6 +480,14 @@ static int usage (void) { fputs ("Usage: lsblk [-abinUuV] [disk...]\n", stderr); return 1; +} + +static int compare_disk (const void *p1, const void *p2) +{ + const struct my_diskinfo *d1 = p1; + const struct my_diskinfo *d2 = p2; + + return strcmp (d1->name, d2->name); } int main (int argc, char *argv[]) @@ -561,6 +569,8 @@ int main (int argc, char *argv[]) free (names); + mergesort (disks, num_disks, sizeof *disks, compare_disk); + if (!(options & OPT_NOBIO)) { for (size_t i = 0; i < num_disks; ++i) { read_raid (&disks[i], disks, num_disks);