2022-10-06 22:56:56 +08:00
|
|
|
#include "disk.h"
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) {
|
2024-02-22 10:38:33 +08:00
|
|
|
return ffStrbufComp(&disk1->mountpoint, &disk2->mountpoint);
|
2022-10-06 22:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks) {
|
2024-04-30 15:12:49 +08:00
|
|
|
const char* error = ffDetectDisksImpl(options, disks);
|
2022-10-06 22:56:56 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
if (disks->length == 0) {
|
2026-07-10 18:08:04 +08:00
|
|
|
return nullptr;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2022-10-06 22:56:56 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
// 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
|
2026-04-14 10:41:18 +08:00
|
|
|
ffListSort(disks, sizeof(FFDisk), (void*) compareDisks);
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_LIST_FOR_EACH (FFDisk, disk, *disks) {
|
|
|
|
|
if (disk->bytesTotal == 0) {
|
2023-08-26 09:32:19 +08:00
|
|
|
disk->type |= FF_DISK_VOLUME_TYPE_UNKNOWN_BIT;
|
2023-08-26 10:36:00 +08:00
|
|
|
}
|
2023-06-12 22:09:52 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 18:08:04 +08:00
|
|
|
return nullptr;
|
2022-10-06 22:56:56 +08:00
|
|
|
}
|
2025-11-06 13:39:30 +08:00
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2026-04-15 16:16:46 +08:00
|
|
|
#include <fnmatch.h>
|
2025-11-06 13:39:30 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
bool ffDiskMatchesFolderPatterns(FFstrbuf* folders, const char* path, char separator) {
|
2025-11-06 13:39:30 +08:00
|
|
|
uint32_t startIndex = 0;
|
2026-03-29 09:28:49 +08:00
|
|
|
while (startIndex < folders->length) {
|
2025-11-06 13:39:30 +08:00
|
|
|
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;
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (matched) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-11-06 13:39:30 +08:00
|
|
|
|
|
|
|
|
startIndex = sepIndex + 1;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|