]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/dissect/dissect.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / dissect / dissect.c
index f2f1e135ec7c461c6c7ff99f2d298c475f9d58f7..42957766eaa75240695c717a128529a88c62f4e6 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -35,7 +36,7 @@ static enum {
 } arg_action = ACTION_DISSECT;
 static const char *arg_image = NULL;
 static const char *arg_path = NULL;
-static DissectImageFlags arg_flags = DISSECT_IMAGE_DISCARD_ON_LOOP;
+static DissectImageFlags arg_flags = DISSECT_IMAGE_REQUIRE_ROOT|DISSECT_IMAGE_DISCARD_ON_LOOP;
 static void *arg_root_hash = NULL;
 static size_t arg_root_hash_size = 0;
 
@@ -191,7 +192,15 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        r = dissect_image(d->fd, arg_root_hash, arg_root_hash_size, &m);
+        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;
+                }
+        }
+
+        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;
@@ -200,6 +209,18 @@ int main(int argc, char *argv[]) {
                 log_error_errno(r, "No root partition for specified root hash found in %s.", arg_image);
                 goto finish;
         }
+        if (r == -ENOTUNIQ) {
+                log_error_errno(r, "Multiple suitable root partitions found in image %s.", arg_image);
+                goto finish;
+        }
+        if (r == -ENXIO) {
+                log_error_errno(r, "No suitable root partition found in image %s.", arg_image);
+                goto finish;
+        }
+        if (r == -EPROTONOSUPPORT) {
+                log_error_errno(r, "Device %s is loopback block device with partition scanning turned off, please turn it on.", arg_image);
+                goto finish;
+        }
         if (r < 0) {
                 log_error_errno(r, "Failed to dissect image: %m");
                 goto finish;
@@ -221,6 +242,9 @@ int main(int argc, char *argv[]) {
                                p->rw ? "writable" : "read-only",
                                partition_designator_to_string(i));
 
+                        if (!sd_id128_is_null(p->uuid))
+                                printf(" (UUID " SD_ID128_FORMAT_STR ")", SD_ID128_FORMAT_VAL(p->uuid));
+
                         if (p->fstype)
                                 printf(" of type %s", p->fstype);