From: dongshengyuan <545258830@qq.com> Date: Thu, 16 Jul 2026 06:39:42 +0000 (+0800) Subject: dissect: include image size in JSON output X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dab2a82a30355c8f1fc51c6655bdc2c5f5844755;p=thirdparty%2Fsystemd.git dissect: include image size in JSON output Use the image metadata size when building JSON output, matching the value already shown by the text output. Reproducer: systemd-dissect --json=short image.raw Before: text output showed Size, but JSON omitted the top-level size field. Follow-up: be5bee2a132d2d3b45d79bb3f27b05bbc767cd0a --- diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index 602306d9b9a..c5b56b44d6a 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -890,7 +890,6 @@ static int action_dissect( _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_(table_unrefp) Table *t = NULL; _cleanup_free_ char *bn = NULL; - uint64_t size = UINT64_MAX; int r; assert(m); @@ -1009,7 +1008,7 @@ static int action_dissect( r = sd_json_buildo( &v, SD_JSON_BUILD_PAIR_STRING("name", bn), - SD_JSON_BUILD_PAIR_CONDITION(size != UINT64_MAX, "size", SD_JSON_BUILD_INTEGER(size)), + SD_JSON_BUILD_PAIR_CONDITION(m->image_size != UINT64_MAX, "size", SD_JSON_BUILD_INTEGER(m->image_size)), SD_JSON_BUILD_PAIR_INTEGER("sectorSize", m->sector_size), SD_JSON_BUILD_PAIR_CONDITION(a >= 0, "architecture", SD_JSON_BUILD_STRING(architecture_to_string(a))), SD_JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(m->image_uuid), "imageUuid", SD_JSON_BUILD_UUID(m->image_uuid)), diff --git a/test/units/TEST-50-DISSECT.dissect.sh b/test/units/TEST-50-DISSECT.dissect.sh index 9fc15d04da7..5a56da55f79 100755 --- a/test/units/TEST-50-DISSECT.dissect.sh +++ b/test/units/TEST-50-DISSECT.dissect.sh @@ -19,6 +19,7 @@ fi systemd-dissect --json=short "$MINIMAL_IMAGE.raw" | \ grep -F '{"rw":"ro","designator":"root","partition_uuid":null,"partition_label":null,"fstype":"squashfs","architecture":null,"verity":"external"' >/dev/null +systemd-dissect --json=short "$MINIMAL_IMAGE.raw" | grep -F '"size":' >/dev/null systemd-dissect "$MINIMAL_IMAGE.raw" | grep -F "MARKER=1" >/dev/null # shellcheck disable=SC2153 systemd-dissect "$MINIMAL_IMAGE.raw" | grep -F -f <(sed 's/"//g' "$OS_RELEASE") >/dev/null