aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

commit c1bf70f88d5be361ebf1009b05cdd1af3cc1b9a8
parent 6dd3f38e81f07c0cd019c71c1b56b7f1e1a9db79
Author: xplshn <anto@xplshn.com.ar>
Date:   Tue, 24 Nov 2026 07:58:41 -0300

diskutil reports a disk's model, partplan lists it

Diffstat:
Mcmd/extra/partplan.c | 19+++----------------
Mshared/diskutil.h | 1+
Mshared/libutil/diskutil.c | 23+++++++++++++++++++++++
3 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/cmd/extra/partplan.c b/cmd/extra/partplan.c @@ -44,10 +44,8 @@ do_disks(void) struct BlockDevInfo *list = blockdev_get_list(), *d; for (d = list; d; d = d->next) { - char path[96], model[64] = ""; - int busy = d->mountpoint[0] != '\0', skipped = 0; - size_t i; - FILE *f; + int busy = d->mountpoint[0] != '\0', skipped = 0; + size_t i; struct BlockDevInfo *part; for (i = 0; i < sizeof skip / sizeof skip[0]; i++) @@ -58,18 +56,7 @@ do_disks(void) for (part = d->parts; part; part = part->next) if (part->mountpoint[0]) busy = 1; - snprintf(path, sizeof path, "/sys/block/%s/device/model", d->name); - if ((f = fopen(path, "r"))) { - if (fgets(model, sizeof model, f)) { - size_t n; - - model[strcspn(model, "\n")] = '\0'; - for (n = strlen(model); n > 0 && model[n - 1] == ' '; n--) - model[n - 1] = '\0'; - } - fclose(f); - } - printf("%s\t%llu\t%s\t%d\n", d->name, (unsigned long long)d->size, model, busy); + printf("%s\t%llu\t%s\t%d\n", d->name, (unsigned long long)d->size, d->model, busy); } blockdev_free_list(list); return 0; diff --git a/shared/diskutil.h b/shared/diskutil.h @@ -23,6 +23,7 @@ struct BlockDevInfo { int minor; char mountpoint[256]; char fstype[32]; + char model[64]; // what the disk calls itself, "" when it does not say struct BlockDevInfo *parts; struct BlockDevInfo *next; }; diff --git a/shared/libutil/diskutil.c b/shared/libutil/diskutil.c @@ -132,6 +132,28 @@ blockdev_close(struct BlockDev *dev) } } +#if defined(__linux__) +/* the model the disk reports, without the blanks firmware pads it with */ +static void +disk_model(const char *name, char *out, size_t n) +{ + char path[128]; + FILE *f; + size_t len; + + out[0] = '\0'; + snprintf(path, sizeof(path), "/sys/block/%s/device/model", name); + if (!(f = fopen(path, "r"))) + return; + if (fgets(out, (int)n, f)) { + out[strcspn(out, "\n")] = '\0'; + for (len = strlen(out); len > 0 && out[len - 1] == ' '; len--) + out[len - 1] = '\0'; + } + fclose(f); +} +#endif + struct BlockDevInfo * blockdev_get_list(void) { @@ -199,6 +221,7 @@ blockdev_get_list(void) if (!is_part) { strlcpy(info->type, "disk", sizeof(info->type)); + disk_model(info->name, info->model, sizeof(info->model)); if (!head) { head = info; } else {