Skip to content

Commit e13f04e

Browse files
committed
Disk: backport changes from config branch
1 parent ad026f6 commit e13f04e

File tree

11 files changed

+66
-73
lines changed

11 files changed

+66
-73
lines changed

src/common/init.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ static void defaultConfig(FFinstance* instance)
157157
instance->config.titleFQDN = false;
158158

159159
ffStrbufInitA(&instance->config.diskFolders, 0);
160-
instance->config.diskShowRemovable = true;
161-
instance->config.diskShowHidden = false;
162-
instance->config.diskShowUnknown = false;
163-
instance->config.diskShowSubvolumes = false;
160+
instance->config.diskShowTypes = FF_DISK_TYPE_REGULAR_BIT | FF_DISK_TYPE_EXTERNAL_BIT;
164161

165162
instance->config.displayCompactType = FF_DISPLAY_COMPACT_TYPE_NONE;
166163
instance->config.displayDetectName = false;

src/data/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Module specific options:
108108
--shell-version <?value>: Set if shell version should be detected and printed
109109
--terminal-version <?value>: Set if terminal version should be detected and printed
110110
--disk-folders <folders>: A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows)
111+
--disk-show-regular <?value>: Set if regular volume should be printed. Default is true
111112
--disk-show-removable <?value>: Set if removable volume should be printed. Default is true
112113
--disk-show-hidden <?value>: Set if hidden volumes should be printed. Default is false
113114
--disk-show-subvolumes <?value>: Set if subvolumes should be printed. Default is false

src/detection/disk/disk.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ const FFDiskResult* ffDetectDisks()
1818

1919
if(result.disks.length == 0 && result.error.length == 0)
2020
ffStrbufAppendS(&result.error, "No disks found");
21-
22-
//We need to sort the disks, so that we can detect, which disk a path resides on
23-
// For example for /boot/efi/bootmgr we need to check /boot/efi before /boot
24-
//Note that we sort alphabetically here for a better ordering when printing the list,
25-
// so the check must be done in reverse order
26-
ffListSort(&result.disks, compareDisks);
21+
else
22+
{
23+
//We need to sort the disks, so that we can detect, which disk a path resides on
24+
// For example for /boot/efi/bootmgr we need to check /boot/efi before /boot
25+
//Note that we sort alphabetically here for a better ordering when printing the list,
26+
// so the check must be done in reverse order
27+
ffListSort(&result.disks, compareDisks);
28+
FF_LIST_FOR_EACH(FFDisk, disk, result.disks)
29+
{
30+
if(disk->bytesTotal == 0)
31+
disk->type |= FF_DISK_TYPE_UNKNOWN_BIT;
32+
}
33+
}
2734
);
2835
}

src/detection/disk/disk.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55

66
#include "fastfetch.h"
77

8-
typedef enum FFDiskType
9-
{
10-
FF_DISK_TYPE_REGULAR,
11-
FF_DISK_TYPE_HIDDEN,
12-
FF_DISK_TYPE_EXTERNAL,
13-
FF_DISK_TYPE_SUBVOLUME
14-
} FFDiskType;
15-
168
typedef struct FFDisk
179
{
1810
FFstrbuf mountpoint;

src/detection/disk/disk_apple.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk)
77
{
88
// FreeBSD doesn't support these flags
99
if(fs->f_flags & MNT_DONTBROWSE)
10-
disk->type = FF_DISK_TYPE_HIDDEN;
10+
disk->type = FF_DISK_TYPE_HIDDEN_BIT;
1111
else if(fs->f_flags & MNT_REMOVABLE)
12-
disk->type = FF_DISK_TYPE_EXTERNAL;
12+
disk->type = FF_DISK_TYPE_EXTERNAL_BIT;
1313
else
14-
disk->type = FF_DISK_TYPE_REGULAR;
14+
disk->type = FF_DISK_TYPE_REGULAR_BIT;
1515

1616
ffStrbufInitS(&disk->name, [NSFileManager.defaultManager displayNameAtPath:@(fs->f_mntonname)].UTF8String);
1717
}

