mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Zpool: don't report invalid fragmentation
This commit is contained in:
@@ -9,7 +9,7 @@ typedef struct FFZpoolResult
|
||||
uint64_t used;
|
||||
uint64_t total;
|
||||
uint64_t version;
|
||||
uint64_t fragmentation;
|
||||
double fragmentation;
|
||||
} FFZpoolResult;
|
||||
|
||||
const char* ffDetectZpool(FFlist* result /* list of FFZpoolResult */);
|
||||
|
||||
@@ -73,7 +73,8 @@ static int enumZpoolCallback(zpool_handle_t* zpool, void* param)
|
||||
item->version = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_VERSION, &source);
|
||||
item->total = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_SIZE, &source);
|
||||
item->used = item->total - data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FREE, &source);
|
||||
item->fragmentation = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FRAGMENTATION, &source);
|
||||
uint64_t fragmentation = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FRAGMENTATION, &source);
|
||||
item->fragmentation = fragmentation == UINT64_MAX ? 0.0/0.0 : (double) fragmentation;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i
|
||||
ffParseSize(result->total, &totalPretty);
|
||||
|
||||
double bytesPercentage = result->total > 0 ? (double) result->used / (double) result->total * 100.0 : 0;
|
||||
double fragPercentage = (double) result->fragmentation;
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
@@ -44,7 +43,7 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i
|
||||
ffStrbufSetF(&buffer, "%s / %s (", usedPretty.chars, totalPretty.chars);
|
||||
ffPercentAppendNum(&buffer, bytesPercentage, options->percent, false, &options->moduleArgs);
|
||||
ffStrbufAppendS(&buffer, ", ");
|
||||
ffPercentAppendNum(&buffer, fragPercentage, options->percent, false, &options->moduleArgs);
|
||||
ffPercentAppendNum(&buffer, result->fragmentation, options->percent, false, &options->moduleArgs);
|
||||
ffStrbufAppendF(&buffer, " frag) - %s", result->state.chars);
|
||||
ffStrbufPutTo(&buffer, stdout);
|
||||
}
|
||||
@@ -56,9 +55,9 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i
|
||||
ffPercentAppendBar(&bytesPercentageBar, bytesPercentage, options->percent, &options->moduleArgs);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY fragPercentageNum = ffStrbufCreate();
|
||||
ffPercentAppendNum(&fragPercentageNum, fragPercentage, options->percent, false, &options->moduleArgs);
|
||||
ffPercentAppendNum(&fragPercentageNum, result->fragmentation, options->percent, false, &options->moduleArgs);
|
||||
FF_STRBUF_AUTO_DESTROY fragPercentageBar = ffStrbufCreate();
|
||||
ffPercentAppendBar(&fragPercentageBar, fragPercentage, options->percent, &options->moduleArgs);
|
||||
ffPercentAppendBar(&fragPercentageBar, result->fragmentation, options->percent, &options->moduleArgs);
|
||||
|
||||
FF_PRINT_FORMAT_CHECKED(buffer.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_ZPOOL_NUM_FORMAT_ARGS, ((FFformatarg[]) {
|
||||
FF_FORMAT_ARG(result->name, "name"),
|
||||
@@ -168,7 +167,7 @@ void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_m
|
||||
yyjson_mut_obj_add_uint(doc, obj, "used", zpool->used);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "total", zpool->total);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "version", zpool->version);
|
||||
yyjson_mut_obj_add_uint(doc, obj, "fragmentation", zpool->fragmentation);
|
||||
yyjson_mut_obj_add_real(doc, obj, "fragmentation", zpool->fragmentation);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFZpoolResult, zpool, results)
|
||||
|
||||
Reference in New Issue
Block a user