Skip to content

Commit 8eb8f71

Browse files
committed
Disk: add option --disk-hidden-folders
1 parent 526868e commit 8eb8f71

File tree

9 files changed

+37
-10
lines changed

9 files changed

+37
-10
lines changed

src/detection/disk/disk.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "disk.h"
22

3-
bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint)
3+
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint)
44
{
55
#ifdef _WIN32
66
const char separator = ';';
@@ -11,12 +11,12 @@ bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint)
1111
uint32_t mountpointLength = (uint32_t) strlen(mountpoint);
1212

1313
uint32_t startIndex = 0;
14-
while(startIndex < options->folders.length)
14+
while(startIndex < folders->length)
1515
{
16-
uint32_t colonIndex = ffStrbufNextIndexC(&options->folders, startIndex, separator);
16+
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator);
1717

1818
uint32_t folderLength = colonIndex - startIndex;
19-
if (folderLength == mountpointLength && memcmp(options->folders.chars + startIndex, mountpoint, mountpointLength) == 0)
19+
if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0)
2020
return true;
2121

2222
startIndex = colonIndex + 1;
@@ -54,5 +54,14 @@ const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
5454
}
5555
}
5656

57+
if (options->hiddenFolders.length)
58+
{
59+
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
60+
{
61+
if (ffDiskMatchMountpoint(&options->hiddenFolders, disk->mountpoint.chars))
62+
disk->type |= FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
63+
}
64+
}
65+
5766
return NULL;
5867
}

src/detection/disk/disk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ typedef struct FFDisk
2828
const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks /* list of FFDisk */);
2929

3030
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks);
31-
bool ffDiskMatchMountpoint(FFDiskOptions* options, const char* mountpoint);
31+
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint);

src/detection/disk/disk_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
145145
{
146146
if(__builtin_expect(options->folders.length > 0, 0))
147147
{
148-
if(!ffDiskMatchMountpoint(options, fs->f_mntonname))
148+
if(!ffDiskMatchMountpoint(&options->folders, fs->f_mntonname))
149149
continue;
150150
}
151151
else if(!ffStrEquals(fs->f_mntonname, "/") && !ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs"))

src/detection/disk/disk_haiku.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
2323

2424
if (__builtin_expect(options->folders.length, 0))
2525
{
26-
if (!ffDiskMatchMountpoint(options, path.Path()))
26+
if (!ffDiskMatchMountpoint(&options->folders, path.Path()))
2727
continue;
2828
}
2929

src/detection/disk/disk_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
281281
{
282282
if (__builtin_expect(options->folders.length, 0))
283283
{
284-
if (!ffDiskMatchMountpoint(options, device->mnt_dir))
284+
if (!ffDiskMatchMountpoint(&options->folders, device->mnt_dir))
285285
continue;
286286
}
287287
else if(!isPhysicalDevice(device))

src/detection/disk/disk_sunos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
113113
{
114114
if (__builtin_expect(options->folders.length, 0))
115115
{
116-
if (!ffDiskMatchMountpoint(options, device.mnt_mountp))
116+
if (!ffDiskMatchMountpoint(&options->folders, device.mnt_mountp))
117117
continue;
118118
}
119119
else if(!isPhysicalDevice(&device))

src/detection/disk/disk_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
4747

4848
if (__builtin_expect((long) options->folders.length, 0))
4949
{
50-
if (!ffDiskMatchMountpoint(options, buffer.chars))
50+
if (!ffDiskMatchMountpoint(&options->folders, buffer.chars))
5151
continue;
5252
}
5353
else if(driveType == DRIVE_NO_ROOT_DIR)

src/modules/disk/disk.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch
205205
return true;
206206
}
207207

208+
if (ffStrEqualsIgnCase(subKey, "hidden-folders"))
209+
{
210+
ffOptionParseString(key, value, &options->hiddenFolders);
211+
return true;
212+
}
213+
208214
if (ffStrEqualsIgnCase(subKey, "show-regular"))
209215
{
210216
if (ffOptionParseBoolean(value))
@@ -293,6 +299,12 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
293299
continue;
294300
}
295301

302+
if (ffStrEqualsIgnCase(key, "hiddenFolders"))
303+
{
304+
ffStrbufSetS(&options->hiddenFolders, yyjson_get_str(val));
305+
continue;
306+
}
307+
296308
if (ffStrEqualsIgnCase(key, "showExternal"))
297309
{
298310
if (yyjson_get_bool(val))
@@ -496,6 +508,11 @@ void ffInitDiskOptions(FFDiskOptions* options)
496508
ffOptionInitModuleArg(&options->moduleArgs, "");
497509

498510
ffStrbufInit(&options->folders);
511+
#if _WIN32 || __APPLE__ || __ANDROID__
512+
ffStrbufInit(&options->hiddenFolders);
513+
#else
514+
ffStrbufInitStatic(&options->hiddenFolders, "/efi:/boot:/boot/efi");
515+
#endif
499516
options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT;
500517
options->calcType = FF_DISK_CALC_TYPE_FREE;
501518
options->percent = (FFPercentageModuleConfig) { 50, 80, 0 };

src/modules/disk/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef struct FFDiskOptions
2929
FFModuleArgs moduleArgs;
3030

3131
FFstrbuf folders;
32+
FFstrbuf hiddenFolders;
3233
FFDiskVolumeType showTypes;
3334
FFDiskCalcType calcType;
3435
FFPercentageModuleConfig percent;

0 commit comments

Comments
 (0)