mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Disk: backport changes from config branch
This commit is contained in:
+1
-4
@@ -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;
|
||||
|
||||
@@ -108,6 +108,7 @@ Module specific options:
|
||||
--shell-version <?value>: Set if shell version should be detected and printed
|
||||
--terminal-version <?value>: Set if terminal version should be detected and printed
|
||||
--disk-folders <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 <?value>: Set if regular volume should be printed. Default is true
|
||||
--disk-show-removable <?value>: Set if removable volume should be printed. Default is true
|
||||
--disk-show-hidden <?value>: Set if hidden volumes should be printed. Default is false
|
||||
--disk-show-subvolumes <?value>: Set if subvolumes should be printed. Default is false
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
+6
-4
@@ -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,
|
||||
|
||||
+11
-4
@@ -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;
|
||||
|
||||
+16
-26
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user