mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Disk: add --disk-show-readonly
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -129,6 +129,7 @@ Module specific options:
|
||||
--disk-show-external <?value>: Set if external volume should be printed. Default is true
|
||||
--disk-show-hidden <?value>: Set if hidden volumes should be printed. Default is false
|
||||
--disk-show-subvolumes <?value>: Set if subvolumes should be printed. Default is false
|
||||
--disk-show-readonly <?value>: Set if read only volumes should be printed. Default is false
|
||||
--disk-show-unknown <?value>: Set if unknown (unable to detect sizes) volumes should be printed. Default is false
|
||||
--disk-use-available <?value>: Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false
|
||||
--bluetooth-show-disconnected: <?value>: Set if disconnected bluetooth devices should be printed. Default is false
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+23
-3
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user