]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: include image size in JSON output
authordongshengyuan <545258830@qq.com>
Thu, 16 Jul 2026 06:39:42 +0000 (14:39 +0800)
committerdongshengyuan <545258830@qq.com>
Sat, 18 Jul 2026 07:53:00 +0000 (15:53 +0800)
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

src/dissect/dissect.c
test/units/TEST-50-DISSECT.dissect.sh

index 602306d9b9a8501db4a1cc22b9a6533e25658bd4..c5b56b44d6aeb4cd4b43ed19b09fe95d77ac73a6 100644 (file)
@@ -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)),
index 9fc15d04da7647d89f313d595e3f9152974a7a9a..5a56da55f79d91e023f36b539c5c24c52f820a44 100755 (executable)
@@ -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