Skip to content

Commit 6319b68

Browse files
committed
PhysicalDisk (FreeBSD): adds type virtual and type unknown detection
1 parent c37ac4d commit 6319b68

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/detection/physicaldisk/physicaldisk_bsd.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
3939
continue;
4040
}
4141

42-
// Should memory disk (MD) be considered as physical disk?
43-
// if (!ffStrEquals(provider->lg_geom->lg_class->lg_name, "DISK"))
44-
// continue;
42+
FFPhysicalDiskType type = FF_PHYSICALDISK_TYPE_NONE;
43+
if (!ffStrEquals(provider->lg_geom->lg_class->lg_name, "DISK")) {
44+
type |= FF_PHYSICALDISK_TYPE_VIRTUAL;
45+
}
46+
uint64_t size = (uint64_t) provider->lg_mediasize;
47+
if (size == 0) {
48+
type |= FF_PHYSICALDISK_TYPE_UNKNOWN;
49+
}
4550

4651
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateS(provider->lg_name);
4752
FF_STRBUF_AUTO_DESTROY identifier = ffStrbufCreate();
48-
FFPhysicalDiskType type = FF_PHYSICALDISK_TYPE_NONE;
4953
for (struct gconfig* ptr = provider->lg_config.lh_first; ptr; ptr = ptr->lg_config.le_next) {
5054
if (ffStrEquals(ptr->lg_name, "descr")) {
5155
ffStrbufSetS(&name, ptr->lg_val);
@@ -72,24 +76,26 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
7276
ffStrbufTrimSpace(&device->serial);
7377
ffStrbufInit(&device->revision);
7478
ffStrbufInit(&device->interconnect);
79+
ffStrbufInitMove(&device->name, &name);
80+
device->size = size;
81+
device->temperature = FF_PHYSICALDISK_TEMP_UNSET;
82+
7583
switch (snapIter->device_type & DEVSTAT_TYPE_IF_MASK) {
7684
case DEVSTAT_TYPE_IF_SCSI:
77-
ffStrbufAppendS(&device->interconnect, "SCSI");
85+
ffStrbufSetStatic(&device->interconnect, "SCSI");
7886
break;
7987
case DEVSTAT_TYPE_IF_IDE:
80-
ffStrbufAppendS(&device->interconnect, "IDE");
88+
ffStrbufSetStatic(&device->interconnect, "IDE");
8189
break;
8290
case DEVSTAT_TYPE_IF_OTHER:
83-
ffStrbufAppendS(&device->interconnect, "OTHER");
91+
ffStrbufSetStatic(&device->interconnect, "OTHER");
8492
break;
8593

8694
// https://github.com/freebsd/freebsd-src/commit/d282baddb0b029ca8466d23ac51e95c918442535
8795
case 0x040 /*DEVSTAT_TYPE_IF_NVME*/:
88-
ffStrbufAppendS(&device->interconnect, "NVMe");
96+
ffStrbufSetStatic(&device->interconnect, "NVMe");
8997
break;
9098
}
91-
device->size = (uint64_t) provider->lg_mediasize;
92-
ffStrbufInitMove(&device->name, &name);
9399

94100
if (!(device->type & FF_PHYSICALDISK_TYPE_READONLY) && !(device->type & FF_PHYSICALDISK_TYPE_READWRITE)) {
95101
int acr = 1, acw = 1; // Number of partitions mounted for reading or writing
@@ -99,7 +105,6 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
99105
}
100106

101107
device->type = type;
102-
device->temperature = FF_PHYSICALDISK_TEMP_UNSET;
103108
}
104109

105110
geom_stats_snapshot_free(snap);

0 commit comments

Comments
 (0)