PhysicalDisk (Linux): detect readonly

This commit is contained in:
李通洲
2023-12-24 22:34:45 +08:00
parent b5a01400e9
commit 02999ae4bf
2 changed files with 9 additions and 0 deletions
@@ -10,6 +10,8 @@ typedef enum FFPhysicalDiskType
FF_PHYSICALDISK_TYPE_FIXED = 1 << 2,
FF_PHYSICALDISK_TYPE_REMOVABLE = 1 << 3,
FF_PHYSICALDISK_TYPE_READONLY = 1 << 2,
} FFPhysicalDiskType;
typedef struct FFPhysicalDiskResult
@@ -109,6 +109,13 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options)
device->type |= removableChar == '1' ? FF_PHYSICALDISK_TYPE_REMOVABLE : FF_PHYSICALDISK_TYPE_FIXED;
}
{
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;
}
{
ffStrbufInit(&device->serial);
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/serial", devName);