src/detection/disk/disk_bsd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk)
1313
ffStrbufStartsWithS(&disk->mountpoint, "/proc") ||
1414
ffStrbufStartsWithS(&disk->mountpoint, "/zroot")
1515
)
16-
disk->type = FF_DISK_TYPE_HIDDEN;
16+
disk->type = FF_DISK_TYPE_HIDDEN_BIT;
1717
else if((fs->f_flags & MNT_NOSUID) || !(fs->f_flags & MNT_LOCAL))
18-
disk->type = FF_DISK_TYPE_EXTERNAL;
18+
disk->type = FF_DISK_TYPE_EXTERNAL_BIT;
1919
else
20-
disk->type = FF_DISK_TYPE_REGULAR;
20+
disk->type = FF_DISK_TYPE_REGULAR_BIT;
2121

2222
ffStrbufInit(&disk->name);
2323
}

src/detection/disk/disk_linux.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static void detectName(FFDisk* disk, const FFstrbuf* device)
112112
if(stat(device->chars, &deviceStat) != 0)
113113
return;
114114

115-
FFstrbuf basePath;
115+
FF_STRBUF_AUTO_DESTROY basePath;
116116
ffStrbufInit(&basePath);
117117

118118
//Try partlabel first
@@ -129,20 +129,18 @@ static void detectName(FFDisk* disk, const FFstrbuf* device)
129129
//Use the mountpoint as a last resort
130130
if(disk->name.length == 0)
131131
ffStrbufAppend(&disk->name, &disk->mountpoint);
132-
133-
ffStrbufDestroy(&basePath);
134132
}
135133

136134
#ifdef __ANDROID__
137135

138136
static void detectType(FF_MAYBE_UNUSED const FFlist* devices, FFDisk* currentDisk, FF_MAYBE_UNUSED const char* options)
139137
{
140138
if(ffStrbufEqualS(&currentDisk->mountpoint, "/") || ffStrbufEqualS(&currentDisk->mountpoint, "/storage/emulated"))
141-
currentDisk->type = FF_DISK_TYPE_REGULAR;
139+
currentDisk->type = FF_DISK_TYPE_REGULAR_BIT;
142140
else if(ffStrbufStartsWithS(&currentDisk->mountpoint, "/mnt/media_rw/"))
143-
currentDisk->type = FF_DISK_TYPE_EXTERNAL;
141+
currentDisk->type = FF_DISK_TYPE_EXTERNAL_BIT;
144142
else
145-
currentDisk->type = FF_DISK_TYPE_HIDDEN;
143+
currentDisk->type = FF_DISK_TYPE_HIDDEN_BIT;
146144
}
147145

148146
#else
@@ -171,13 +169,13 @@ static bool isSubvolume(const FFlist* devices)
171169
static void detectType(const FFlist* devices, FFDisk* currentDisk, const char* options)
172170
{
173171
if(isSubvolume(devices))
174-
currentDisk->type = FF_DISK_TYPE_SUBVOLUME;
172+
currentDisk->type = FF_DISK_TYPE_SUBVOLUME_BIT;
175173
else if(strstr(options, "nosuid") != NULL || strstr(options, "nodev") != NULL)
176-
currentDisk->type = FF_DISK_TYPE_EXTERNAL;
174+
currentDisk->type = FF_DISK_TYPE_EXTERNAL_BIT;
177175
else if(ffStrbufStartsWithS(&currentDisk->mountpoint, "/boot") || ffStrbufStartsWithS(&currentDisk->mountpoint, "/efi"))
178-
currentDisk->type = FF_DISK_TYPE_HIDDEN;
176+
currentDisk->type = FF_DISK_TYPE_HIDDEN_BIT;
179177
else
180-
currentDisk->type = FF_DISK_TYPE_REGULAR;
178+
currentDisk->type = FF_DISK_TYPE_REGULAR_BIT;
181179
}
182180

183181
#endif
@@ -204,7 +202,7 @@ void ffDetectDisksImpl(FFDiskResult* disks)
204202
return;
205203
}
206204

207-
FFlist devices;
205+
FF_LIST_AUTO_DESTROY devices;
208206
ffListInit(&devices, sizeof(FFstrbuf));
209207

210208
char* line = NULL;
@@ -254,7 +252,6 @@ void ffDetectDisksImpl(FFDiskResult* disks)
254252

