From a063cd4feb0f3a67a569332cc7b0969920340afc Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 1 Feb 2023 15:56:25 +0100 Subject: [PATCH] Correctly handle zfs pools #413 --- CMakeLists.txt | 1 + src/common/dbus.c | 1 + src/common/format.c | 1 + src/detection/cursor/cursor_linux.c | 1 + src/detection/disk/disk_linux.c | 12 ++++++++ src/detection/displayserver/linux/wmde.c | 1 + src/detection/displayserver/linux/xlib.c | 1 + src/detection/gpu/gpu_linux.c | 1 + src/detection/os/os_linux.c | 1 + .../terminalfont/terminalfont_linux.c | 1 + .../terminalshell/terminalshell_linux.c | 4 +-- src/detection/vulkan.c | 1 + src/detection/wmtheme/wmtheme.h | 2 ++ src/detection/wmtheme/wmtheme_linux.c | 4 +-- src/fastfetch.c | 3 +- src/modules/opencl.c | 1 + src/util/FFstrbuf.c | 11 ------- src/util/FFstrbuf.h | 2 -- src/util/platform/FFPlatform.c | 1 + src/util/platform/FFPlatform_unix.c | 2 +- src/util/stringUtils.c | 29 +++++++++++++++++++ src/util/stringUtils.h | 12 ++++++++ 22 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 src/util/stringUtils.c create mode 100644 src/util/stringUtils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a2e5c3957..fcff26c2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,6 +307,7 @@ set(LIBFASTFETCH_SRC src/util/FFstrbuf.c src/util/FFvaluestore.c src/util/platform/FFPlatform.c + src/util/stringUtils.c ) if(LINUX) diff --git a/src/common/dbus.c b/src/common/dbus.c index 1d2840b2f..f974b39d9 100644 --- a/src/common/dbus.c +++ b/src/common/dbus.c @@ -3,6 +3,7 @@ #ifdef FF_HAVE_DBUS #include "common/thread.h" +#include "util/stringUtils.h" static bool loadLibSymbols(const FFinstance* instance, FFDBusLibrary* lib) { diff --git a/src/common/format.c b/src/common/format.c index 1a4a688c5..7394822f8 100644 --- a/src/common/format.c +++ b/src/common/format.c @@ -2,6 +2,7 @@ #include "common/format.h" #include "common/parsing.h" #include "util/textModifier.h" +#include "util/stringUtils.h" #include diff --git a/src/detection/cursor/cursor_linux.c b/src/detection/cursor/cursor_linux.c index ab7104dea..88366c935 100644 --- a/src/detection/cursor/cursor_linux.c +++ b/src/detection/cursor/cursor_linux.c @@ -5,6 +5,7 @@ #include "common/settings.h" #include "detection/gtk.h" #include "detection/displayserver/displayserver.h" +#include "util/stringUtils.h" #include diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index ec7a26abf..c15eea812 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -1,5 +1,7 @@ #include "disk.h" +#include "util/stringUtils.h" + #include #include #include @@ -19,6 +21,10 @@ static bool isPhysicalDevice(const char* device) if(strcmp(device, "drvfs") == 0) return true; + //ZFS root pool. The format is rpool/// + if(strncmp(device, "rpool/", 6) == 0) + return true; + //Pseudo filesystems don't have a device in /dev const char* devPrefix = "/dev/"; if(strncmp(device, devPrefix, strlen(devPrefix)) != 0) @@ -141,6 +147,7 @@ static bool isSubvolume(const FFlist* devices) { const FFstrbuf* currentDevie = ffListGet(devices, devices->length - 1); + //Filter all disks which device was already found. This catches BTRFS subvolumes. for(uint32_t i = 0; i < devices->length - 1; i++) { const FFstrbuf* otherDevice = ffListGet(devices, i); @@ -149,6 +156,11 @@ static bool isSubvolume(const FFlist* devices) return true; } + //ZFS subvolumes: rpool///. + //Test if the third slash is present. + if(strncmp(currentDevie->chars, "rpool/", 6) == 0 && ffStrHasNChars(currentDevie->chars, '/', 3)) + return true; + return false; } diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index 71b1d1474..3c40b2e11 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -3,6 +3,7 @@ #include "common/properties.h" #include "common/parsing.h" #include "common/processing.h" +#include "util/stringUtils.h" #include #include diff --git a/src/detection/displayserver/linux/xlib.c b/src/detection/displayserver/linux/xlib.c index e6fb8b930..a804dd29a 100644 --- a/src/detection/displayserver/linux/xlib.c +++ b/src/detection/displayserver/linux/xlib.c @@ -3,6 +3,7 @@ #ifdef FF_HAVE_X11 #include "common/library.h" #include "common/parsing.h" +#include "util/stringUtils.h" #include typedef struct X11PropertyData diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index d34807df9..549d8ed40 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -6,6 +6,7 @@ #include "common/properties.h" #include "common/parsing.h" #include "detection/temps/temps_linux.h" +#include "util/stringUtils.h" #include #include #include diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 45a0f5cec..063e8455b 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -1,6 +1,7 @@ #include "os.h" #include "common/properties.h" #include "common/parsing.h" +#include "util/stringUtils.h" #include #include diff --git a/src/detection/terminalfont/terminalfont_linux.c b/src/detection/terminalfont/terminalfont_linux.c index 1d06d09c1..b83724160 100644 --- a/src/detection/terminalfont/terminalfont_linux.c +++ b/src/detection/terminalfont/terminalfont_linux.c @@ -4,6 +4,7 @@ #include "common/parsing.h" #include "detection/terminalshell/terminalshell.h" #include "detection/displayserver/displayserver.h" +#include "util/stringUtils.h" static const char* getSystemMonospaceFont(const FFinstance* instance) { diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 1a2875508..460b98a09 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -1,9 +1,9 @@ -#include "fastfetch.h" +#include "terminalshell.h" #include "common/io/io.h" #include "common/parsing.h" #include "common/processing.h" #include "common/thread.h" -#include "terminalshell.h" +#include "util/stringUtils.h" #include #include diff --git a/src/detection/vulkan.c b/src/detection/vulkan.c index c61e6f8f8..b6ccd0698 100644 --- a/src/detection/vulkan.c +++ b/src/detection/vulkan.c @@ -7,6 +7,7 @@ #include "common/library.h" #include "common/io/io.h" #include "common/parsing.h" +#include "util/stringUtils.h" #include #include diff --git a/src/detection/wmtheme/wmtheme.h b/src/detection/wmtheme/wmtheme.h index e1475006f..33a15dd0f 100644 --- a/src/detection/wmtheme/wmtheme.h +++ b/src/detection/wmtheme/wmtheme.h @@ -3,6 +3,8 @@ #ifndef FASTFETCH_INCLUDED_detection_wmtheme #define FASTFETCH_INCLUDED_detection_wmtheme +#include "fastfetch.h" + bool ffDetectWmTheme(FFinstance* instance, FFstrbuf* themeOrError); #endif diff --git a/src/detection/wmtheme/wmtheme_linux.c b/src/detection/wmtheme/wmtheme_linux.c index 87a8437c1..8d2a079f6 100644 --- a/src/detection/wmtheme/wmtheme_linux.c +++ b/src/detection/wmtheme/wmtheme_linux.c @@ -1,10 +1,10 @@ -#include "fastfetch.h" +#include "wmtheme.h" #include "common/properties.h" #include "common/parsing.h" #include "common/settings.h" #include "detection/gtk.h" #include "detection/displayserver/displayserver.h" -#include "wmtheme.h" +#include "util/stringUtils.h" static bool detectWMThemeFromConfigFile(FFinstance* instance, const char* configFile, const char* themeRegex, const char* defaultValue, FFstrbuf* themeOrError) { diff --git a/src/fastfetch.c b/src/fastfetch.c index ded937466..c107f4768 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1,9 +1,10 @@ #include "fastfetch.h" -#include "util/FFvaluestore.h" #include "common/printing.h" #include "common/parsing.h" #include "common/io/io.h" #include "common/time.h" +#include "util/FFvaluestore.h" +#include "util/stringUtils.h" #include #include diff --git a/src/modules/opencl.c b/src/modules/opencl.c index debfcd45e..18e826317 100644 --- a/src/modules/opencl.c +++ b/src/modules/opencl.c @@ -7,6 +7,7 @@ #if defined(FF_HAVE_OPENCL) || defined(__APPLE__) #include "common/library.h" #include "common/parsing.h" +#include "util/stringUtils.h" #include #define CL_TARGET_OPENCL_VERSION 100 diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 375c53aaa..94f436d51 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -3,17 +3,6 @@ #include #include -bool ffStrSet(const char* str) -{ - if(str == NULL) - return false; - - while(isspace(*str)) - str++; - - return *str != '\0'; -} - static char* CHAR_NULL_PTR = ""; void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate) diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index 7342cb607..7755225a7 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -18,8 +18,6 @@ #define strcasestr StrStrIA #endif -bool ffStrSet(const char* str); - #define FASTFETCH_STRBUF_DEFAULT_ALLOC 32 typedef struct FFstrbuf diff --git a/src/util/platform/FFPlatform.c b/src/util/platform/FFPlatform.c index d549b6501..2a880aed1 100644 --- a/src/util/platform/FFPlatform.c +++ b/src/util/platform/FFPlatform.c @@ -1,4 +1,5 @@ #include "FFPlatform_private.h" +#include "util/stringUtils.h" void ffPlatformInit(FFPlatform* platform) { diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index 65dad8d8b..6d65defcb 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -1,5 +1,5 @@ #include "FFPlatform_private.h" - +#include "util/stringUtils.h" #include "fastfetch_config.h" #include diff --git a/src/util/stringUtils.c b/src/util/stringUtils.c new file mode 100644 index 000000000..703c81a45 --- /dev/null +++ b/src/util/stringUtils.c @@ -0,0 +1,29 @@ +#include "stringUtils.h" + +#include +#include + +bool ffStrSet(const char* str) +{ + if(str == NULL) + return false; + + while(isspace(*str)) + str++; + + return *str != '\0'; +} + +bool ffStrHasNChars(const char* str, char c, uint32_t n) +{ + for(uint32_t i = 0; i < n; i++) + { + char* current = strchr(str, c); + if(current == NULL) + return false; + + str = current + 1; + } + + return true; +} diff --git a/src/util/stringUtils.h b/src/util/stringUtils.h new file mode 100644 index 000000000..7c2475353 --- /dev/null +++ b/src/util/stringUtils.h @@ -0,0 +1,12 @@ +#pragma once + +#ifndef FF_INCLUDED_util_stringUtils_h +#define FF_INCLUDED_util_stringUtils_h + +#include +#include + +bool ffStrSet(const char* str); +bool ffStrHasNChars(const char* str, char c, uint32_t n); + +#endif