master ohmu/fastfetch-openbsd / src / detection / disk / disk_haiku.cpp
ohmu  ·  2026-10-15
 1extern "C" {
 2#include "disk.h"
 3#include "common/strutil.h"
 4}
 5#include <fs_info.h>
 6#include <Directory.h>
 7#include <Path.h>
 8
 9const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) {
10    int32 pos = 0;
11
12    for (dev_t dev; (dev = next_dev(&pos)) >= B_OK;) {
13        fs_info fs;
14        if (fs_stat_dev(dev, &fs) < 0) {
15            continue;
16        }
17
18        if (!ffStrSet(fs.device_name)) {
19            continue;
20        }
21
22        node_ref node(fs.dev, fs.root);
23        BDirectory dir(&node);
24        BPath path(&dir);
25        if (path.InitCheck() != B_OK) {
26            continue;
27        }
28
29        if (__builtin_expect(options->folders.length, 0)) {
30            if (!ffStrbufSeparatedContainS(&options->folders, path.Path(), FF_DISK_FOLDER_SEPARATOR)) {
31                continue;
32            }
33        }
34
35        if (options->hideFolders.length && ffDiskMatchesFolderPatterns(&options->hideFolders, path.Path(), FF_DISK_FOLDER_SEPARATOR)) {
36            continue;
37        }
38
39        if (options->hideFS.length && ffStrbufSeparatedContainS(&options->hideFS, fs.fsh_name, ':')) {
40            continue;
41        }
42
43        FFDisk* disk = FF_LIST_ADD(FFDisk, *disks);
44
45        disk->bytesTotal = (uint64_t) fs.total_blocks * (uint64_t) fs.block_size;
46        disk->bytesFree = (uint64_t) fs.free_blocks * (uint64_t) fs.block_size;
47
48        disk->filesTotal = (uint32_t) fs.total_nodes;
49        disk->filesUsed = (uint32_t) (fs.total_nodes - fs.free_nodes);
50
51        ffStrbufInitS(&disk->mountFrom, fs.device_name);
52        ffStrbufInitS(&disk->mountpoint, path.Path());
53        ffStrbufInitS(&disk->filesystem, fs.fsh_name);
54        ffStrbufInitS(&disk->name, fs.volume_name);
55        disk->type = FF_DISK_VOLUME_TYPE_NONE;
56        if (!(fs.flags & B_FS_IS_PERSISTENT)) {
57            disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
58        }
59        if (fs.flags & B_FS_IS_READONLY) {
60            disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_READONLY_BIT);
61        }
62        if (fs.flags & B_FS_IS_REMOVABLE) {
63            disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
64        }
65        if (disk->type == FF_DISK_VOLUME_TYPE_NONE) {
66            disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
67        }
68        disk->createTime = 0;
69
70        time_t crTime;
71        if (dir.GetCreationTime(&crTime) == B_OK) {
72            disk->createTime = (uint64_t) crTime * 1000;
73        }
74    }
75    return nullptr;
76}