diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/disk/disk.c | |
Add the files
Diffstat (limited to 'src/detection/disk/disk.c')
| -rw-r--r-- | src/detection/disk/disk.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c new file mode 100644 index 0000000..c86282d --- /dev/null +++ b/src/detection/disk/disk.c @@ -0,0 +1,55 @@ +#include "disk.h" + +static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) { + return ffStrbufComp(&disk1->mountpoint, &disk2->mountpoint); +} + +const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks) { + const char* error = ffDetectDisksImpl(options, disks); + + if (error) { + return error; + } + if (disks->length == 0) { + return NULL; + } + + // We need to sort the disks, so that we can detect, which disk a path resides on + // For example for /boot/efi/bootmgr we need to check /boot/efi before /boot + // Note that we sort alphabetically here for a better ordering when printing the list, + // so the check must be done in reverse order + ffListSort(disks, sizeof(FFDisk), (void*) compareDisks); + FF_LIST_FOR_EACH (FFDisk, disk, *disks) { + if (disk->bytesTotal == 0) { + disk->type |= FF_DISK_VOLUME_TYPE_UNKNOWN_BIT; + } else { + disk->bytesUsed = disk->bytesTotal - (options->calcType == FF_DISK_CALC_TYPE_FREE ? disk->bytesFree : disk->bytesAvailable); + } + } + + return NULL; +} + +#ifndef _WIN32 + #include <fnmatch.h> + +bool ffDiskMatchesFolderPatterns(FFstrbuf* folders, const char* path, char separator) { + uint32_t startIndex = 0; + while (startIndex < folders->length) { + uint32_t sepIndex = ffStrbufNextIndexC(folders, startIndex, separator); + + char savedSep = folders->chars[sepIndex]; // Can be '\0' if at end + folders->chars[sepIndex] = '\0'; + + bool matched = fnmatch(&folders->chars[startIndex], path, 0) == 0; + folders->chars[sepIndex] = savedSep; + + if (matched) { + return true; + } + + startIndex = sepIndex + 1; + } + return false; +} +#endif |