Files
fastfetch/src/detection/disk/disk_haiku.cpp
T

75 lines
2.5 KiB
C++
Raw Normal View History

2026-03-29 09:28:49 +08:00
extern "C" {
2025-02-12 00:17:18 +08:00
#include "disk.h"
2026-05-28 15:58:08 +08:00
#include "common/strutil.h"
2025-02-12 00:17:18 +08:00
}
#include <fs_info.h>
#include <Directory.h>
#include <Path.h>
2026-03-29 09:28:49 +08:00
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) {
2025-02-15 01:47:18 +01:00
int32 pos = 0;
2025-02-12 00:17:18 +08:00
2026-03-29 09:28:49 +08:00
for (dev_t dev; (dev = next_dev(&pos)) >= B_OK;) {
2025-02-12 00:17:18 +08:00
fs_info fs;
2026-03-29 09:28:49 +08:00
if (fs_stat_dev(dev, &fs) < 0) {
continue;
}
node_ref node(fs.dev, fs.root);
BDirectory dir(&node);
BPath path(&dir);
2026-03-29 09:28:49 +08:00
if (path.InitCheck() != B_OK) {
continue;
}
2026-03-29 09:28:49 +08:00
if (__builtin_expect(options->folders.length, 0)) {
if (!ffStrbufSeparatedContainS(&options->folders, path.Path(), FF_DISK_FOLDER_SEPARATOR)) {
continue;
2026-03-29 09:28:49 +08:00
}
}
2025-02-12 00:17:18 +08:00
2026-03-29 09:28:49 +08:00
if (options->hideFolders.length && ffDiskMatchesFolderPatterns(&options->hideFolders, path.Path(), FF_DISK_FOLDER_SEPARATOR)) {
continue;
2026-03-29 09:28:49 +08:00
}
2026-03-29 09:28:49 +08:00
if (options->hideFS.length && ffStrbufSeparatedContainS(&options->hideFS, fs.fsh_name, ':')) {
continue;
2026-03-29 09:28:49 +08:00
}
2026-04-14 10:41:18 +08:00
FFDisk* disk = FF_LIST_ADD(FFDisk, *disks);
2025-02-12 00:17:18 +08:00
2026-03-29 09:28:49 +08:00
disk->bytesTotal = (uint64_t) fs.total_blocks * (uint64_t) fs.block_size;
disk->bytesFree = (uint64_t) fs.free_blocks * (uint64_t) fs.block_size;
2025-02-12 00:17:18 +08:00
disk->bytesAvailable = disk->bytesFree;
2025-03-26 14:42:55 +08:00
disk->bytesUsed = 0; // To be filled in ./disk.c
2025-02-12 00:17:18 +08:00
disk->filesTotal = (uint32_t) fs.total_nodes;
2025-03-26 14:42:55 +08:00
disk->filesUsed = (uint32_t) (fs.total_nodes - fs.free_nodes);
2025-02-12 00:17:18 +08:00
ffStrbufInitS(&disk->mountFrom, fs.device_name);
ffStrbufInitS(&disk->mountpoint, path.Path());
2025-02-12 00:17:18 +08:00
ffStrbufInitS(&disk->filesystem, fs.fsh_name);
ffStrbufInitS(&disk->name, fs.volume_name);
disk->type = FF_DISK_VOLUME_TYPE_NONE;
2026-03-29 09:28:49 +08:00
if (!(fs.flags & B_FS_IS_PERSISTENT)) {
2025-02-12 00:17:18 +08:00
disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
2026-03-29 09:28:49 +08:00
}
if (fs.flags & B_FS_IS_READONLY) {
2025-02-12 00:17:18 +08:00
disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_READONLY_BIT);
2026-03-29 09:28:49 +08:00
}
if (fs.flags & B_FS_IS_REMOVABLE) {
2025-02-12 00:17:18 +08:00
disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
2026-03-29 09:28:49 +08:00
}
if (disk->type == FF_DISK_VOLUME_TYPE_NONE) {
disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
}
2025-02-12 00:17:18 +08:00
disk->createTime = 0;
time_t crTime;
2026-03-29 09:28:49 +08:00
if (dir.GetCreationTime(&crTime) == B_OK) {
disk->createTime = (uint64_t) crTime * 1000;
2026-03-29 09:28:49 +08:00
}
2025-02-12 00:17:18 +08:00
}
return NULL;
2025-02-12 00:17:18 +08:00
}