Files
fastfetch/src/detection/disk/disk.c
T
李通洲 f93ffed57a Disk: fix Windows quota affecting free space and unify disk size calculation
- Windows: use FILE_FS_FULL_SIZE_INFORMATION_EX on Windows 10 1809+ (Build >= 17763) when calcType != AVAILABLE to get ActualTotalAllocationUnits/ActualAvailableAllocationUnits (ignoring per-user disk quotas). Fall back to legacy FILE_FS_FULL_SIZE_INFORMATION with CallerAvailableAllocationUnits when calcType is AVAILABLE or EX is unavailable.
- Unix-like: respect --disk-calc-type. Use f_bfree for FREE, f_bavail for AVAILABLE (Linux/BSD/SunOS). Haiku currently always uses free_blocks.
- Refactor FFDisk: remove bytesUsed and bytesAvailable; compute used = total - free in disk module.
- Disk module: update custom format (remove `size-available`, add `bytes-used` and `bytes-total`); update JSON output (remove `bytes.available`, `bytes.used`).
- Disk detection: stop computing used in common path; let each platform set bytesFree by chosen semantics.

Fixes #2651
2026-10-13 15:35:12 +08:00

54 lines
1.6 KiB
C

#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 nullptr;
}
// 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;
}
}
return nullptr;
}
#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