255253
FF_LIST_FOR_EACH(FFstrbuf, device, devices)
256254
ffStrbufDestroy(device);
257-
ffListDestroy(&devices);
258255

259256
fclose(mountsFile);
260257
}

src/detection/disk/disk_windows.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ void ffDetectDisksImpl(FFDiskResult* disks)
3333
disk->bytesUsed = disk->bytesTotal - bytesFree;
3434

3535
if(driveType == DRIVE_REMOVABLE || driveType == DRIVE_REMOTE || driveType == DRIVE_CDROM)
36-
disk->type = FF_DISK_TYPE_EXTERNAL;
36+
disk->type = FF_DISK_TYPE_EXTERNAL_BIT;
3737
else if(driveType == DRIVE_FIXED)
38-
disk->type = FF_DISK_TYPE_REGULAR;
38+
disk->type = FF_DISK_TYPE_REGULAR_BIT;
3939
else
40-
disk->type = FF_DISK_TYPE_HIDDEN;
40+
disk->type = FF_DISK_TYPE_HIDDEN_BIT;
4141

4242
ffStrbufInit(&disk->filesystem);
4343
ffStrbufInit(&disk->name);

src/fastfetch.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,14 +1262,16 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
12621262
instance->config.terminalVersion = optionParseBoolean(value);
12631263
else if(strcasecmp(key, "--disk-folders") == 0)
12641264
optionParseString(key, value, &instance->config.diskFolders);
1265+
else if(strcasecmp(key, "--disk-show-regular") == 0)
1266+
optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_REGULAR_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_REGULAR_BIT);
12651267
else if(strcasecmp(key, "--disk-show-removable") == 0)
1266-
instance->config.diskShowRemovable = optionParseBoolean(value);
1268+
optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_EXTERNAL_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_EXTERNAL_BIT);
12671269
else if(strcasecmp(key, "--disk-show-hidden") == 0)
1268-
instance->config.diskShowHidden = optionParseBoolean(value);
1270+
optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_HIDDEN_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_HIDDEN_BIT);
12691271
else if(strcasecmp(key, "--disk-show-subvolumes") == 0)
1270-
instance->config.diskShowSubvolumes = optionParseBoolean(value);
1272+
optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_SUBVOLUME_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_SUBVOLUME_BIT);
12711273
else if(strcasecmp(key, "--disk-show-unknown") == 0)
1272-
instance->config.diskShowUnknown = optionParseBoolean(value);
1274+
optionParseBoolean(value) ? (instance->config.diskShowTypes |= FF_DISK_TYPE_UNKNOWN_BIT) : (instance->config.diskShowTypes &= ~FF_DISK_TYPE_UNKNOWN_BIT);
12731275
else if(strcasecmp(key, "--display-compact-type") == 0)
12741276
{
12751277
optionParseEnum(key, value, &instance->config.displayCompactType,

src/fastfetch.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ typedef enum FFLocalIpCompactType
5555
FF_LOCALIP_COMPACT_TYPE_ONELINE,
5656
} FFLocalIpCompactType;
5757

58+
typedef enum FFDiskType
59+
{
60+
FF_DISK_TYPE_NONE = 0,
61+
FF_DISK_TYPE_REGULAR_BIT = 1 << 0,
62+
FF_DISK_TYPE_HIDDEN_BIT = 1 << 1,
63+
FF_DISK_TYPE_EXTERNAL_BIT = 1 << 2,
64+
FF_DISK_TYPE_SUBVOLUME_BIT = 1 << 3,
65+
FF_DISK_TYPE_UNKNOWN_BIT = 1 << 4,
66+
} FFDiskType;
67+
5868
typedef enum FFBinaryPrefixType
5969
{
6070
FF_BINARY_PREFIX_TYPE_IEC, // 1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)
@@ -217,10 +227,7 @@ typedef struct FFconfig
217227
bool terminalVersion;
218228

219229
FFstrbuf diskFolders;
220-
bool diskShowRemovable;
221-
bool diskShowHidden;
222-
bool diskShowUnknown;
223-
bool diskShowSubvolumes;
230+
FFDiskType diskShowTypes;
224231

225232
FFDisplayCompactType displayCompactType;
226233
bool displayDetectName;

0 commit comments

Comments
 (0)