From c24328e26e9a0ce289bb37f164f89039edebfa50 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sat, 14 Sep 2024 16:18:35 +0800 Subject: [PATCH] Btrfs: add new module --- CMakeLists.txt | 7 + src/common/modules.c | 1 + src/detection/btrfs/btrfs.h | 28 +++ src/detection/btrfs/btrfs_linux.c | 166 +++++++++++++++++ src/detection/btrfs/btrfs_nosupport.c | 6 + src/modules/btrfs/btrfs.c | 254 ++++++++++++++++++++++++++ src/modules/btrfs/btrfs.h | 9 + src/modules/btrfs/option.h | 14 ++ src/modules/modules.h | 1 + src/modules/options.h | 1 + src/modules/zpool/zpool.c | 8 +- src/options/modules.c | 2 + src/options/modules.h | 1 + 13 files changed, 494 insertions(+), 4 deletions(-) create mode 100644 src/detection/btrfs/btrfs.h create mode 100644 src/detection/btrfs/btrfs_linux.c create mode 100644 src/detection/btrfs/btrfs_nosupport.c create mode 100644 src/modules/btrfs/btrfs.c create mode 100644 src/modules/btrfs/btrfs.h create mode 100644 src/modules/btrfs/option.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 547d4f06e..4dcfc4868 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,6 +342,7 @@ set(LIBFASTFETCH_SRC src/modules/bootmgr/bootmgr.c src/modules/brightness/brightness.c src/modules/break/break.c + src/modules/btrfs/btrfs.c src/modules/camera/camera.c src/modules/chassis/chassis.c src/modules/colors/colors.c @@ -428,6 +429,7 @@ if(LINUX) src/detection/board/board_linux.c src/detection/bootmgr/bootmgr_linux.c src/detection/brightness/brightness_linux.c + src/detection/btrfs/btrfs_linux.c src/detection/chassis/chassis_linux.c src/detection/cpu/cpu_linux.c src/detection/cpucache/cpucache_linux.c @@ -508,6 +510,7 @@ elseif(ANDROID) src/detection/board/board_android.c src/detection/bootmgr/bootmgr_nosupport.c src/detection/brightness/brightness_nosupport.c + src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_linux.c src/detection/cpucache/cpucache_linux.c @@ -573,6 +576,7 @@ elseif(FreeBSD) src/detection/board/board_bsd.c src/detection/bootmgr/bootmgr_bsd.c src/detection/brightness/brightness_bsd.c + src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_bsd.c src/detection/cpu/cpu_bsd.c src/detection/cpucache/cpucache_shared.c @@ -652,6 +656,7 @@ elseif(APPLE) src/detection/board/board_apple.c src/detection/bootmgr/bootmgr_apple.c src/detection/brightness/brightness_apple.c + src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_nosupport.c src/detection/cpu/cpu_apple.c src/detection/cpucache/cpucache_apple.c @@ -718,6 +723,7 @@ elseif(WIN32) src/detection/board/board_windows.c src/detection/bootmgr/bootmgr_windows.c src/detection/brightness/brightness_windows.cpp + src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_windows.c src/detection/cpu/cpu_windows.c src/detection/cpucache/cpucache_windows.c @@ -785,6 +791,7 @@ elseif(SunOS) src/detection/board/board_windows.c src/detection/bootmgr/bootmgr_nosupport.c src/detection/brightness/brightness_nosupport.c + src/detection/btrfs/btrfs_nosupport.c src/detection/chassis/chassis_windows.c src/detection/cpu/cpu_sunos.c src/detection/cpucache/cpucache_shared.c diff --git a/src/common/modules.c b/src/common/modules.c index 28f270165..232c555f0 100644 --- a/src/common/modules.c +++ b/src/common/modules.c @@ -13,6 +13,7 @@ static FFModuleBaseInfo* B[] = { (void*) &instance.config.modules.bootmgr, (void*) &instance.config.modules.break_, (void*) &instance.config.modules.brightness, + (void*) &instance.config.modules.btrfs, NULL, }; diff --git a/src/detection/btrfs/btrfs.h b/src/detection/btrfs/btrfs.h new file mode 100644 index 000000000..a82157d09 --- /dev/null +++ b/src/detection/btrfs/btrfs.h @@ -0,0 +1,28 @@ +#pragma once + +#include "fastfetch.h" + +typedef struct FFBtrfsDiskUsage +{ + uint64_t total; + uint64_t used; + const char* type; + bool dup; +} FFBtrfsDiskUsage; + +typedef struct FFBtrfsResult +{ + FFstrbuf name; + FFstrbuf uuid; + FFstrbuf devices; + FFstrbuf features; + uint32_t generation; + uint32_t nodeSize; + uint32_t sectorSize; + uint64_t totalSize; + uint64_t globalReservationUsed; + uint64_t globalReservationTotal; + FFBtrfsDiskUsage allocation[3]; +} FFBtrfsResult; + +const char* ffDetectBtrfs(FFlist* result /* list of FFBtrfsResult */); diff --git a/src/detection/btrfs/btrfs_linux.c b/src/detection/btrfs/btrfs_linux.c new file mode 100644 index 000000000..993300bac --- /dev/null +++ b/src/detection/btrfs/btrfs_linux.c @@ -0,0 +1,166 @@ +#include "btrfs.h" + +#include "common/io/io.h" + +enum { uuidLen = (uint32_t) __builtin_strlen("00000000-0000-0000-0000-000000000000") }; + +static const char* enumerateDevices(FFBtrfsResult* item, FFstrbuf* path, FFstrbuf* buffer) +{ + ffStrbufAppendS(path, "devices/"); + FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path->chars); + if(dirp == NULL) + return "opendir(\"/sys/fs/btrfs/UUID/devices\") == NULL"; + const uint32_t devicesPathLen = path->length; + + struct dirent* entry; + while ((entry = readdir(dirp)) != NULL) + { + if (entry->d_name[0] == '.') + continue; + + if (item->devices.length) + ffStrbufAppendC(&item->devices, ','); + ffStrbufAppendS(&item->devices, entry->d_name); + ffStrbufAppendS(path, entry->d_name); + ffStrbufAppendS(path, "/size"); + + if (ffReadFileBuffer(path->chars, buffer)) + item->totalSize += ffStrbufToUInt(buffer, 0) * 512; + + ffStrbufSubstrBefore(path, devicesPathLen); + } + + return NULL; +} + +static const char* enumerateFeatures(FFBtrfsResult* item, FFstrbuf* path) +{ + ffStrbufAppendS(path, "features/"); + FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path->chars); + if(dirp == NULL) + return "opendir(\"/sys/fs/btrfs/UUID/features\") == NULL"; + const uint32_t featuresPathLen = path->length; + + struct dirent* entry; + while ((entry = readdir(dirp)) != NULL) + { + if (entry->d_name[0] == '.') + continue; + if (item->features.length) + ffStrbufAppendC(&item->features, ','); + ffStrbufAppendS(&item->features, entry->d_name); + + ffStrbufSubstrBefore(path, featuresPathLen); + } + + return NULL; +} + +static const char* detectAllocation(FFBtrfsResult* item, FFstrbuf* path, FFstrbuf* buffer) +{ + ffStrbufAppendS(path, "allocation/"); + const uint32_t AllocationPathLen = path->length; + + ffStrbufAppendS(path, "global_rsv_size"); + if (ffReadFileBuffer(path->chars, buffer)) + item->globalReservationTotal = ffStrbufToUInt(buffer, 0); + else + return "ffReadFileBuffer(\"/sys/fs/btrfs/UUID/allocation/global_rsv_size\") == NULL"; + ffStrbufSubstrBefore(path, AllocationPathLen); + + ffStrbufAppendS(path, "global_rsv_reserved"); + if (ffReadFileBuffer(path->chars, buffer)) + item->globalReservationUsed = ffStrbufToUInt(buffer, 0); + ffStrbufSubstrBefore(path, AllocationPathLen); + item->globalReservationUsed = item->globalReservationTotal - item->globalReservationUsed; + + #define FF_BTRFS_DETECT_TYPE(index, _type) \ + ffStrbufAppendS(path, #_type "/total_bytes"); \ + if (ffReadFileBuffer(path->chars, buffer)) \ + item->allocation[index].total = ffStrbufToUInt(buffer, 0); \ + ffStrbufSubstrBefore(path, AllocationPathLen); \ + \ + ffStrbufAppendS(path, #_type "/bytes_used"); \ + if (ffReadFileBuffer(path->chars, buffer)) \ + item->allocation[index].used = ffStrbufToUInt(buffer, 0); \ + ffStrbufSubstrBefore(path, AllocationPathLen); \ + \ + ffStrbufAppendS(path, #_type "/dup"); \ + item->allocation[index].dup = ffPathExists(path->chars, FF_PATHTYPE_DIRECTORY); \ + ffStrbufSubstrBefore(path, AllocationPathLen); \ + \ + item->allocation[index].type = #_type; + + FF_BTRFS_DETECT_TYPE(0, data); + FF_BTRFS_DETECT_TYPE(1, metadata); + FF_BTRFS_DETECT_TYPE(2, system); + + #undef FF_BTRFS_DETECT_TYPE + + return NULL; +} + +const char* ffDetectBtrfs(FFlist* result) +{ + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/fs/btrfs/"); + const uint32_t basePathLen = path.length; + + FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path.chars); + if(dirp == NULL) + return "opendir(\"/sys/fs/btrfs\") == NULL"; + + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); + + struct dirent* entry; + while ((entry = readdir(dirp)) != NULL) + { + if (entry->d_name[0] == '.') + continue; + if (strlen(entry->d_name) != uuidLen) + continue; + + FFBtrfsResult* item = ffListAdd(result); + (*item) = (FFBtrfsResult){}; + ffStrbufInitNS(&item->uuid, uuidLen, entry->d_name); + ffStrbufInit(&item->name); + ffStrbufInit(&item->devices); + ffStrbufInit(&item->features); + + ffStrbufAppendNS(&path, uuidLen, entry->d_name); + ffStrbufAppendC(&path, '/'); + const uint32_t itemPathLen = path.length; + + ffStrbufAppendS(&path, "label"); + if (ffAppendFileBuffer(path.chars, &item->name)) + ffStrbufTrimRightSpace(&item->name); + ffStrbufSubstrBefore(&path, itemPathLen); + + enumerateDevices(item, &path, &buffer); + ffStrbufSubstrBefore(&path, itemPathLen); + + enumerateFeatures(item, &path); + ffStrbufSubstrBefore(&path, itemPathLen); + + ffStrbufAppendS(&path, "generation"); + if (ffReadFileBuffer(path.chars, &buffer)) + item->generation = (uint32_t) ffStrbufToUInt(&buffer, 0); + ffStrbufSubstrBefore(&path, itemPathLen); + + ffStrbufAppendS(&path, "nodesize"); + if (ffReadFileBuffer(path.chars, &buffer)) + item->nodeSize = (uint32_t) ffStrbufToUInt(&buffer, 0); + ffStrbufSubstrBefore(&path, itemPathLen); + + ffStrbufAppendS(&path, "sectorsize"); + if (ffReadFileBuffer(path.chars, &buffer)) + item->sectorSize = (uint32_t) ffStrbufToUInt(&buffer, 0); + ffStrbufSubstrBefore(&path, itemPathLen); + + detectAllocation(item, &path, &buffer); + + // finally + ffStrbufSubstrBefore(&path, basePathLen); + } + + return NULL; +} diff --git a/src/detection/btrfs/btrfs_nosupport.c b/src/detection/btrfs/btrfs_nosupport.c new file mode 100644 index 000000000..23c70a1ef --- /dev/null +++ b/src/detection/btrfs/btrfs_nosupport.c @@ -0,0 +1,6 @@ +#include "btrfs.h" + +const char* ffDetectBtrfs(FF_MAYBE_UNUSED FFlist* result) +{ + return "Not supported on this platform"; +} diff --git a/src/modules/btrfs/btrfs.c b/src/modules/btrfs/btrfs.c new file mode 100644 index 000000000..77e7ba1ad --- /dev/null +++ b/src/modules/btrfs/btrfs.c @@ -0,0 +1,254 @@ +#include "common/printing.h" +#include "common/jsonconfig.h" +#include "common/percent.h" +#include "detection/btrfs/btrfs.h" +#include "modules/btrfs/btrfs.h" +#include "util/stringUtils.h" + +#define FF_BTRFS_NUM_FORMAT_ARGS 13 + +static void printBtrfs(FFBtrfsOptions* options, FFBtrfsResult* result, uint8_t index) +{ + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); + if (options->moduleArgs.key.length == 0) + { + if (result->name.length > 0) + ffStrbufSetF(&buffer, "%s (%s)", FF_BTRFS_MODULE_NAME, result->name.chars); + else + ffStrbufSetS(&buffer, FF_BTRFS_MODULE_NAME); + } + else + { + ffStrbufClear(&buffer); + FF_PARSE_FORMAT_STRING_CHECKED(&buffer, &options->moduleArgs.key, 3, ((FFformatarg[]){ + FF_FORMAT_ARG(index, "index"), + FF_FORMAT_ARG(result->name, "name"), + FF_FORMAT_ARG(options->moduleArgs.keyIcon, "icon"), + })); + } + + uint64_t used = 0, allocated = 0, total = result->totalSize; + for (int i = 0; i < 3; ++i) + { + uint64_t times = result->allocation[i].dup ? 2 : 1; + used += result->allocation[i].used * times; + allocated += result->allocation[i].total * times; + } + + FF_STRBUF_AUTO_DESTROY usedPretty = ffStrbufCreate(); + ffParseSize(used, &usedPretty); + FF_STRBUF_AUTO_DESTROY allocatedPretty = ffStrbufCreate(); + ffParseSize(allocated, &allocatedPretty); + FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate(); + ffParseSize(total, &totalPretty); + + double usedPercentage = total > 0 ? (double) used / (double) total * 100.0 : 0; + double allocatedPercentage = total > 0 ? (double) allocated / (double) total * 100.0 : 0; + + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(buffer.chars, index, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY); + + ffStrbufClear(&buffer); + ffStrbufSetF(&buffer, "%s / %s (", usedPretty.chars, totalPretty.chars); + ffPercentAppendNum(&buffer, usedPercentage, options->percent, false, &options->moduleArgs); + ffStrbufAppendS(&buffer, ", "); + ffPercentAppendNum(&buffer, allocatedPercentage, options->percent, false, &options->moduleArgs); + ffStrbufAppendF(&buffer, " allocated)"); + ffStrbufPutTo(&buffer, stdout); + } + else + { + FF_STRBUF_AUTO_DESTROY usedPercentageNum = ffStrbufCreate(); + ffPercentAppendNum(&usedPercentageNum, usedPercentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY usedPercentageBar = ffStrbufCreate(); + ffPercentAppendBar(&usedPercentageBar, usedPercentage, options->percent, &options->moduleArgs); + + FF_STRBUF_AUTO_DESTROY allocatedPercentageNum = ffStrbufCreate(); + ffPercentAppendNum(&allocatedPercentageNum, allocatedPercentage, options->percent, false, &options->moduleArgs); + FF_STRBUF_AUTO_DESTROY allocatedPercentageBar = ffStrbufCreate(); + ffPercentAppendBar(&allocatedPercentageBar, allocatedPercentage, options->percent, &options->moduleArgs); + + FF_STRBUF_AUTO_DESTROY nodeSizePretty = ffStrbufCreate(); + ffParseSize(result->nodeSize, &nodeSizePretty); + FF_STRBUF_AUTO_DESTROY sectorSizePretty = ffStrbufCreate(); + ffParseSize(result->sectorSize, §orSizePretty); + + FF_PRINT_FORMAT_CHECKED(buffer.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_BTRFS_NUM_FORMAT_ARGS, ((FFformatarg[]) { + FF_FORMAT_ARG(result->name, "name"), + FF_FORMAT_ARG(result->uuid, "uuid"), + FF_FORMAT_ARG(result->devices, "devices"), + FF_FORMAT_ARG(result->features, "features"), + FF_FORMAT_ARG(usedPretty, "used"), + FF_FORMAT_ARG(allocatedPretty, "allocated"), + FF_FORMAT_ARG(totalPretty, "total"), + FF_FORMAT_ARG(usedPercentageNum, "used-percentage"), + FF_FORMAT_ARG(allocatedPercentageNum, "allocated-percentage"), + FF_FORMAT_ARG(usedPercentageBar, "used-percentage-bar"), + FF_FORMAT_ARG(allocatedPercentageBar, "allocated-percentage-bar"), + FF_FORMAT_ARG(nodeSizePretty, "node-size"), + FF_FORMAT_ARG(sectorSizePretty, "sector-size"), + })); + } +} + +void ffPrintBtrfs(FFBtrfsOptions* options) +{ + FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBtrfsResult)); + + const char* error = ffDetectBtrfs(&results); + + if (error) + { + ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error); + return; + } + if(results.length == 0) + { + ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", "No btrfs drive found"); + return; + } + + for(uint32_t i = 0; i < results.length; i++) + { + FFBtrfsResult* result = FF_LIST_GET(FFBtrfsResult, results, i); + uint8_t index = results.length == 1 ? 0 : (uint8_t) (i + 1); + printBtrfs(options, result, index); + } + + FF_LIST_FOR_EACH(FFBtrfsResult, result, results) + { + ffStrbufDestroy(&result->name); + ffStrbufDestroy(&result->uuid); + ffStrbufDestroy(&result->devices); + ffStrbufDestroy(&result->features); + } +} + +bool ffParseBtrfsCommandOptions(FFBtrfsOptions* options, const char* key, const char* value) +{ + const char* subKey = ffOptionTestPrefix(key, FF_BTRFS_MODULE_NAME); + if (!subKey) return false; + if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) + return true; + + if (ffPercentParseCommandOptions(key, subKey, value, &options->percent)) + return true; + + return false; +} + +void ffParseBtrfsJsonObject(FFBtrfsOptions* options, yyjson_val* module) +{ + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(module, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + if(ffStrEqualsIgnCase(key, "type")) + continue; + + if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) + continue; + + if (ffPercentParseJsonObject(key, val, &options->percent)) + continue; + + ffPrintError(FF_BTRFS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key); + } +} + +void ffGenerateBtrfsJsonConfig(FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyBtrfsOptions))) FFBtrfsOptions defaultOptions; + ffInitBtrfsOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent); +} + +void ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBtrfsResult)); + + const char* error = ffDetectBtrfs(&results); + if (error) + { + yyjson_mut_obj_add_str(doc, module, "error", error); + return; + } + + yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result"); + + FF_LIST_FOR_EACH(FFBtrfsResult, btrfs, results) + { + yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr); + yyjson_mut_obj_add_strbuf(doc, obj, "name", &btrfs->name); + yyjson_mut_obj_add_strbuf(doc, obj, "uuid", &btrfs->uuid); + yyjson_mut_obj_add_strbuf(doc, obj, "devices", &btrfs->devices); + yyjson_mut_obj_add_strbuf(doc, obj, "features", &btrfs->features); + yyjson_mut_obj_add_uint(doc, obj, "generation", btrfs->generation); + yyjson_mut_obj_add_uint(doc, obj, "nodeSize", btrfs->nodeSize); + yyjson_mut_obj_add_uint(doc, obj, "sectorSize", btrfs->sectorSize); + yyjson_mut_obj_add_uint(doc, obj, "totalSize", btrfs->totalSize); + yyjson_mut_val* allocation = yyjson_mut_obj_add_arr(doc, obj, "allocation"); + for (int i = 0; i < 3; ++i) + { + yyjson_mut_val* item = yyjson_mut_arr_add_obj(doc, allocation); + yyjson_mut_obj_add_str(doc, item, "type", btrfs->allocation[i].type); + yyjson_mut_obj_add_bool(doc, item, "dup", btrfs->allocation[i].dup); + yyjson_mut_obj_add_uint(doc, item, "used", btrfs->allocation[i].used); + yyjson_mut_obj_add_uint(doc, item, "total", btrfs->allocation[i].total); + } + } + + FF_LIST_FOR_EACH(FFBtrfsResult, btrfs, results) + { + ffStrbufDestroy(&btrfs->name); + ffStrbufDestroy(&btrfs->uuid); + ffStrbufDestroy(&btrfs->devices); + ffStrbufDestroy(&btrfs->features); + } +} + +void ffPrintBtrfsHelpFormat(void) +{ + FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_BTRFS_MODULE_NAME, "{5} / {7} ({8}, {9} allocated)", FF_BTRFS_NUM_FORMAT_ARGS, ((const char* []) { + "Name / Label - name", + "UUID - uuid", + "Associated devices - devices", + "Enabled features - features", + "Size used - used", + "Size allocated - allocated", + "Size total - total", + "Used percentage num - used-percentage", + "Allocated percentage num - allocated-percentage", + "Used percentage bar - used-percentage-bar", + "Allocated percentage bar - allocated-percentage-bar", + "Node size - node-size", + "Sector size - sector-size", + })); +} + +void ffInitBtrfsOptions(FFBtrfsOptions* options) +{ + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_BTRFS_MODULE_NAME, + "Print BTRFS volumes", + ffParseBtrfsCommandOptions, + ffParseBtrfsJsonObject, + ffPrintBtrfs, + ffGenerateBtrfsJsonResult, + ffPrintBtrfsHelpFormat, + ffGenerateBtrfsJsonConfig + ); + ffOptionInitModuleArg(&options->moduleArgs, "󱑛"); + options->percent = (FFColorRangeConfig) { 50, 80 }; +} + +void ffDestroyBtrfsOptions(FFBtrfsOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/btrfs/btrfs.h b/src/modules/btrfs/btrfs.h new file mode 100644 index 000000000..25df25084 --- /dev/null +++ b/src/modules/btrfs/btrfs.h @@ -0,0 +1,9 @@ +#pragma once + +#include "fastfetch.h" + +#define FF_BTRFS_MODULE_NAME "Btrfs" + +void ffPrintBtrfs(FFBtrfsOptions* options); +void ffInitBtrfsOptions(FFBtrfsOptions* options); +void ffDestroyBtrfsOptions(FFBtrfsOptions* options); diff --git a/src/modules/btrfs/option.h b/src/modules/btrfs/option.h new file mode 100644 index 000000000..504b15768 --- /dev/null +++ b/src/modules/btrfs/option.h @@ -0,0 +1,14 @@ +#pragma once + +// This file will be included in "fastfetch.h", do NOT put unnecessary things here + +#include "common/option.h" +#include "common/percent.h" + +typedef struct FFBtrfsOptions +{ + FFModuleBaseInfo moduleInfo; + FFModuleArgs moduleArgs; + + FFColorRangeConfig percent; +} FFBtrfsOptions; diff --git a/src/modules/modules.h b/src/modules/modules.h index d6e6f5c14..84d9e6fcb 100644 --- a/src/modules/modules.h +++ b/src/modules/modules.h @@ -10,6 +10,7 @@ #include "modules/board/board.h" #include "modules/bootmgr/bootmgr.h" #include "modules/break/break.h" +#include "modules/btrfs/btrfs.h" #include "modules/camera/camera.h" #include "modules/chassis/chassis.h" #include "modules/cpu/cpu.h" diff --git a/src/modules/options.h b/src/modules/options.h index 74ad4c0b4..2677d2515 100644 --- a/src/modules/options.h +++ b/src/modules/options.h @@ -10,6 +10,7 @@ #include "modules/bootmgr/option.h" #include "modules/break/option.h" #include "modules/brightness/option.h" +#include "modules/btrfs/option.h" #include "modules/camera/option.h" #include "modules/chassis/option.h" #include "modules/cpu/option.h" diff --git a/src/modules/zpool/zpool.c b/src/modules/zpool/zpool.c index 66a59f291..7288a03dd 100644 --- a/src/modules/zpool/zpool.c +++ b/src/modules/zpool/zpool.c @@ -66,7 +66,7 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i FF_FORMAT_ARG(usedPretty, "size-used"), FF_FORMAT_ARG(totalPretty, "size-total"), FF_FORMAT_ARG(bytesPercentageNum, "size-percentage"), - FF_FORMAT_ARG(fragPercentage, "frag-percentage"), + FF_FORMAT_ARG(fragPercentageNum, "frag-percentage"), FF_FORMAT_ARG(bytesPercentageBar, "size-percentage-bar"), FF_FORMAT_ARG(fragPercentageBar, "frag-percentage-bar"), })); @@ -171,10 +171,10 @@ void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_m yyjson_mut_obj_add_uint(doc, obj, "fragmentation", zpool->fragmentation); } - FF_LIST_FOR_EACH(FFZpoolResult, battery, results) + FF_LIST_FOR_EACH(FFZpoolResult, zpool, results) { - ffStrbufDestroy(&battery->name); - ffStrbufDestroy(&battery->state); + ffStrbufDestroy(&zpool->name); + ffStrbufDestroy(&zpool->state); } } diff --git a/src/options/modules.c b/src/options/modules.c index 22c6fcf5b..10b6fc627 100644 --- a/src/options/modules.c +++ b/src/options/modules.c @@ -11,6 +11,7 @@ void ffOptionsInitModules(FFOptionsModules* options) ffInitBootmgrOptions(&options->bootmgr); ffInitBreakOptions(&options->break_); ffInitBrightnessOptions(&options->brightness); + ffInitBtrfsOptions(&options->btrfs); ffInitCameraOptions(&options->camera); ffInitCPUOptions(&options->cpu); ffInitCPUUsageOptions(&options->cpuUsage); @@ -84,6 +85,7 @@ void ffOptionsDestroyModules(FFOptionsModules* options) ffDestroyBootmgrOptions(&options->bootmgr); ffDestroyBreakOptions(&options->break_); ffDestroyBrightnessOptions(&options->brightness); + ffDestroyBtrfsOptions(&options->btrfs); ffDestroyCameraOptions(&options->camera); ffDestroyCPUOptions(&options->cpu); ffDestroyCPUCacheOptions(&options->cpuCache); diff --git a/src/options/modules.h b/src/options/modules.h index 27ec92dc4..7f210be69 100644 --- a/src/options/modules.h +++ b/src/options/modules.h @@ -12,6 +12,7 @@ typedef struct FFOptionsModules FFBootmgrOptions bootmgr; FFBreakOptions break_; FFBrightnessOptions brightness; + FFBtrfsOptions btrfs; FFCPUOptions cpu; FFCPUCacheOptions cpuCache; FFCPUUsageOptions cpuUsage;