44#include "common/size.h"
55#include "detection/zpool/zpool.h"
66#include "modules/zpool/zpool.h"
7+ #include "util/FFstrbuf.h"
78#include "util/stringUtils.h"
89
910static void printZpool (FFZpoolOptions * options , FFZpoolResult * result , uint8_t index )
@@ -22,17 +23,22 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i
2223 FF_PARSE_FORMAT_STRING_CHECKED (& buffer , & options -> moduleArgs .key , ((FFformatarg []) {
2324 FF_FORMAT_ARG (index , "index" ),
2425 FF_FORMAT_ARG (result -> name , "name" ),
26+ FF_FORMAT_ARG (result -> guid , "guid" ),
2527 FF_FORMAT_ARG (options -> moduleArgs .keyIcon , "icon" ),
2628 }));
2729 }
2830
2931 FF_STRBUF_AUTO_DESTROY usedPretty = ffStrbufCreate ();
3032 ffSizeAppendNum (result -> used , & usedPretty );
3133
34+ FF_STRBUF_AUTO_DESTROY allocatedPretty = ffStrbufCreate ();
35+ ffSizeAppendNum (result -> allocated , & allocatedPretty );
36+
3237 FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate ();
3338 ffSizeAppendNum (result -> total , & totalPretty );
3439
35- double bytesPercentage = result -> total > 0 ? (double ) result -> used / (double ) result -> total * 100.0 : 0 ;
40+ double usedPercentage = result -> total > 0 ? (double ) result -> used / (double ) result -> total * 100.0 : 0 ;
41+ double allocatedPercentage = result -> total > 0 ? (double ) result -> allocated / (double ) result -> total * 100.0 : 0 ;
3642 FFPercentageTypeFlags percentType = options -> percent .type == 0 ? instance .config .display .percentType : options -> percent .type ;
3743
3844 if (options -> moduleArgs .outputFormat .length == 0 )
@@ -41,20 +47,31 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i
4147
4248 ffStrbufClear (& buffer );
4349 ffStrbufSetF (& buffer , "%s / %s (" , usedPretty .chars , totalPretty .chars );
44- ffPercentAppendNum (& buffer , bytesPercentage , options -> percent , false, & options -> moduleArgs );
50+ ffPercentAppendNum (& buffer , usedPercentage , options -> percent , false, & options -> moduleArgs );
4551 ffStrbufAppendS (& buffer , ", " );
52+ ffPercentAppendNum (& buffer , allocatedPercentage , options -> percent , false, & options -> moduleArgs );
53+ ffStrbufAppendS (& buffer , " allocated, " );
4654 ffPercentAppendNum (& buffer , result -> fragmentation , options -> percent , false, & options -> moduleArgs );
4755 ffStrbufAppendF (& buffer , " frag) - %s" , result -> state .chars );
56+ if (result -> readOnly )
57+ ffStrbufAppendS (& buffer , " [Read-only]" );
4858 ffStrbufPutTo (& buffer , stdout );
4959 }
5060 else
5161 {
52- FF_STRBUF_AUTO_DESTROY bytesPercentageNum = ffStrbufCreate ();
62+ FF_STRBUF_AUTO_DESTROY usedPercentageNum = ffStrbufCreate ();
63+ if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT )
64+ ffPercentAppendNum (& usedPercentageNum , usedPercentage , options -> percent , false, & options -> moduleArgs );
65+ FF_STRBUF_AUTO_DESTROY usedPercentageBar = ffStrbufCreate ();
66+ if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT )
67+ ffPercentAppendBar (& usedPercentageBar , usedPercentage , options -> percent , & options -> moduleArgs );
68+
69+ FF_STRBUF_AUTO_DESTROY allocatedPercentageNum = ffStrbufCreate ();
5370 if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT )
54- ffPercentAppendNum (& bytesPercentageNum , bytesPercentage , options -> percent , false, & options -> moduleArgs );
55- FF_STRBUF_AUTO_DESTROY bytesPercentageBar = ffStrbufCreate ();
71+ ffPercentAppendNum (& allocatedPercentageNum , allocatedPercentage , options -> percent , false, & options -> moduleArgs );
72+ FF_STRBUF_AUTO_DESTROY allocatedPercentageBar = ffStrbufCreate ();
5673 if (percentType & FF_PERCENTAGE_TYPE_BAR_BIT )
57- ffPercentAppendBar (& bytesPercentageBar , bytesPercentage , options -> percent , & options -> moduleArgs );
74+ ffPercentAppendBar (& allocatedPercentageBar , allocatedPercentage , options -> percent , & options -> moduleArgs );
5875
5976 FF_STRBUF_AUTO_DESTROY fragPercentageNum = ffStrbufCreate ();
6077 if (percentType & FF_PERCENTAGE_TYPE_NUM_BIT )
@@ -65,13 +82,18 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i
6582
6683 FF_PRINT_FORMAT_CHECKED (buffer .chars , 0 , & options -> moduleArgs , FF_PRINT_TYPE_NO_CUSTOM_KEY , ((FFformatarg []) {
6784 FF_FORMAT_ARG (result -> name , "name" ),
85+ FF_FORMAT_ARG (result -> guid , "guid" ),
6886 FF_FORMAT_ARG (result -> state , "state" ),
6987 FF_FORMAT_ARG (usedPretty , "size-used" ),
88+ FF_FORMAT_ARG (allocatedPretty , "size-allocated" ),
7089 FF_FORMAT_ARG (totalPretty , "size-total" ),
71- FF_FORMAT_ARG (bytesPercentageNum , "size-percentage" ),
90+ FF_FORMAT_ARG (usedPercentageNum , "used-percentage" ),
91+ FF_FORMAT_ARG (allocatedPercentageNum , "allocated-percentage" ),
7292 FF_FORMAT_ARG (fragPercentageNum , "frag-percentage" ),
73- FF_FORMAT_ARG (bytesPercentageBar , "size-percentage-bar" ),
93+ FF_FORMAT_ARG (usedPercentageBar , "used-percentage-bar" ),
94+ FF_FORMAT_ARG (allocatedPercentageBar , "allocated-percentage-bar" ),
7495 FF_FORMAT_ARG (fragPercentageBar , "frag-percentage-bar" ),
96+ FF_FORMAT_ARG (result -> readOnly , "is-readonly" ),
7597 }));
7698 }
7799}
@@ -149,13 +171,15 @@ bool ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_m
149171 yyjson_mut_val * obj = yyjson_mut_arr_add_obj (doc , arr );
150172 yyjson_mut_obj_add_strbuf (doc , obj , "name" , & zpool -> name );
151173 yyjson_mut_obj_add_strbuf (doc , obj , "state" , & zpool -> state );
174+ yyjson_mut_obj_add_uint (doc , obj , "guid" , zpool -> guid );
152175 yyjson_mut_obj_add_uint (doc , obj , "used" , zpool -> used );
176+ yyjson_mut_obj_add_uint (doc , obj , "allocated" , zpool -> allocated );
153177 yyjson_mut_obj_add_uint (doc , obj , "total" , zpool -> total );
154- yyjson_mut_obj_add_uint (doc , obj , "version" , zpool -> version );
155178 if (zpool -> fragmentation != - DBL_MAX )
156179 yyjson_mut_obj_add_real (doc , obj , "fragmentation" , zpool -> fragmentation );
157180 else
158181 yyjson_mut_obj_add_null (doc , obj , "fragmentation" );
182+ yyjson_mut_obj_add_bool (doc , obj , "readOnly" , zpool -> readOnly );
159183 }
160184
161185 FF_LIST_FOR_EACH (FFZpoolResult , zpool , results )
@@ -188,12 +212,16 @@ FFModuleBaseInfo ffZpoolModuleInfo = {
188212 .generateJsonConfig = (void * ) ffGenerateZpoolJsonConfig ,
189213 .formatArgs = FF_FORMAT_ARG_LIST (((FFModuleFormatArg []) {
190214 {"Zpool name" , "name" },
215+ {"Zpool guid" , "guid" },
191216 {"Zpool state" , "state" },
192217 {"Size used" , "used" },
218+ {"Size allocated" , "allocated" },
193219 {"Size total" , "total" },
194- {"Size percentage num" , "used-percentage" },
220+ {"Size used percentage num" , "used-percentage" },
221+ {"Size allocated percentage num" , "allocated-percentage" },
195222 {"Fragmentation percentage num" , "fragmentation-percentage" },
196- {"Size percentage bar" , "used-percentage-bar" },
223+ {"Size used percentage bar" , "used-percentage-bar" },
224+ {"Size allocated percentage bar" , "allocated-percentage-bar" },
197225 {"Fragmentation percentage bar" , "fragmentation-percentage-bar" },
198226 }))
199227};
0 commit comments