]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/dissect/dissect.c
Merge pull request #9437 from poettering/sd-boot-count
[thirdparty/systemd.git] / src / dissect / dissect.c
index fd9db5ba8786b4016ff4edb2bb50fbdbcdd7b2d8..86fa84337bfbde8882b3867a32083a16b4b52a8d 100644 (file)
@@ -1,21 +1,4 @@
-/***
-  This file is part of systemd.
-
-  Copyright 2016 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include <fcntl.h>
 #include <stdio.h>
@@ -27,6 +10,8 @@
 #include "log.h"
 #include "loop-util.h"
 #include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
 #include "util.h"
 
 static enum {
@@ -121,7 +106,7 @@ static int parse_argv(int argc, char *argv[]) {
 
                         r = unhexmem(optarg, strlen(optarg), &p, &l);
                         if (r < 0)
-                                return log_error_errno(r, "Failed to parse root hash: %s", optarg);
+                                return log_error_errno(r, "Failed to parse root hash '%s': %m", optarg);
                         if (l < sizeof(sd_id128_t)) {
                                 log_error("Root hash must be at least 128bit long: %s", optarg);
                                 free(p);
@@ -191,19 +176,17 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        r = dissect_image(d->fd, arg_root_hash, arg_root_hash_size, arg_flags, &m);
-        if (r == -ENOPKG) {
-                log_error_errno(r, "Couldn't identify a suitable partition table or file system in %s.", arg_image);
-                goto finish;
-        }
-        if (r == -EADDRNOTAVAIL) {
-                log_error_errno(r, "No root partition for specified root hash found in %s.", arg_image);
-                goto finish;
+        if (!arg_root_hash) {
+                r = root_hash_load(arg_image, &arg_root_hash, &arg_root_hash_size);
+                if (r < 0) {
+                        log_error_errno(r, "Failed to read root hash file for %s: %m", arg_image);
+                        goto finish;
+                }
         }
-        if (r < 0) {
-                log_error_errno(r, "Failed to dissect image: %m");
+
+        r = dissect_image_and_warn(d->fd, arg_image, arg_root_hash, arg_root_hash_size, arg_flags, &m);
+        if (r < 0)
                 goto finish;
-        }
 
         switch (arg_action) {
 
@@ -243,6 +226,36 @@ int main(int argc, char *argv[]) {
                         putchar('\n');
                 }
 
+                r = dissected_image_acquire_metadata(m);
+                if (r < 0) {
+                        log_error_errno(r, "Failed to acquire image metadata: %m");
+                        goto finish;
+                }
+
+                if (m->hostname)
+                        printf("  Hostname: %s\n", m->hostname);
+
+                if (!sd_id128_is_null(m->machine_id))
+                        printf("Machine ID: " SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(m->machine_id));
+
+                if (!strv_isempty(m->machine_info)) {
+                        char **p, **q;
+
+                        STRV_FOREACH_PAIR(p, q, m->machine_info)
+                                printf("%s %s=%s\n",
+                                       p == m->machine_info ? "Mach. Info:" : "           ",
+                                       *p, *q);
+                }
+
+                if (!strv_isempty(m->os_release)) {
+                        char **p, **q;
+
+                        STRV_FOREACH_PAIR(p, q, m->os_release)
+                                printf("%s %s=%s\n",
+                                       p == m->os_release ? "OS Release:" : "           ",
+                                       *p, *q);
+                }
+
                 break;
         }
 
@@ -251,7 +264,7 @@ int main(int argc, char *argv[]) {
                 if (r < 0)
                         goto finish;
 
-                r = dissected_image_mount(m, arg_path, arg_flags);
+                r = dissected_image_mount(m, arg_path, UID_INVALID, arg_flags);
                 if (r < 0) {
                         log_error_errno(r, "Failed to mount image: %m");
                         goto finish;