PhysicalDisk (macOS): detect read-only

This commit is contained in:
李通洲
2023-12-25 08:55:17 +08:00
parent 350388295d
commit 3b6d5468da
5 changed files with 26 additions and 4 deletions
+18 -2
View File
@@ -63,22 +63,31 @@ void ffPrintPhysicalDisk(FFPhysicalDiskOptions* options)
: dev->type & FF_PHYSICALDISK_TYPE_FIXED
? "Fixed"
: "";
const char* readOnlyType = dev->type & FF_PHYSICALDISK_TYPE_READONLY
? "Read-only"
: "";
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
if (physicalType[0] || removableType[0])
if (physicalType[0] || removableType[0] || readOnlyType[0])
{
ffStrbufAppendS(&buffer, " [");
if (physicalType[0])
ffStrbufAppendS(&buffer, physicalType);
if (removableType[0])
{
if (physicalType[0])
if (buffer.chars[buffer.length - 1] != '[')
ffStrbufAppendS(&buffer, ", ");
ffStrbufAppendS(&buffer, removableType);
}
if (readOnlyType[0])
{
if (buffer.chars[buffer.length - 1] != '[')
ffStrbufAppendS(&buffer, ", ");
ffStrbufAppendS(&buffer, readOnlyType);
}
ffStrbufAppendC(&buffer, ']');
}
ffStrbufPutTo(&buffer, stdout);
@@ -193,6 +202,13 @@ void ffGeneratePhysicalDiskJsonResult(FFPhysicalDiskOptions* options, yyjson_mut
yyjson_mut_obj_add_bool(doc, obj, "removable", false);
else
yyjson_mut_obj_add_null(doc, obj, "removable");
if (dev->type & FF_PHYSICALDISK_TYPE_READONLY)
yyjson_mut_obj_add_bool(doc, obj, "readOnly", true);
else if (dev->type & FF_PHYSICALDISK_TYPE_READWRITE)
yyjson_mut_obj_add_bool(doc, obj, "readOnly", false);
else
yyjson_mut_obj_add_null(doc, obj, "readOnly");
}
FF_LIST_FOR_EACH(FFPhysicalDiskResult, dev, result)