geom_part: Restore the human readable format of size

Prior to the change 4f809ffec69c, the sizes are formated by
humanize_number(3) with the flag HN_DECIMAL, which displays the result
using one decimal place when it is less than 10. That is more accurate
and useful. Add equivalent field modifier hn-decimal to xo_emit() to
restore the previous behavior.

Reported by:	Mark Millard
Reviewed by:	js
Fixes:		4f809ffec69c gpart: add libxo support for "show" subcommand + man page updates
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D56514

(cherry picked from commit 0d16792c6e983005581ed0176ed81e7302582196)
This commit is contained in:
Zhenlei Huang 2026-04-21 00:59:59 +08:00
parent d11419ed37
commit d2bf940ec1

View file

@ -653,7 +653,7 @@ gpart_show_geom(struct ggeom *gp, const char *element, int show_providers)
secsz = pp->lg_sectorsize;
xo_open_instance("part");
xo_emit("=>{t:start/%*jd} {t:sectors/%*jd} "
"{t:name/%*s} {:scheme} ({h:size/%jd})"
"{t:name/%*s} {:scheme} ({h,hn-decimal:size/%jd})"
"{t:state}\n",
wblocks, (intmax_t)first, wblocks, (intmax_t)(last - first + 1),
wname, gp->lg_name, scheme, (intmax_t)pp->lg_mediasize,
@ -675,7 +675,7 @@ gpart_show_geom(struct ggeom *gp, const char *element, int show_providers)
xo_emit(" {t:start/%*jd} "
"{t:sectors/%*jd} "
"{P:/%*s} "
"{ne:free}- free - ({h:size/%jd})\n",
"{ne:free}- free - ({h,hn-decimal:size/%jd})\n",
wblocks, (intmax_t)first,
wblocks, (intmax_t)(sector - first),
wname, "",
@ -723,7 +723,7 @@ gpart_show_geom(struct ggeom *gp, const char *element, int show_providers)
}
if (idx)
xo_emit("]");
xo_emit(" ({h:size/%jd})\n", (intmax_t)pp->lg_mediasize);
xo_emit(" ({h,hn-decimal:size/%jd})\n", (intmax_t)pp->lg_mediasize);
xo_close_instance(s);
first = end + 1;
}
@ -732,7 +732,7 @@ gpart_show_geom(struct ggeom *gp, const char *element, int show_providers)
xo_open_instance("unallocated");
length = last - first + 1;
xo_emit(" {t:start/%*jd} {t:sectors/%*jd} "
"{P:/%*s} {ne:free}- free - ({h:size/%jd})\n",
"{P:/%*s} {ne:free}- free - ({h,hn-decimal:size/%jd})\n",
wblocks, (intmax_t)first, wblocks, (intmax_t)length,
wname, "", "true", (intmax_t)length * secsz);
xo_close_instance("unallocated");