Make shell:disk_list_partitions() report PiB ad EiB

I.e. pebibytes and exbibytes. 1 zebibyte (ZiB) is 2^70 bytes which is
above 2^64 bytes, so ignore it so far.

Btw, 2^80 bytes is 1 yobibyte (YiB).
This commit is contained in:
Ivan Baravy 2023-01-04 20:36:34 +00:00
parent 464b92cda4
commit ef72da6b76

37
shell.c
View File

@ -4,7 +4,7 @@
UMKa - User-Mode KolibriOS developer tools UMKa - User-Mode KolibriOS developer tools
umka_shell - the shell umka_shell - the shell
Copyright (C) 2017-2022 Ivan Baravy <dunkaist@gmail.com> Copyright (C) 2017-2023 Ivan Baravy <dunkaist@gmail.com>
Copyright (C) 2021 Magomed Kostoev <mkostoevr@yandex.ru> Copyright (C) 2021 Magomed Kostoev <mkostoevr@yandex.ru>
*/ */
@ -477,7 +477,7 @@ cmd_i40(struct shell_ctx *ctx, int argc, char **argv) {
} }
static void static void
bytes_to_kmgt(uint64_t *bytes, const char **kmg) { bytes_to_kmgtpe(uint64_t *bytes, const char **kmg) {
*kmg = "B"; *kmg = "B";
lldiv_t d = lldiv(*bytes, 1024); lldiv_t d = lldiv(*bytes, 1024);
if (d.rem != 0) { if (d.rem != 0) {
@ -503,16 +503,28 @@ bytes_to_kmgt(uint64_t *bytes, const char **kmg) {
} }
*bytes = d.quot; *bytes = d.quot;
*kmg = "TiB"; *kmg = "TiB";
d = lldiv(*bytes, 1024);
if (d.rem != 0) {
return;
}
*bytes = d.quot;
*kmg = "PiB";
d = lldiv(*bytes, 1024);
if (d.rem != 0) {
return;
}
*bytes = d.quot;
*kmg = "EiB";
} }
static void static void
disk_list_partitions(disk_t *d) { disk_list_partitions(disk_t *d) {
uint64_t kmgt_count = d->media_info.sector_size * d->media_info.capacity; uint64_t kmgtpe_count = d->media_info.sector_size * d->media_info.capacity;
const char *kmgt = NULL; const char *kmgtpe = NULL;
bytes_to_kmgt(&kmgt_count, &kmgt); bytes_to_kmgtpe(&kmgtpe_count, &kmgtpe);
printf("/%s: sector_size=%u, capacity=%" PRIu64 " (%" PRIu64 " %s), " printf("/%s: sector_size=%u, capacity=%" PRIu64 " (%" PRIu64 " %s), "
"num_partitions=%u\n", d->name, d->media_info.sector_size, "num_partitions=%u\n", d->name, d->media_info.sector_size,
d->media_info.capacity, kmgt_count, kmgt, d->num_partitions); d->media_info.capacity, kmgtpe_count, kmgtpe, d->num_partitions);
for (size_t i = 0; i < d->num_partitions; i++) { for (size_t i = 0; i < d->num_partitions; i++) {
partition_t *p = d->partitions[i]; partition_t *p = d->partitions[i];
const char *fsname; const char *fsname;
@ -529,11 +541,14 @@ disk_list_partitions(disk_t *d) {
} else { } else {
fsname = "???"; fsname = "???";
} }
kmgt_count = d->media_info.sector_size * p->length; kmgtpe_count = d->media_info.sector_size * p->first_sector;
bytes_to_kmgt(&kmgt_count, &kmgt); bytes_to_kmgtpe(&kmgtpe_count, &kmgtpe);
printf("/%s/%d: fs=%s, start=%" PRIu64 ", length=%" PRIu64 printf("/%s/%d: fs=%s, start=%" PRIu64 " (%" PRIu64 " %s)",
" (%" PRIu64 " %s)\n", d->name, i+1, fsname, p->first_sector, d->name, i+1, fsname, p->first_sector, kmgtpe_count, kmgtpe);
p->length, kmgt_count, kmgt); kmgtpe_count = d->media_info.sector_size * p->length;
bytes_to_kmgtpe(&kmgtpe_count, &kmgtpe);
printf(", length=%" PRIu64 " (%" PRIu64 " %s)\n",
p->length, kmgtpe_count, kmgtpe);
} }
} }