]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: move helpers for categorizing DDIs into generic code 29525/head
authorLennart Poettering <lennart@poettering.net>
Tue, 10 Oct 2023 21:09:45 +0000 (23:09 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Oct 2023 13:56:08 +0000 (15:56 +0200)
These tests are already done at two places, let's unify them in one
place, and tweak them slightly (specifically: require for considering a
DDI bootable in UEFI we also need need an init system inside).

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

index a03f9a64db87fa2ac30bdee141402ac03a479ecd..e232e4f7e53e0fff02097394f821add615067647 100644 (file)
@@ -889,15 +889,14 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
                     !strv_isempty(m->confext_release))
                         putc('\n', stdout);
 
-                printf("    Use As: %s bootable system for UEFI\n", COLOR_MARK_BOOL(m->partitions[PARTITION_ESP].found));
-
-                if (m->has_init_system >= 0)
-                        printf("            %s bootable system for container\n", COLOR_MARK_BOOL(m->has_init_system));
-
+                printf("    Use As: %s bootable system for UEFI\n",
+                       COLOR_MARK_BOOL(dissected_image_is_bootable_uefi(m)));
+                printf("            %s bootable system for container\n",
+                       COLOR_MARK_BOOL(dissected_image_is_bootable_os(m)));
                 printf("            %s portable service\n",
-                       COLOR_MARK_BOOL(strv_env_pairs_get(m->os_release, "PORTABLE_PREFIXES")));
+                       COLOR_MARK_BOOL(dissected_image_is_portable(m)));
                 printf("            %s initrd\n",
-                       COLOR_MARK_BOOL(!strv_isempty(m->initrd_release)));
+                       COLOR_MARK_BOOL(dissected_image_is_initrd(m)));
 
                 for (ImageClass c = _IMAGE_CLASS_EXTENSION_FIRST; c <= _IMAGE_CLASS_EXTENSION_LAST; c++) {
                         const char *string_class = image_class_to_string(c);
@@ -942,10 +941,10 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
                                                JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->initrd_release), "initrdRelease", JSON_BUILD_STRV_ENV_PAIR(m->initrd_release)),
                                                JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->sysext_release), "sysextRelease", JSON_BUILD_STRV_ENV_PAIR(m->sysext_release)),
                                                JSON_BUILD_PAIR_CONDITION(!strv_isempty(m->confext_release), "confextRelease", JSON_BUILD_STRV_ENV_PAIR(m->confext_release)),
-                                               JSON_BUILD_PAIR("useBootableUefi", JSON_BUILD_BOOLEAN(m->partitions[PARTITION_ESP].found)),
-                                               JSON_BUILD_PAIR_CONDITION(m->has_init_system >= 0, "useBootableContainer", JSON_BUILD_BOOLEAN(m->has_init_system)),
-                                               JSON_BUILD_PAIR("useInitrd", JSON_BUILD_BOOLEAN(!strv_isempty(m->initrd_release))),
-                                               JSON_BUILD_PAIR("usePortableService", JSON_BUILD_BOOLEAN(strv_env_pairs_get(m->os_release, "PORTABLE_MATCHES"))),
+                                               JSON_BUILD_PAIR("useBootableUefi", JSON_BUILD_BOOLEAN(dissected_image_is_bootable_uefi(m))),
+                                               JSON_BUILD_PAIR("useBootableContainer", JSON_BUILD_BOOLEAN(dissected_image_is_bootable_os(m))),
+                                               JSON_BUILD_PAIR("useInitrd", JSON_BUILD_BOOLEAN(dissected_image_is_initrd(m))),
+                                               JSON_BUILD_PAIR("usePortableService", JSON_BUILD_BOOLEAN(dissected_image_is_portable(m))),
                                                JSON_BUILD_PAIR("useSystemExtension", JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "system"))),
                                                JSON_BUILD_PAIR("useInitRDSystemExtension", JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "initrd"))),
                                                JSON_BUILD_PAIR("usePortableSystemExtension", JSON_BUILD_BOOLEAN(strv_contains(sysext_scopes, "portable"))),
index 21a0f22bcc27f27c253a45d4eafbf8e35661fd09..8be632acc27530993593d3786ad7eaebc569eb43 100644 (file)
@@ -6,11 +6,13 @@
 #include "sd-id128.h"
 
 #include "architecture.h"
+#include "env-util.h"
 #include "gpt.h"
 #include "list.h"
 #include "loop-util.h"
 #include "macro.h"
 #include "os-util.h"
+#include "strv.h"
 
 typedef struct DissectedImage DissectedImage;
 typedef struct DissectedPartition DissectedPartition;
@@ -169,6 +171,22 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
 
 Architecture dissected_image_architecture(DissectedImage *m);
 
+static inline bool dissected_image_is_bootable_os(DissectedImage *m) {
+        return m && m->has_init_system > 0;
+}
+
+static inline bool dissected_image_is_bootable_uefi(DissectedImage *m) {
+        return m && m->partitions[PARTITION_ESP].found && dissected_image_is_bootable_os(m);
+}
+
+static inline bool dissected_image_is_portable(DissectedImage *m) {
+        return m && strv_env_pairs_get(m->os_release, "PORTABLE_PREFIXES");
+}
+
+static inline bool dissected_image_is_initrd(DissectedImage *m) {
+        return m && !strv_isempty(m->initrd_release);
+}
+
 DecryptedImage* decrypted_image_ref(DecryptedImage *p);
 DecryptedImage* decrypted_image_unref(DecryptedImage *p);
 DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref);