From a71f2142bb6db68503bbddacc3cb7c1a0b0b1bb3 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 20 Jan 2023 13:28:25 +0100 Subject: [PATCH] Disk(Linux): Better subvolume detection #396 --- src/detection/disk/disk_linux.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 1907657d7..8d7fd1ee3 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -29,17 +29,18 @@ static void strbufAppendMountPoint(FFstrbuf* mountpoint, const char* source) } #ifndef __ANDROID__ -static bool isSubvolume(const char* options) +static bool isSubvolume(const FFlist* allDisks, const FFDisk* currentDisk) { - const char* prefix = "subvol=/@"; //Btrfs subvolume - const char* subvolume = strstr(options, prefix); - if(subvolume == NULL) - return false; + FF_LIST_FOR_EACH(FFDisk, disk, *allDisks) + { + if(disk == currentDisk) + continue; - subvolume += strlen(prefix); + if(ffStrbufEqual(&disk->mountpoint, ¤tDisk->mountpoint)) + return true; + } - //If there is no space or comma after the @, it is a btrfs subvolume - return *subvolume != ' ' && *subvolume != ','; + return false; } #endif @@ -104,7 +105,7 @@ void ffDetectDisksImpl(FFDiskResult* disks) else disk->type = FF_DISK_TYPE_HIDDEN; #else - if(isSubvolume(currentPos)) + if(isSubvolume(&disks->disks, disk)) disk->type = FF_DISK_TYPE_SUBVOLUME; else if(strstr(currentPos, "nosuid") != NULL || strstr(currentPos, "nodev") != NULL) disk->type = FF_DISK_TYPE_EXTERNAL;