diff --git a/doc/json_schema.json b/doc/json_schema.json index be2334b2e..60c3c5259 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -884,6 +884,11 @@ "title": "Set if subvolumes should be printed", "default": false }, + "showReadOnly": { + "type": "boolean", + "title": "Set if read only volumes should be printed", + "default": false + }, "showUnknown": { "type": "boolean", "title": "Set if unknown (unable to detect sizes) volumes should be printed", diff --git a/src/data/help.txt b/src/data/help.txt index 6c484d29f..eb975f786 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -129,6 +129,7 @@ Module specific options: --disk-show-external : Set if external volume should be printed. Default is true --disk-show-hidden : Set if hidden volumes should be printed. Default is false --disk-show-subvolumes : Set if subvolumes should be printed. Default is false + --disk-show-readonly : Set if read only volumes should be printed. Default is false --disk-show-unknown : Set if unknown (unable to detect sizes) volumes should be printed. Default is false --disk-use-available : Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false --bluetooth-show-disconnected: : Set if disconnected bluetooth devices should be printed. Default is false diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index 89d66b4ad..04168484b 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -55,6 +55,9 @@ const char* ffDetectDisksImpl(FFlist* disks) ffStrbufInitS(&disk->mountpoint, fs->f_mntonname); ffStrbufInitS(&disk->filesystem, fs->f_fstypename); detectFsInfo(fs, disk); + + if(fs->f_flags & MNT_EXRDONLY) + disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; } return NULL; diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 1f0f6acd3..fb5597baa 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -215,6 +215,9 @@ static void detectStats(FFDisk* disk) disk->filesTotal = (uint32_t) fs.f_files; disk->filesUsed = (uint32_t) (disk->filesTotal - fs.f_ffree); + + if(fs.f_flag & ST_RDONLY) + disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; } const char* ffDetectDisksImpl(FFlist* disks) diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index 291d59ba6..5b3b39232 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -52,11 +52,12 @@ const char* ffDetectDisksImpl(FFlist* disks) //https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa#remarks UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS); + DWORD diskFlags; BOOL result = GetVolumeInformationW(mountpoint, diskName, sizeof(diskName) / sizeof(*diskName), //Volume name NULL, //Serial number NULL, //Max component length - NULL, //File system flags + &diskFlags, //File system flags diskFileSystem, sizeof(diskFileSystem) / sizeof(*diskFileSystem) ); SetErrorMode(errorMode); @@ -65,6 +66,8 @@ const char* ffDetectDisksImpl(FFlist* disks) { ffStrbufSetWS(&disk->filesystem, diskFileSystem); ffStrbufSetWS(&disk->name, diskName); + if(diskFlags & FILE_READ_ONLY_VOLUME) + disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT; } //Unsupported diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 724061176..7d8460163 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -100,6 +100,7 @@ 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); 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}, @@ -110,7 +111,8 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) {FF_FORMAT_ARG_TYPE_BOOL, &isExternal}, {FF_FORMAT_ARG_TYPE_BOOL, &isHidden}, {FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem}, - {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name} + {FF_FORMAT_ARG_TYPE_STRBUF, &disk->name}, + {FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly}, }); } } @@ -156,7 +158,7 @@ static void printAutodetected(FFDiskOptions* options, const FFlist* disks) { FF_LIST_FOR_EACH(FFDisk, disk, *disks) { - if(!(disk->type & options->showTypes)) + if(disk->type & ~options->showTypes) continue; printDisk(options, disk); @@ -194,7 +196,7 @@ void ffInitDiskOptions(FFDiskOptions* options) ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->folders); - options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT; + options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; options->calcType = FF_DISK_CALC_TYPE_FREE; } @@ -247,6 +249,15 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch return true; } + if (ffStrEqualsIgnCase(subKey, "show-readonly")) + { + if (ffOptionParseBoolean(value)) + options->showTypes |= FF_DISK_VOLUME_TYPE_READONLY_BIT; + else + options->showTypes &= ~FF_DISK_VOLUME_TYPE_READONLY_BIT; + return true; + } + if (ffStrEqualsIgnCase(subKey, "show-unknown")) { if (ffOptionParseBoolean(value)) @@ -319,6 +330,15 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "showReadOnly")) + { + if (yyjson_get_bool(val)) + options->showTypes |= FF_DISK_VOLUME_TYPE_READONLY_BIT; + else + options->showTypes &= ~FF_DISK_VOLUME_TYPE_READONLY_BIT; + continue; + } + if (ffStrEqualsIgnCase(key, "showUnknown")) { if (yyjson_get_bool(val)) diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index f24090c34..9b727e542 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -12,6 +12,7 @@ typedef enum FFDiskVolumeType FF_DISK_VOLUME_TYPE_EXTERNAL_BIT = 1 << 2, FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT = 1 << 3, FF_DISK_VOLUME_TYPE_UNKNOWN_BIT = 1 << 4, + FF_DISK_VOLUME_TYPE_READONLY_BIT = 1 << 5, } FFDiskVolumeType; typedef enum FFDiskCalcType