]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: show intended architecture of a disk image
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Mar 2023 15:09:57 +0000 (16:09 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Mar 2023 16:08:28 +0000 (17:08 +0100)
We already determine the architecture of disk images and make a choice,
and store it per partition. Let's make this accessible globally.

src/dissect/dissect.c
src/shared/dissect-image.c
src/shared/dissect-image.h

index a6a5b9e2108a44a19df56338620d955121dfb59d..f08e745a554a87328cd473f8eca2f5488b3467a2 100644 (file)
@@ -603,6 +603,9 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
 
         printf(" Sec. Size: %" PRIu32 "\n", m->sector_size);
 
+        printf("     Arch.: %s\n",
+               strna(architecture_to_string(dissected_image_architecture(m))));
+
         if (arg_json_format_flags & JSON_FORMAT_OFF)
                 putc('\n', stdout);
 
index b20e21cce2d84b0a95d9471f4dcdeab216e06e5e..9636fd8d48a2490d5959cae64a864aabdad75979 100644 (file)
@@ -3156,6 +3156,20 @@ finish:
         return r;
 }
 
+Architecture dissected_image_architecture(DissectedImage *img) {
+        assert(img);
+
+        if (img->partitions[PARTITION_ROOT].found &&
+            img->partitions[PARTITION_ROOT].architecture >= 0)
+                return img->partitions[PARTITION_ROOT].architecture;
+
+        if (img->partitions[PARTITION_USR].found &&
+            img->partitions[PARTITION_USR].architecture >= 0)
+                return img->partitions[PARTITION_USR].architecture;
+
+        return _ARCHITECTURE_INVALID;
+}
+
 int dissect_loop_device(
                 LoopDevice *loop,
                 const VeritySettings *verity,
index 3efe784ee90a281f86941293f602d8c3ab5af7c4..6b90895216cbaca34846eb4339d2dea67046cb6b 100644 (file)
@@ -160,6 +160,8 @@ int dissected_image_mount_and_warn(DissectedImage *m, const char *where, uid_t u
 
 int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_flags);
 
+Architecture dissected_image_architecture(DissectedImage *m);
+
 DecryptedImage* decrypted_image_ref(DecryptedImage *p);
 DecryptedImage* decrypted_image_unref(DecryptedImage *p);
 DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref);