From 78c6d7104999fe79222513c30adae249668360f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 11 Oct 2025 16:19:11 +0800 Subject: [PATCH] Disk (Linux): adds glob pattern matching for hidden disk folders Fixes #1999 --- src/modules/disk/disk.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index d33cf3d6f..c9995db4f 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -5,7 +5,10 @@ #include "common/time.h" #include "detection/disk/disk.h" #include "modules/disk/disk.h" -#include "util/stringUtils.h" + +#ifndef _WIN32 + #include +#endif #pragma GCC diagnostic ignored "-Wsign-conversion" @@ -186,6 +189,30 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk, uint32_t index } } +static inline bool isMatchFolders(FFstrbuf* folders, const FFstrbuf* path, char separator) +{ + #ifndef _WIN32 + uint32_t startIndex = 0; + while(startIndex < folders->length) + { + uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator); + + char savedColon = folders->chars[colonIndex]; // Can be '\0' if at end + folders->chars[colonIndex] = '\0'; + + bool matched = fnmatch(&folders->chars[startIndex], path->chars, 0) == 0; + folders->chars[colonIndex] = savedColon; + + if (matched) return true; + + startIndex = colonIndex + 1; + } + return false; + #else + return ffStrbufSeparatedContain(folders, path, separator); + #endif +} + bool ffPrintDisk(FFDiskOptions* options) { FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk)); @@ -203,8 +230,11 @@ bool ffPrintDisk(FFDiskOptions* options) if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes)) continue; - if (options->hideFolders.length && ffStrbufSeparatedContain(&options->hideFolders, &disk->mountpoint, FF_DISK_FOLDER_SEPARATOR)) - continue; + if (options->hideFolders.length) + { + if (isMatchFolders(&options->hideFolders, &disk->mountpoint, FF_DISK_FOLDER_SEPARATOR)) + continue; + } if (options->hideFS.length && ffStrbufSeparatedContain(&options->hideFS, &disk->filesystem, ':')) continue; @@ -452,7 +482,7 @@ void ffInitDiskOptions(FFDiskOptions* options) #if _WIN32 || __APPLE__ || __ANDROID__ ffStrbufInit(&options->hideFolders); #else - ffStrbufInitStatic(&options->hideFolders, "/efi:/boot:/boot/efi:/boot/firmware"); + ffStrbufInitS(&options->hideFolders, "/efi:/boot:/boot/efi:/boot/firmware"); #endif ffStrbufInit(&options->hideFS); options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT;