Skip to content

Commit e356454

Browse files
committed
Zpool: add NetBSD support
Signed-off-by: hoshinomori <hoshinomori@owarisekai.moe>
1 parent e04cc9c commit e356454

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/detection/zpool/zpool_linux.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,53 @@ const char* ffDetectZpool(FFlist* result /* list of FFZpoolResult */)
109109

110110
#else
111111

112+
#include "common/processing.h"
113+
#include "util/path.h"
114+
112115
const char* ffDetectZpool(FF_MAYBE_UNUSED FFlist* result)
113116
{
114-
return "Fastfetch was compiled without libzfs support";
117+
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
118+
const char* error = ffFindExecutableInPath("zpool", &path);
119+
if (error) return "Failed to find zpool executable path";
120+
121+
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreate();
122+
if (ffProcessAppendStdOut(&output, (char* const[]){
123+
path.chars,
124+
"get",
125+
"-Hp",
126+
"health,version,size,allocated,fragmentation",
127+
NULL
128+
}) == NULL)
129+
{
130+
if (output.length == 0)
131+
return NULL;
132+
133+
char* line = NULL;
134+
size_t len = 0;
135+
while (ffStrbufGetline(&line, &len, &output))
136+
{
137+
FFZpoolResult* item = ffListAdd(result);
138+
ffStrbufInitS(&item->name, line);
139+
ffStrbufSubstrBeforeFirstC(&item->name, '\t');
140+
uint32_t startIndex = item->name.length;
141+
ffStrbufInitS(&item->state, line + startIndex + sizeof("health\t"));
142+
ffStrbufSubstrBeforeFirstC(&item->state, '\t');
143+
ffStrbufGetline(&line, &len, &output);
144+
item->version = ffStrbufToUInt(
145+
&(FFstrbuf){.chars = line + startIndex + sizeof("version\t")} , 5000);
146+
ffStrbufGetline(&line, &len, &output);
147+
item->total = ffStrbufToUInt(
148+
&(FFstrbuf){.chars = line + startIndex + sizeof("size\t")}, 0);
149+
ffStrbufGetline(&line, &len, &output);
150+
item->used = ffStrbufToUInt(
151+
&(FFstrbuf){.chars = line + startIndex + sizeof("allocated\t")}, 0);
152+
ffStrbufGetline(&line, &len, &output);
153+
item->fragmentation = ffStrbufToDouble(
154+
&(FFstrbuf){.chars = line + startIndex + sizeof("fragmentation\t")}, -DBL_MAX);
155+
}
156+
return NULL;
157+
}
158+
return "Failed to run zpool get -Hp health,version,size,allocated,fragmentation";
115159
}
116160

117161
#endif

0 commit comments

Comments
 (0)