Skip to content

Commit 32d6436

Browse files
committed
Disk: add --disk-show-readonly
1 parent 7358326 commit 32d6436

File tree

7 files changed

+40
-4
lines changed

7 files changed

+40
-4
lines changed

doc/json_schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,11 @@
884884
"title": "Set if subvolumes should be printed",
885885
"default": false
886886
},
887+
"showReadOnly": {
888+
"type": "boolean",
889+
"title": "Set if read only volumes should be printed",
890+
"default": false
891+
},
887892
"showUnknown": {
888893
"type": "boolean",
889894
"title": "Set if unknown (unable to detect sizes) volumes should be printed",

src/data/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Module specific options:
129129
--disk-show-external <?value>: Set if external volume should be printed. Default is true
130130
--disk-show-hidden <?value>: Set if hidden volumes should be printed. Default is false
131131
--disk-show-subvolumes <?value>: Set if subvolumes should be printed. Default is false
132+
--disk-show-readonly <?value>: Set if read only volumes should be printed. Default is false
132133
--disk-show-unknown <?value>: Set if unknown (unable to detect sizes) volumes should be printed. Default is false
133134
--disk-use-available <?value>: Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false
134135
--bluetooth-show-disconnected: <?value>: Set if disconnected bluetooth devices should be printed. Default is false

src/detection/disk/disk_bsd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const char* ffDetectDisksImpl(FFlist* disks)
5555
ffStrbufInitS(&disk->mountpoint, fs->f_mntonname);
5656
ffStrbufInitS(&disk->filesystem, fs->f_fstypename);
5757
detectFsInfo(fs, disk);
58+
59+
if(fs->f_flags & MNT_EXRDONLY)
60+
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
5861
}
5962

6063
return NULL;

src/detection/disk/disk_linux.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ static void detectStats(FFDisk* disk)
215215

216216
disk->filesTotal = (uint32_t) fs.f_files;
217217
disk->filesUsed = (uint32_t) (disk->filesTotal - fs.f_ffree);
218+
219+
if(fs.f_flag & ST_RDONLY)
220+
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
218221
}
219222

220223
const char* ffDetectDisksImpl(FFlist* disks)

src/detection/disk/disk_windows.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ const char* ffDetectDisksImpl(FFlist* disks)
5252
//https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getvolumeinformationa#remarks
5353
UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
5454

55+
DWORD diskFlags;
5556
BOOL result = GetVolumeInformationW(mountpoint,
5657
diskName, sizeof(diskName) / sizeof(*diskName), //Volume name
5758
NULL, //Serial number
5859
NULL, //Max component length
59-
NULL, //File system flags
60+
&diskFlags, //File system flags
6061
diskFileSystem, sizeof(diskFileSystem) / sizeof(*diskFileSystem)
6162
);
6263
SetErrorMode(errorMode);
@@ -65,6 +66,8 @@ const char* ffDetectDisksImpl(FFlist* disks)
6566
{
6667
ffStrbufSetWS(&disk->filesystem, diskFileSystem);
6768
ffStrbufSetWS(&disk->name, diskName);
69+
if(diskFlags & FILE_READ_ONLY_VOLUME)
70+
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
6871
}
6972

7073
//Unsupported

src/modules/disk/disk.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
100100

101101
bool isExternal = !!(disk->type & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT);
102102
bool isHidden = !!(disk->type & FF_DISK_VOLUME_TYPE_HIDDEN_BIT);
103+
bool isReadOnly = !!(disk->type & FF_DISK_VOLUME_TYPE_READONLY_BIT);
103104
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
104105
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
105106
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
@@ -110,7 +111,8 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk)
110111
{FF_FORMAT_ARG_TYPE_BOOL, &isExternal},
111112
{FF_FORMAT_ARG_TYPE_BOOL, &isHidden},
112113
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},
113-
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name}
114+
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->name},
115+
{FF_FORMAT_ARG_TYPE_BOOL, &isReadOnly},
114116
});
115117
}
116118
}
@@ -156,7 +158,7 @@ static void printAutodetected(FFDiskOptions* options, const FFlist* disks)
156158
{
157159
FF_LIST_FOR_EACH(FFDisk, disk, *disks)
158160
{
159-
if(!(disk->type & options->showTypes))
161+
if(disk->type & ~options->showTypes)
160162
continue;
161163

162164
printDisk(options, disk);
@@ -194,7 +196,7 @@ void ffInitDiskOptions(FFDiskOptions* options)
194196
ffOptionInitModuleArg(&options->moduleArgs);
195197

196198
ffStrbufInit(&options->folders);
197-
options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
199+
options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT;
198200
options->calcType = FF_DISK_CALC_TYPE_FREE;
199201
}
200202

@@ -247,6 +249,15 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch
247249
return true;
248250
}
249251

252+
if (ffStrEqualsIgnCase(subKey, "show-readonly"))
253+
{
254+
if (ffOptionParseBoolean(value))
255+
options->showTypes |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
256+
else
257+
options->showTypes &= ~FF_DISK_VOLUME_TYPE_READONLY_BIT;
258+
return true;
259+
}
260+
250261
if (ffStrEqualsIgnCase(subKey, "show-unknown"))
251262
{
252263
if (ffOptionParseBoolean(value))
@@ -319,6 +330,15 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module)
319330
continue;
320331
}
321332

333+
if (ffStrEqualsIgnCase(key, "showReadOnly"))
334+
{
335+
if (yyjson_get_bool(val))
336+
options->showTypes |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
337+
else
338+
options->showTypes &= ~FF_DISK_VOLUME_TYPE_READONLY_BIT;
339+
continue;
340+
}
341+
322342
if (ffStrEqualsIgnCase(key, "showUnknown"))
323343
{
324344
if (yyjson_get_bool(val))

src/modules/disk/option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ typedef enum FFDiskVolumeType
1212
FF_DISK_VOLUME_TYPE_EXTERNAL_BIT = 1 << 2,
1313
FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT = 1 << 3,
1414
FF_DISK_VOLUME_TYPE_UNKNOWN_BIT = 1 << 4,
15+
FF_DISK_VOLUME_TYPE_READONLY_BIT = 1 << 5,
1516
} FFDiskVolumeType;
1617

1718
typedef enum FFDiskCalcType

0 commit comments

Comments
 (0)