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

36 lines
1.2 KiB
C
Raw Normal View History

2022-10-06 22:56:56 +08:00
#include "disk.h"
2022-10-17 13:19:48 +02:00
#include "detection/internal.h"
2022-10-06 22:56:56 +08:00
2022-10-17 13:19:48 +02:00
void ffDetectDisksImpl(FFDiskResult* disks);
2022-10-06 22:56:56 +08:00
2022-10-17 13:19:48 +02:00
static int compareDisks(const void* disk1, const void* disk2)
2022-10-06 22:56:56 +08:00
{
2022-10-17 13:19:48 +02:00
return ffStrbufCompAlphabetically(&((const FFDisk*) disk1)->mountpoint, &((const FFDisk*) disk2)->mountpoint);
2022-10-06 22:56:56 +08:00
}
2022-10-17 13:19:48 +02:00
const FFDiskResult* ffDetectDisks()
2022-10-06 22:56:56 +08:00
{
2022-10-17 13:19:48 +02:00
FF_DETECTION_INTERNAL_GUARD(FFDiskResult,
ffStrbufInit(&result.error);
ffListInitA(&result.disks, sizeof(FFDisk), 4);
2022-10-06 22:56:56 +08:00
2022-10-17 13:19:48 +02:00
ffDetectDisksImpl(&result);
2022-10-06 22:56:56 +08:00
2022-10-17 13:19:48 +02:00
if(result.disks.length == 0 && result.error.length == 0)
ffStrbufAppendS(&result.error, "No disks found");
2023-06-08 21:34:56 +08:00
else
{
//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(&result.disks, compareDisks);
FF_LIST_FOR_EACH(FFDisk, disk, result.disks)
{
if(disk->bytesTotal == 0)
disk->type |= FF_DISK_TYPE_UNKNOWN_BIT;
}
}
2022-10-17 13:19:48 +02:00
);
2022-10-06 22:56:56 +08:00
}