Files
fastfetch/src/detection/disk/disk.c
T

59 lines
1.7 KiB
C
Raw Normal View History

2022-10-06 22:56:56 +08:00
#include "disk.h"
2025-05-19 16:42:11 +08:00
bool ffDiskMatchMountpoint(FFstrbuf* folders, const char* mountpoint)
{
#ifdef _WIN32
const char separator = ';';
#else
const char separator = ':';
#endif
uint32_t mountpointLength = (uint32_t) strlen(mountpoint);
uint32_t startIndex = 0;
2025-05-19 16:42:11 +08:00
while(startIndex < folders->length)
{
2025-05-19 16:42:11 +08:00
uint32_t colonIndex = ffStrbufNextIndexC(folders, startIndex, separator);
uint32_t folderLength = colonIndex - startIndex;
2025-05-19 16:42:11 +08:00
if (folderLength == mountpointLength && memcmp(folders->chars + startIndex, mountpoint, mountpointLength) == 0)
return true;
startIndex = colonIndex + 1;
}
return false;
}
2022-10-06 22:56:56 +08:00
2024-02-22 10:38:33 +08:00
static int compareDisks(const FFDisk* disk1, const FFDisk* disk2)
2022-10-06 22:56:56 +08:00
{
2024-02-22 10:38:33 +08:00
return ffStrbufComp(&disk1->mountpoint, &disk2->mountpoint);
2022-10-06 22:56:56 +08:00
}
2023-08-26 10:36:00 +08:00
const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks)
2022-10-06 22:56:56 +08:00
{
const char* error = ffDetectDisksImpl(options, disks);
2022-10-06 22:56:56 +08:00
2023-06-12 22:09:52 +08:00
if (error) return error;
if (disks->length == 0) return "No disks found";
2022-10-06 22:56:56 +08:00
2023-06-12 22:09:52 +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
2024-02-22 10:38:33 +08:00
ffListSort(disks, (void*) compareDisks);
2023-06-12 22:09:52 +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
else
{
disk->bytesUsed = disk->bytesTotal - (
options->calcType == FF_DISK_CALC_TYPE_FREE ? disk->bytesFree : disk->bytesAvailable
);
}
2023-06-12 22:09:52 +08:00
}
return NULL;
2022-10-06 22:56:56 +08:00
}