diff --git a/src/common/init.c b/src/common/init.c index ebf261031..c3aeb1f9b 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -157,10 +157,7 @@ static void defaultConfig(FFinstance* instance) instance->config.titleFQDN = false; ffStrbufInitA(&instance->config.diskFolders, 0); - instance->config.diskShowRemovable = true; - instance->config.diskShowHidden = false; - instance->config.diskShowUnknown = false; - instance->config.diskShowSubvolumes = false; + instance->config.diskShowTypes = FF_DISK_TYPE_REGULAR_BIT | FF_DISK_TYPE_EXTERNAL_BIT; instance->config.displayCompactType = FF_DISPLAY_COMPACT_TYPE_NONE; instance->config.displayDetectName = false; diff --git a/src/data/help.txt b/src/data/help.txt index 08749c08d..83428e0da 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -108,6 +108,7 @@ Module specific options: --shell-version : Set if shell version should be detected and printed --terminal-version : Set if terminal version should be detected and printed --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) + --disk-show-regular : Set if regular volume should be printed. Default is true --disk-show-removable : Set if removable volume should be printed. Default is true --disk-show-hidden : Set if hidden volumes should be printed. Default is false --disk-show-subvolumes : Set if subvolumes should be printed. Default is false diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index de25d634e..55cfec7de 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -18,11 +18,18 @@ const FFDiskResult* ffDetectDisks() if(result.disks.length == 0 && result.error.length == 0) ffStrbufAppendS(&result.error, "No disks found"); - - //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, - // so the check must be done in reverse order - ffListSort(&result.disks, compareDisks); + else + { + //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, + // so the check must be done in reverse order + ffListSort(&result.disks, compareDisks); + FF_LIST_FOR_EACH(FFDisk, disk, result.disks) + { + if(disk->bytesTotal == 0) + disk->type |= FF_DISK_TYPE_UNKNOWN_BIT; + } + } ); } diff --git a/src/detection/disk/disk.h b/src/detection/disk/disk.h index f4230ce46..9572f267f 100644 --- a/src/detection/disk/disk.h +++ b/src/detection/disk/disk.h @@ -5,14 +5,6 @@ #include "fastfetch.h" -typedef enum FFDiskType -{ - FF_DISK_TYPE_REGULAR, - FF_DISK_TYPE_HIDDEN, - FF_DISK_TYPE_EXTERNAL, - FF_DISK_TYPE_SUBVOLUME -} FFDiskType; - typedef struct FFDisk { FFstrbuf mountpoint; diff --git a/src/detection/disk/disk_apple.m b/src/detection/disk/disk_apple.m index b2f7cec08..8868dd801 100644 --- a/src/detection/disk/disk_apple.m +++ b/src/detection/disk/disk_apple.m @@ -7,11 +7,11 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) { // FreeBSD doesn't support these flags if(fs->f_flags & MNT_DONTBROWSE) - disk->type = FF_DISK_TYPE_HIDDEN; + disk->type = FF_DISK_TYPE_HIDDEN_BIT; else if(fs->f_flags & MNT_REMOVABLE) - disk->type = FF_DISK_TYPE_EXTERNAL; + disk->type = FF_DISK_TYPE_EXTERNAL_BIT; else - disk->type = FF_DISK_TYPE_REGULAR; + disk->type = FF_DISK_TYPE_REGULAR_BIT; ffStrbufInitS(&disk->name, [NSFileManager.defaultManager displayNameAtPath:@(fs->f_mntonname)].UTF8String); } diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 0e14ef3f2..3ff71925a 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -13,11 +13,11 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk) ffStrbufStartsWithS(&disk->mountpoint, "/proc") || ffStrbufStartsWithS(&disk->mountpoint, "/zroot") ) - disk->type = FF_DISK_TYPE_HIDDEN; + disk->type = FF_DISK_TYPE_HIDDEN_BIT; else if((fs->f_flags & MNT_NOSUID) || !(fs->f_flags & MNT_LOCAL)) - disk->type = FF_DISK_TYPE_EXTERNAL; + disk->type = FF_DISK_TYPE_EXTERNAL_BIT; else - disk->type = FF_DISK_TYPE_REGULAR; + disk->type = FF_DISK_TYPE_REGULAR_BIT; ffStrbufInit(&disk->name); } diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 94b4c3488..2d54b20e2 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -112,7 +112,7 @@ static void detectName(FFDisk* disk, const FFstrbuf* device) if(stat(device->chars, &deviceStat) != 0) return; - FFstrbuf basePath; + FF_STRBUF_AUTO_DESTROY basePath; ffStrbufInit(&basePath); //Try partlabel first @@ -129,8 +129,6 @@ static void detectName(FFDisk* disk, const FFstrbuf* device) //Use the mountpoint as a last resort if(disk->name.length == 0) ffStrbufAppend(&disk->name, &disk->mountpoint); - - ffStrbufDestroy(&basePath); } #ifdef __ANDROID__ @@ -138,11 +136,11 @@ static void detectName(FFDisk* disk, const FFstrbuf* device) static void detectType(FF_MAYBE_UNUSED const FFlist* devices, FFDisk* currentDisk, FF_MAYBE_UNUSED const char* options) { if(ffStrbufEqualS(¤tDisk->mountpoint, "/") || ffStrbufEqualS(¤tDisk->mountpoint, "/storage/emulated")) - currentDisk->type = FF_DISK_TYPE_REGULAR; + currentDisk->type = FF_DISK_TYPE_REGULAR_BIT; else if(ffStrbufStartsWithS(¤tDisk->mountpoint, "/mnt/media_rw/")) - currentDisk->type = FF_DISK_TYPE_EXTERNAL; + currentDisk->type = FF_DISK_TYPE_EXTERNAL_BIT; else - currentDisk->type = FF_DISK_TYPE_HIDDEN; + currentDisk->type = FF_DISK_TYPE_HIDDEN_BIT; } #else @@ -171,13 +169,13 @@ static bool isSubvolume(const FFlist* devices) static void detectType(const FFlist* devices, FFDisk* currentDisk, const char* options) { if(isSubvolume(devices)) - currentDisk->type = FF_DISK_TYPE_SUBVOLUME; + currentDisk->type = FF_DISK_TYPE_SUBVOLUME_BIT; else if(strstr(options, "nosuid") != NULL || strstr(options, "nodev") != NULL) - currentDisk->type = FF_DISK_TYPE_EXTERNAL; + currentDisk->type = FF_DISK_TYPE_EXTERNAL_BIT; else if(ffStrbufStartsWithS(¤tDisk->mountpoint, "/boot") || ffStrbufStartsWithS(¤tDisk->mountpoint, "/efi")) - currentDisk->type = FF_DISK_TYPE_HIDDEN; + currentDisk->type = FF_DISK_TYPE_HIDDEN_BIT; else - currentDisk->type = FF_DISK_TYPE_REGULAR; + currentDisk->type = FF_DISK_TYPE_REGULAR_BIT; } #endif @@ -204,7 +202,7 @@ void ffDetectDisksImpl(FFDiskResult* disks) return; } - FFlist devices; + FF_LIST_AUTO_DESTROY devices; ffListInit(&devices, sizeof(FFstrbuf)); char* line = NULL; @@ -254,7 +252,6 @@ void ffDetectDisksImpl(FFDiskResult* disks) FF_LIST_FOR_EACH(FFstrbuf, device, devices) ffStrbufDestroy(device); - ffListDestroy(&devices); fclose(mountsFile); } diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index c5c881b57..d98362694 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -33,11 +33,11 @@ void ffDetectDisksImpl(FFDiskResult* disks) disk->bytesUsed = disk->bytesTotal - bytesFree; if(driveType == DRIVE_REMOVABLE || driveType == DRIVE_REMOTE || driveType == DRIVE_CDROM) - disk->type = FF_DISK_TYPE_EXTERNAL; + disk->type = FF_DISK_TYPE_EXTERNAL_BIT; else if(driveType == DRIVE_FIXED) - disk->type = FF_DISK_TYPE_REGULAR; + disk->type = FF_DISK_TYPE_REGULAR_BIT; else - disk->type = FF_DISK_TYPE_HIDDEN; + disk->type = FF_DISK_TYPE_HIDDEN_BIT; ffStrbufInit(&disk->filesystem); ffStrbufInit(&disk->name); diff --git a/src/fastfetch.c b/src/fastfetch.c index 462b546c6..63480f514 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1262,14 +1262,16 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con instance->config.terminalVersion = optionParseBoolean(value); else if(strcasecmp(key, "--disk-folders") == 0) optionParseString(key, value, &instance->config.diskFolders); + else if(strcasecmp(key, "--disk-show-regular") == 0) + optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_REGULAR_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_REGULAR_BIT); else if(strcasecmp(key, "--disk-show-removable") == 0) - instance->config.diskShowRemovable = optionParseBoolean(value); + optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_EXTERNAL_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_EXTERNAL_BIT); else if(strcasecmp(key, "--disk-show-hidden") == 0) - instance->config.diskShowHidden = optionParseBoolean(value); + optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_HIDDEN_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_HIDDEN_BIT); else if(strcasecmp(key, "--disk-show-subvolumes") == 0) - instance->config.diskShowSubvolumes = optionParseBoolean(value); + optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_SUBVOLUME_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_SUBVOLUME_BIT); else if(strcasecmp(key, "--disk-show-unknown") == 0) - instance->config.diskShowUnknown = optionParseBoolean(value); + optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_UNKNOWN_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_UNKNOWN_BIT); else if(strcasecmp(key, "--display-compact-type") == 0) { optionParseEnum(key, value, &instance->config.displayCompactType, diff --git a/src/fastfetch.h b/src/fastfetch.h index 7545c599b..3e7c52c19 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -55,6 +55,16 @@ typedef enum FFLocalIpCompactType FF_LOCALIP_COMPACT_TYPE_ONELINE, } FFLocalIpCompactType; +typedef enum FFDiskType +{ + FF_DISK_TYPE_NONE = 0, + FF_DISK_TYPE_REGULAR_BIT = 1 << 0, + FF_DISK_TYPE_HIDDEN_BIT = 1 << 1, + FF_DISK_TYPE_EXTERNAL_BIT = 1 << 2, + FF_DISK_TYPE_SUBVOLUME_BIT = 1 << 3, + FF_DISK_TYPE_UNKNOWN_BIT = 1 << 4, +} FFDiskType; + typedef enum FFBinaryPrefixType { FF_BINARY_PREFIX_TYPE_IEC, // 1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard) @@ -217,10 +227,7 @@ typedef struct FFconfig bool terminalVersion; FFstrbuf diskFolders; - bool diskShowRemovable; - bool diskShowHidden; - bool diskShowUnknown; - bool diskShowSubvolumes; + FFDiskType diskShowTypes; FFDisplayCompactType displayCompactType; bool displayDetectName; diff --git a/src/modules/disk.c b/src/modules/disk.c index d2311f11f..dd2064d73 100644 --- a/src/modules/disk.c +++ b/src/modules/disk.c @@ -9,7 +9,7 @@ static void printDisk(FFinstance* instance, const FFDisk* disk) { - FFstrbuf key; + FF_STRBUF_AUTO_DESTROY key; ffStrbufInit(&key); if(instance->config.disk.key.length == 0) @@ -23,11 +23,11 @@ static void printDisk(FFinstance* instance, const FFDisk* disk) }); } - FFstrbuf usedPretty; + FF_STRBUF_AUTO_DESTROY usedPretty; ffStrbufInit(&usedPretty); ffParseSize(disk->bytesUsed, instance->config.binaryPrefixType, &usedPretty); - FFstrbuf totalPretty; + FF_STRBUF_AUTO_DESTROY totalPretty; ffStrbufInit(&totalPretty); ffParseSize(disk->bytesTotal, instance->config.binaryPrefixType, &totalPretty); @@ -37,7 +37,7 @@ static void printDisk(FFinstance* instance, const FFDisk* disk) { ffPrintLogoAndKey(instance, key.chars, 0, NULL); - FFstrbuf str; + FF_STRBUF_AUTO_DESTROY str; ffStrbufInit(&str); if(disk->bytesTotal > 0) @@ -60,12 +60,11 @@ static void printDisk(FFinstance* instance, const FFDisk* disk) else ffStrbufAppendS(&str, "Unknown "); - if(disk->type == FF_DISK_TYPE_EXTERNAL && !(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) + if(disk->type & FF_DISK_TYPE_EXTERNAL_BIT && !(instance->config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) ffStrbufAppendS(&str, "[Removable]"); ffStrbufTrimRight(&str, ' '); ffStrbufPutTo(&str, stdout); - ffStrbufDestroy(&str); } else { @@ -78,16 +77,12 @@ static void printDisk(FFinstance* instance, const FFDisk* disk) {FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed}, {FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal}, {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_BOOL, FF_FORMAT_ARG_VALUE_BOOL(disk->type & FF_DISK_TYPE_EXTERNAL_BIT)}, + {FF_FORMAT_ARG_TYPE_BOOL, FF_FORMAT_ARG_VALUE_BOOL(disk->type & FF_DISK_TYPE_HIDDEN_BIT)}, {FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem}, {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name} }); } - - ffStrbufDestroy(&totalPretty); - ffStrbufDestroy(&usedPretty); - ffStrbufDestroy(&key); } static void printMountpoint(FFinstance* instance, const FFlist* disks, const char* mountpoint) @@ -113,7 +108,7 @@ static void printMountpoints(FFinstance* instance, const FFlist* disks) const char separator = ':'; #endif - FFstrbuf mountpoints; + FF_STRBUF_AUTO_DESTROY mountpoints; ffStrbufInitCopy(&mountpoints, &instance->config.diskFolders); ffStrbufTrim(&mountpoints, separator); @@ -131,24 +126,19 @@ static void printMountpoints(FFinstance* instance, const FFlist* disks) static void printAutodetected(FFinstance* instance, const FFlist* disks) { - for(uint32_t i = 0; i < disks->length; i++) + bool found = false; + + FF_LIST_FOR_EACH(FFDisk, disk, *disks) { - const FFDisk* disk = ffListGet(disks, i); - - if(disk->type == FF_DISK_TYPE_EXTERNAL && !instance->config.diskShowRemovable) - continue; - - if(disk->type == FF_DISK_TYPE_SUBVOLUME && !instance->config.diskShowSubvolumes) - continue; - - if(disk->type == FF_DISK_TYPE_HIDDEN && !instance->config.diskShowHidden) - continue; - - if(disk->bytesTotal == 0 && !instance->config.diskShowUnknown) + if(!(disk->type & instance->config.diskShowTypes)) continue; printDisk(instance, disk); + found = true; } + + if (!found) + ffPrintError(instance, FF_DISK_MODULE_NAME, 0, &instance->config.disk, "No disk found"); } void ffPrintDisk(FFinstance* instance)