mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Disk (Linux): detect physical type
This commit is contained in:
+29
-2
@@ -6,7 +6,7 @@
|
||||
#include "modules/disk/disk.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#define FF_DISK_NUM_FORMAT_ARGS 10
|
||||
#define FF_DISK_NUM_FORMAT_ARGS 11
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
|
||||
static void printDisk(FFDiskOptions* options, const FFDisk* disk)
|
||||
@@ -111,6 +111,19 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
|
||||
bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
|
||||
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
|
||||
bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT);
|
||||
const char* physicalType;
|
||||
switch(disk->physicalType)
|
||||
{
|
||||
case FF_DISK_PHYSICAL_TYPE_HDD:
|
||||
physicalType = "HDD";
|
||||
break;
|
||||
case FF_DISK_PHYSICAL_TYPE_SSD:
|
||||
physicalType = "SSD";
|
||||
break;
|
||||
default:
|
||||
physicalType = "Unknown";
|
||||
break;
|
||||
}
|
||||
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
|
||||
@@ -123,6 +136,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name},
|
||||
{FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, physicalType}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -403,7 +417,7 @@ void ffGenerateDiskJson(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "mountpoint", &item->mountpoint);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "mountFrom", &item->mountFrom);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "name", &item->name);
|
||||
yyjson_mut_val* typeArr = yyjson_mut_obj_add_arr(doc, obj, "type");
|
||||
yyjson_mut_val* typeArr = yyjson_mut_obj_add_arr(doc, obj, "volumeType");
|
||||
if(item->type & FF_DISK_VOLUME_TYPE_REGULAR_BIT)
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "Regular");
|
||||
if(item->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT)
|
||||
@@ -414,6 +428,19 @@ void ffGenerateDiskJson(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "Hidden");
|
||||
if(item->type & FF_DISK_VOLUME_TYPE_READONLY_BIT)
|
||||
yyjson_mut_arr_add_str(doc, typeArr, "Read-only");
|
||||
|
||||
switch(item->physicalType)
|
||||
{
|
||||
case FF_DISK_PHYSICAL_TYPE_HDD:
|
||||
yyjson_mut_obj_add_str(doc, obj, "physicalType", "HDD");
|
||||
break;
|
||||
case FF_DISK_PHYSICAL_TYPE_SSD:
|
||||
yyjson_mut_obj_add_str(doc, obj, "physicalType", "SSD");
|
||||
break;
|
||||
default:
|
||||
yyjson_mut_obj_add_null(doc, obj, "physicalType");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFDisk, item, disks)
|
||||
|
||||
Reference in New Issue
Block a user