From 57a4b9b6ed7ed7668af307c13046041b03ab2ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 19 Sep 2025 14:54:13 +0800 Subject: [PATCH] Disk: refactors mountpoint matching to use shared string utilities --- src/detection/disk/disk.c | 19 ------------------- src/detection/disk/disk.h | 1 - src/detection/disk/disk_bsd.c | 2 +- src/detection/disk/disk_haiku.cpp | 2 +- src/detection/disk/disk_linux.c | 2 +- src/detection/disk/disk_sunos.c | 2 +- src/detection/disk/disk_windows.c | 2 +- src/modules/disk/disk.c | 4 ++-- 8 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index 5b17dc0c3..5d52b86e7 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -1,24 +1,5 @@ #include "disk.h" -bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint) -{ - uint32_t mountpointLength = (uint32_t) strlen(mountpoint); - - uint32_t startIndex = 0; - while(startIndex < folders->length) - { - uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, FF_DISK_FOLDER_SEPARATOR); - - uint32_t folderLength = colonIndex - startIndex; - if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0) - return true; - - startIndex = colonIndex + 1; - } - - return false; -} - static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) { return ffStrbufComp(&disk1->mountpoint, &disk2->mountpoint); diff --git a/src/detection/disk/disk.h b/src/detection/disk/disk.h index ba8ead2fa..f2fab8782 100644 --- a/src/detection/disk/disk.h +++ b/src/detection/disk/disk.h @@ -35,4 +35,3 @@ typedef struct FFDisk const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks /* list of FFDisk */); const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks); -bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint); diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 6a4860283..13597fb96 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -145,7 +145,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { if(__builtin_expect(options->folders.length > 0, 0)) { - if(!ffDiskMatchMountpoint(&options->folders, fs->f_mntonname)) + if(!ffStrbufSeparatedContainS(&options->folders, fs->f_mntonname, FF_DISK_FOLDER_SEPARATOR)) continue; } else if(!ffStrEquals(fs->f_mntonname, "/") && !ffStrStartsWith(fs->f_mntfromname, "/dev/") && !ffStrEquals(fs->f_fstypename, "zfs") && !ffStrEquals(fs->f_fstypename, "fusefs.sshfs")) diff --git a/src/detection/disk/disk_haiku.cpp b/src/detection/disk/disk_haiku.cpp index 6bf216922..25fe018b9 100644 --- a/src/detection/disk/disk_haiku.cpp +++ b/src/detection/disk/disk_haiku.cpp @@ -23,7 +23,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) if (__builtin_expect(options->folders.length, 0)) { - if (!ffDiskMatchMountpoint(&options->folders, path.Path())) + if (!ffStrbufSeparatedContainS(&options->folders, path.Path(), FF_DISK_FOLDER_SEPARATOR)) continue; } diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index d90012601..8cb9130e9 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -291,7 +291,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { if (__builtin_expect(options->folders.length > 0, false)) { - if (!ffDiskMatchMountpoint(&options->folders, device->mnt_dir)) + if (!ffStrbufSeparatedContainS(&options->folders, device->mnt_dir, FF_DISK_FOLDER_SEPARATOR)) continue; } else if(!isPhysicalDevice(device)) diff --git a/src/detection/disk/disk_sunos.c b/src/detection/disk/disk_sunos.c index d52a5e907..8272cc1ed 100644 --- a/src/detection/disk/disk_sunos.c +++ b/src/detection/disk/disk_sunos.c @@ -113,7 +113,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { if (__builtin_expect(options->folders.length, 0)) { - if (!ffDiskMatchMountpoint(&options->folders, device.mnt_mountp)) + if (!ffStrbufSeparatedContainS(&options->folders, device.mnt_mountp, FF_DISK_FOLDER_SEPARATOR)) continue; } else if(!isPhysicalDevice(&device)) diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index 092a247c3..ea6766b45 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -47,7 +47,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) if (__builtin_expect((long) options->folders.length, 0)) { - if (!ffDiskMatchMountpoint(&options->folders, buffer.chars)) + if (!ffStrbufSeparatedContain(&options->folders, &buffer, FF_DISK_FOLDER_SEPARATOR)) continue; } else if(driveType == DRIVE_NO_ROOT_DIR) diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index c9d8fc4e6..d33cf3d6f 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -203,10 +203,10 @@ bool ffPrintDisk(FFDiskOptions* options) if(__builtin_expect(options->folders.length == 0, 1) && (disk->type & ~options->showTypes)) continue; - if (options->hideFolders.length && ffDiskMatchMountpoint(&options->hideFolders, disk->mountpoint.chars)) + if (options->hideFolders.length && ffStrbufSeparatedContain(&options->hideFolders, &disk->mountpoint, FF_DISK_FOLDER_SEPARATOR)) continue; - if (options->hideFS.length && ffStrbufMatchSeparated(&disk->filesystem, &options->hideFS, ':')) + if (options->hideFS.length && ffStrbufSeparatedContain(&options->hideFS, &disk->filesystem, ':')) continue; printDisk(options, disk, ++index);