mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-02 19:31:10 +01:00
PhysicalDisk (macOS): detect read-only
This commit is contained in:
@@ -11,7 +11,8 @@ typedef enum FFPhysicalDiskType
|
||||
FF_PHYSICALDISK_TYPE_FIXED = 1 << 2,
|
||||
FF_PHYSICALDISK_TYPE_REMOVABLE = 1 << 3,
|
||||
|
||||
FF_PHYSICALDISK_TYPE_READONLY = 1 << 2,
|
||||
FF_PHYSICALDISK_TYPE_READWRITE = 1 << 4,
|
||||
FF_PHYSICALDISK_TYPE_READONLY = 1 << 5,
|
||||
} FFPhysicalDiskType;
|
||||
|
||||
typedef struct FFPhysicalDiskResult
|
||||
|
||||
@@ -52,6 +52,9 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
|
||||
FF_CFTYPE_AUTO_RELEASE CFBooleanRef removable = IORegistryEntryCreateCFProperty(entryPartition, CFSTR(kIOMediaRemovableKey), kCFAllocatorDefault, kNilOptions);
|
||||
device->type |= CFBooleanGetValue(removable) ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED;
|
||||
|
||||
FF_CFTYPE_AUTO_RELEASE CFBooleanRef writable = IORegistryEntryCreateCFProperty(entryPartition, CFSTR(kIOMediaWritableKey), kCFAllocatorDefault, kNilOptions);
|
||||
device->type |= CFBooleanGetValue(writable) ? FF_PHYSICALDISK_TYPE_READWRITE : FF_PHYSICALDISK_TYPE_READONLY;
|
||||
|
||||
FF_CFTYPE_AUTO_RELEASE CFStringRef bsdName = IORegistryEntryCreateCFProperty(entryPartition, CFSTR(kIOBSDNameKey), kCFAllocatorDefault, kNilOptions);
|
||||
if (bsdName)
|
||||
{
|
||||
|
||||
@@ -113,7 +113,7 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
|
||||
char roChar = '0';
|
||||
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/ro", devName);
|
||||
if (ffReadFileData(pathSysBlock, 1, &roChar) > 0)
|
||||
device->type |= roChar == '1' ? FF_PHYSICALDISK_TYPE_READONLY : 0;
|
||||
device->type |= roChar == '1' ? FF_PHYSICALDISK_TYPE_READONLY : FF_PHYSICALDISK_TYPE_READWRITE;
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -138,6 +138,8 @@ static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFPhysic
|
||||
__typeof__(gmt.MediaInfo[0].DeviceSpecific.DiskInfo)* diskInfo = &gmt.MediaInfo[0].DeviceSpecific.DiskInfo;
|
||||
if (diskInfo->MediaCharacteristics & MEDIA_READ_ONLY)
|
||||
device->type |= FF_PHYSICALDISK_TYPE_READONLY;
|
||||
else if (diskInfo->MediaCharacteristics & MEDIA_READ_WRITE)
|
||||
device->type |= FF_PHYSICALDISK_TYPE_READWRITE;
|
||||
if (device->size == 0)
|
||||
device->size = (uint64_t) diskInfo->NumberMediaSides * diskInfo->TracksPerCylinder * diskInfo->SectorsPerTrack * diskInfo->BytesPerSector;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user