From: Lennart Poettering Date: Tue, 10 Oct 2023 21:09:45 +0000 (+0200) Subject: dissect: move helpers for categorizing DDIs into generic code X-Git-Tag: v255-rc1~247^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F29525%2Fhead;p=thirdparty%2Fsystemd.git dissect: move helpers for categorizing DDIs into generic code 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). --- diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index a03f9a64db8..e232e4f7e53 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -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"))), diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 21a0f22bcc2..8be632acc27 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -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);