diff --git a/CHANGELOG.md b/CHANGELOG.md index 17f58128a..5408b652c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Features: * Better max CPU frequency detection support with `CPUID / 16H` instruction (CPU, Windows) * This requires Core I Gen 6 or newer, and with `Virtual Machine Platform` Windows feature disabled. X86 only. * Improve performance of nix packages detection (Packages, Linux) +* Add option `--disk-ignore-remote` to ignore remote disks to improve performance (Disk, Windows) # 2.10.2 diff --git a/doc/json_schema.json b/doc/json_schema.json index 5804b2292..a7d338dca 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1265,6 +1265,11 @@ "description": "Set if unknown (unable to detect sizes) volumes should be printed", "default": false }, + "ignoreRemote": { + "type": "boolean", + "description": "Set if remote volumes should be ignored when detecting for performance reasons. Windows only", + "default": false + }, "useAvailable": { "type": "boolean", "description": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", diff --git a/src/data/help.json b/src/data/help.json index f7cdfb2ec..9f1cb52a5 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1007,6 +1007,16 @@ "default": false } }, + { + "long": "disk-ignore-remote", + "desc": "Set if remote volumes should be ignored when detecting for performance reasons", + "remark": "Windows only", + "arg": { + "type": "bool", + "optional": true, + "default": false + } + }, { "long": "disk-use-available", "desc": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", diff --git a/src/detection/disk/disk.c b/src/detection/disk/disk.c index e712a9c12..17dd553b1 100644 --- a/src/detection/disk/disk.c +++ b/src/detection/disk/disk.c @@ -1,6 +1,6 @@ #include "disk.h" -const char* ffDetectDisksImpl(FFlist* disks); +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks); static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) { @@ -9,7 +9,7 @@ static int compareDisks(const FFDisk* disk1, const FFDisk* disk2) const char* ffDetectDisks(FFDiskOptions* options, FFlist* disks) { - const char* error = ffDetectDisksImpl(disks); + const char* error = ffDetectDisksImpl(options, disks); if (error) return error; if (disks->length == 0) return "No disks found"; diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index c6f9a1c82..227800db1 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -90,7 +90,7 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk) } #endif -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FFlist* disks) { int size = getfsstat(NULL, 0, MNT_WAIT); diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index 31715e6d5..41701ce7e 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -250,7 +250,7 @@ static void detectStats(FFDisk* disk) #endif } -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FF_MAYBE_UNUSED FFDiskOptions* options, FFlist* disks) { FILE* mountsFile = setmntent("/proc/mounts", "r"); if(mountsFile == NULL) diff --git a/src/detection/disk/disk_windows.c b/src/detection/disk/disk_windows.c index ef5329e50..3aada23c7 100644 --- a/src/detection/disk/disk_windows.c +++ b/src/detection/disk/disk_windows.c @@ -6,7 +6,7 @@ #include #include -const char* ffDetectDisksImpl(FFlist* disks) +const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { wchar_t buf[MAX_PATH + 1]; uint32_t length = GetLogicalDriveStringsW(sizeof(buf) / sizeof(*buf), buf); @@ -18,7 +18,7 @@ const char* ffDetectDisksImpl(FFlist* disks) wchar_t* mountpoint = buf + i; UINT driveType = GetDriveTypeW(mountpoint); - if(driveType == DRIVE_NO_ROOT_DIR) + if(driveType == DRIVE_NO_ROOT_DIR || (driveType == DRIVE_REMOTE && options->ignoreRemote)) { i += (uint32_t)wcslen(mountpoint); continue; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 364d5bf2d..52719ece0 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -281,6 +281,12 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch return true; } + if (ffStrEqualsIgnCase(subKey, "ignore-remote")) + { + options->ignoreRemote = ffOptionParseBoolean(value); + return true; + } + if (ffPercentParseCommandOptions(key, subKey, value, &options->percent)) return true; @@ -351,6 +357,12 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "ignoreRemote")) + { + options->ignoreRemote = yyjson_get_bool(val); + continue; + } + if (ffStrEqualsIgnCase(key, "useAvailable")) { if (yyjson_get_bool(val)) @@ -398,6 +410,9 @@ void ffGenerateDiskJsonConfig(FFDiskOptions* options, yyjson_mut_doc* doc, yyjso if (defaultOptions.calcType != options->calcType) yyjson_mut_obj_add_bool(doc, module, "useAvailable", options->calcType == FF_DISK_CALC_TYPE_AVAILABLE); + if (defaultOptions.ignoreRemote != options->ignoreRemote) + yyjson_mut_obj_add_bool(doc, module, "ignoreRemote", options->ignoreRemote); + ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent); } diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index 7c2abdcaa..e1fef2e6b 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -31,4 +31,5 @@ typedef struct FFDiskOptions FFDiskVolumeType showTypes; FFDiskCalcType calcType; FFColorRangeConfig percent; + bool ignoreRemote; } FFDiskOptions;