diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index 3ce33aed5..de25d634e 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -19,13 +19,6 @@ const FFDiskResult* ffDetectDisks() if(result.disks.length == 0 && result.error.length == 0) ffStrbufAppendS(&result.error, "No disks found"); - for(uint32_t i = 0; i < result.disks.length; ++i) - { - FFDisk* disk = ffListGet(&result.disks, i); - disk->bytesPercentage = (uint8_t) (((long double) disk->bytesUsed / (long double) disk->bytesTotal) * 100.0); - disk->filesPercentage = (uint8_t) (((long double) disk->filesUsed / (long double) disk->filesTotal) * 100.0); - } - //We need to sort the disks, so that we can detect, which disk a path resides on // For example for /boot/efi/bootmgr we need to check /boot/efi before /boot //Note that we sort alphabetically here for a better ordering when printing the list, diff --git a/src/detection/disk/disk.h b/src/detection/disk/disk.h index e8b6b100b..c061ce6c9 100644 --- a/src/detection/disk/disk.h +++ b/src/detection/disk/disk.h @@ -21,11 +21,9 @@ typedef struct FFDisk uint64_t bytesUsed; uint64_t bytesTotal; - uint8_t bytesPercentage; uint32_t filesUsed; uint32_t filesTotal; - uint8_t filesPercentage; } FFDisk; typedef struct FFDiskResult diff --git a/src/modules/disk.c b/src/modules/disk.c index 3ec02f59f..0245d8a4a 100644 --- a/src/modules/disk.c +++ b/src/modules/disk.c @@ -30,23 +30,31 @@ static void printDisk(FFinstance* instance, const FFDisk* disk) ffStrbufInit(&totalPretty); ffParseSize(disk->bytesTotal, instance->config.binaryPrefixType, &totalPretty); + uint8_t bytesPercentage = disk->bytesTotal > 0 ? (uint8_t) (((long double) disk->bytesUsed / (long double) disk->bytesTotal) * 100.0) : 0; + if(instance->config.disk.outputFormat.length == 0) { ffPrintLogoAndKey(instance, key.chars, 0, NULL); - printf("%s / %s (%u%%)", usedPretty.chars, totalPretty.chars, disk->bytesPercentage); + if(disk->bytesTotal > 0) + printf("%s / %s (%u%%)", usedPretty.chars, totalPretty.chars, bytesPercentage); + else + fputs("unknown", stdout); + if(disk->type == FF_DISK_TYPE_EXTERNAL) printf(" [Removable]"); putchar('\n'); } else { + uint8_t filesPercentage = disk->filesTotal > 0 ? (uint8_t) (((double) disk->filesUsed / (double) disk->filesTotal) * 100.0) : 0; + ffPrintFormatString(instance, key.chars, 0, NULL, &instance->config.disk.outputFormat, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty}, - {FF_FORMAT_ARG_TYPE_UINT8, &disk->bytesPercentage}, + {FF_FORMAT_ARG_TYPE_UINT8, &bytesPercentage}, {FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed}, {FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal}, - {FF_FORMAT_ARG_TYPE_UINT8, &disk->filesPercentage}, + {FF_FORMAT_ARG_TYPE_UINT8, &filesPercentage}, {FF_FORMAT_ARG_TYPE_BOOL, FF_FORMAT_ARG_VALUE_BOOL(disk->type == FF_DISK_TYPE_EXTERNAL)}, {FF_FORMAT_ARG_TYPE_BOOL, FF_FORMAT_ARG_VALUE_BOOL(disk->type == FF_DISK_TYPE_HIDDEN)}, {FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},