]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/dissect-image.c
resolved: rework parsing of /etc/hosts
[thirdparty/systemd.git] / src / shared / dissect-image.c
index 06070d085edcc0184a1b054d5a16806214f77bdc..4e572ac861c5a18c24b633f593ee46888b9b16b9 100644 (file)
 #include "copy.h"
 #include "crypt-util.h"
 #include "def.h"
-#include "device-enumerator-private.h"
 #include "device-nodes.h"
+#include "device-util.h"
 #include "dissect-image.h"
+#include "env-file.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
@@ -27,6 +28,7 @@
 #include "linux-3.13/dm-ioctl.h"
 #include "missing.h"
 #include "mount-util.h"
+#include "mountpoint-util.h"
 #include "os-util.h"
 #include "path-util.h"
 #include "process-util.h"
@@ -37,6 +39,7 @@
 #include "string-table.h"
 #include "string-util.h"
 #include "strv.h"
+#include "tmpfile-util.h"
 #include "user-util.h"
 #include "xattr-util.h"
 
@@ -219,8 +222,9 @@ int dissect_image(
                                         return -ENOMEM;
                         }
 
-                        if (asprintf(&n, "/dev/block/%u:%u", major(st.st_rdev), minor(st.st_rdev)) < 0)
-                                return -ENOMEM;
+                        r = device_path_make_major_minor(st.st_mode, st.st_rdev, &n);
+                        if (r < 0)
+                                return r;
 
                         m->partitions[PARTITION_ROOT] = (DissectedPartition) {
                                 .found = true,
@@ -231,7 +235,7 @@ int dissect_image(
                                 .node = TAKE_PTR(n),
                         };
 
-                        m->encrypted = streq(fstype, "crypto_LUKS");
+                        m->encrypted = streq_ptr(fstype, "crypto_LUKS");
 
                         *ret = TAKE_PTR(m);
 
@@ -278,16 +282,10 @@ int dissect_image(
                 if (r < 0)
                         return r;
 
-                r = device_enumerator_scan_devices(e);
-                if (r < 0)
-                        return r;
-
                 /* Count the partitions enumerated by the kernel */
                 n = 0;
-                FOREACH_DEVICE_AND_SUBSYSTEM(e, q) {
-                        dev_t qn;
-
-                        if (sd_device_get_devnum(q, &qn) < 0)
+                FOREACH_DEVICE(e, q) {
+                        if (sd_device_get_devnum(q, NULL) < 0)
                                 continue;
 
                         if (!device_is_block(q))
@@ -350,7 +348,7 @@ int dissect_image(
                 e = sd_device_enumerator_unref(e);
         }
 
-        FOREACH_DEVICE_AND_SUBSYSTEM(e, q) {
+        FOREACH_DEVICE(e, q) {
                 unsigned long long pflags;
                 blkid_partition pp;
                 const char *node;
@@ -775,7 +773,7 @@ int dissected_image_mount(DissectedImage *m, const char *where, uid_t uid_shift,
                 }
         }
 
-        if ((flags & DISSECT_IMAGE_MOUNT_ROOT_ONLY))
+        if (flags & DISSECT_IMAGE_MOUNT_ROOT_ONLY)
                 return 0;
 
         r = mount_partition(m->partitions + PARTITION_HOME, where, "/home", uid_shift, flags);
@@ -1092,14 +1090,13 @@ int dissected_image_decrypt_interactively(
                 else if (r != -ENOKEY)
                         return log_error_errno(r, "Failed to decrypt image: %m");
 
-                if (--n < 0) {
-                        log_error("Too many retries.");
-                        return -EKEYREJECTED;
-                }
+                if (--n < 0)
+                        return log_error_errno(SYNTHETIC_ERRNO(EKEYREJECTED),
+                                               "Too many retries.");
 
                 z = strv_free(z);
 
-                r = ask_password_auto("Please enter image passphrase!", NULL, "dissect", "dissect", USEC_INFINITY, 0, &z);
+                r = ask_password_auto("Please enter image passphrase:", NULL, "dissect", "dissect", USEC_INFINITY, 0, &z);
                 if (r < 0)
                         return log_error_errno(r, "Failed to query for passphrase: %m");
 
@@ -1339,14 +1336,14 @@ int dissected_image_acquire_metadata(DissectedImage *m) {
                 }
 
                 case META_MACHINE_INFO:
-                        r = load_env_file_pairs(f, "machine-info", NULL, &machine_info);
+                        r = load_env_file_pairs(f, "machine-info", &machine_info);
                         if (r < 0)
                                 log_debug_errno(r, "Failed to read /etc/machine-info: %m");
 
                         break;
 
                 case META_OS_RELEASE:
-                        r = load_env_file_pairs(f, "os-release", NULL, &os_release);
+                        r = load_env_file_pairs(f, "os-release", &os_release);
                         if (r < 0)
                                 log_debug_errno(r, "Failed to read OS release file: %m");