Skip to content

Commit 01d3765

Browse files
committed
Disk (Haiku): code cleanup; honor option->folders
1 parent f5dbbb7 commit 01d3765

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/detection/disk/disk_haiku.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
extern "C"
22
{
33
#include "disk.h"
4+
#include "util/stringUtils.h"
45
}
56
#include <fs_info.h>
67
#include <Directory.h>
78
#include <Path.h>
89

9-
const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_UNUSED FFlist* disks)
10+
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
1011
{
1112
int32 pos = 0;
1213

1314
for (dev_t dev; (dev = next_dev(&pos)) >= B_OK;)
1415
{
1516
fs_info fs;
16-
fs_stat_dev(dev, &fs);
17+
if (fs_stat_dev(dev, &fs) < -1) continue;
18+
19+
if (!ffStrStartsWith(fs.device_name, "/dev/")) continue; // physical disks only
20+
21+
node_ref node(fs.dev, fs.root);
22+
BDirectory dir(&node);
23+
BPath path(&dir);
24+
if (path.InitCheck() != B_OK) continue;
25+
26+
if (__builtin_expect(options->folders.length, 0))
27+
{
28+
if (!ffDiskMatchMountpoint(options, path.Path()))
29+
continue;
30+
}
1731

1832
FFDisk* disk = (FFDisk*) ffListAdd(disks);
1933

@@ -26,16 +40,7 @@ const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_U
2640
disk->filesUsed = (uint32_t) (disk->filesTotal - (uint64_t)fs.free_nodes);
2741

2842
ffStrbufInitS(&disk->mountFrom, fs.device_name);
29-
ffStrbufInit(&disk->mountpoint);
30-
{
31-
node_ref node(fs.dev, fs.root);
32-
BDirectory dir(&node);
33-
BPath path(&dir);
34-
if (path.InitCheck() == B_OK)
35-
ffStrbufSetS(&disk->mountpoint, path.Path());
36-
else
37-
ffStrbufSetStatic(&disk->mountpoint, "?");
38-
}
43+
ffStrbufInitS(&disk->mountpoint, path.Path());
3944
ffStrbufInitS(&disk->filesystem, fs.fsh_name);
4045
ffStrbufInitS(&disk->name, fs.volume_name);
4146
disk->type = FF_DISK_VOLUME_TYPE_NONE;
@@ -45,7 +50,12 @@ const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FF_MAYBE_U
4550
disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_READONLY_BIT);
4651
if (fs.flags & B_FS_IS_REMOVABLE)
4752
disk->type = (FFDiskVolumeType) (disk->type | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
53+
if (disk->type == FF_DISK_VOLUME_TYPE_NONE) disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
4854
disk->createTime = 0;
55+
56+
time_t crTime;
57+
if (dir.GetCreationTime(&crTime) == B_OK)
58+
disk->createTime = (uint64_t) crTime * 1000;
4959
}
50-
return 0;
60+
return NULL;
5161
}

0 commit comments

Comments
 (0)