]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: reuse LoopDevice.node in dissect_image()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 6 Sep 2022 13:43:47 +0000 (22:43 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Sep 2022 11:45:24 +0000 (20:45 +0900)
Currently, dissect_image() is only called through dissect_loop_device(),
and the LoopDevice object has device name. Hence, it is not necessary to
get device name in dissect_image().

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

index 06f2037952fa17c42cdad15f2f93861f6f415eb3..d5425c4de4857f18f6d69b3ff28977cdb743d48a 100644 (file)
@@ -193,6 +193,7 @@ static int make_partition_devname(
 
 int dissect_image(
                 int fd,
+                const char *devname,
                 const char *image_path,
                 const VeritySettings *verity,
                 const MountOptions *mount_options,
@@ -205,17 +206,16 @@ int dissect_image(
         bool is_gpt, is_mbr, multiple_generic = false,
                 generic_rw = false,  /* initialize to appease gcc */
                 generic_growfs = false;
-        _cleanup_(sd_device_unrefp) sd_device *d = NULL;
         _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL;
         _cleanup_(blkid_free_probep) blkid_probe b = NULL;
         _cleanup_free_ char *generic_node = NULL;
         sd_id128_t generic_uuid = SD_ID128_NULL;
-        const char *pttype = NULL, *devname = NULL;
+        const char *pttype = NULL;
         blkid_partlist pl;
         int r, generic_nr = -1, n_partitions;
-        struct stat st;
 
         assert(fd >= 0);
+        assert(devname);
         assert(ret);
         assert(!verity || verity->designator < 0 || IN_SET(verity->designator, PARTITION_ROOT, PARTITION_USR));
         assert(!verity || verity->root_hash || verity->root_hash_size == 0);
@@ -259,16 +259,6 @@ int dissect_image(
                 }
         }
 
-        if (fstat(fd, &st) < 0)
-                return -errno;
-
-        if (!S_ISBLK(st.st_mode))
-                return -ENOTBLK;
-
-        r = sd_device_new_from_stat_rdev(&d, &st);
-        if (r < 0)
-                return r;
-
         b = blkid_new_probe();
         if (!b)
                 return -ENOMEM;
@@ -319,10 +309,6 @@ int dissect_image(
                         m->image_name = TAKE_PTR(name_stripped);
         }
 
-        r = sd_device_get_devname(d, &devname);
-        if (r < 0)
-                return log_debug_errno(r, "Failed to get device devname: %m");
-
         if ((!(flags & DISSECT_IMAGE_GPT_ONLY) &&
             (flags & DISSECT_IMAGE_GENERIC_ROOT)) ||
             (flags & DISSECT_IMAGE_NO_PARTITION_TABLE)) {
index b9aa3ad63ac3071887010d74021b4eef5d70185b..fe478bde493b0434014f4d6b5af343500d6ab6ec 100644 (file)
@@ -255,6 +255,7 @@ const char* mount_options_from_designator(const MountOptions *options, Partition
 int probe_filesystem(const char *node, char **ret_fstype);
 int dissect_image(
                 int fd,
+                const char *devname,
                 const char *image_path,
                 const VeritySettings *verity,
                 const MountOptions *mount_options,
@@ -262,7 +263,7 @@ int dissect_image(
                 DissectedImage **ret);
 static inline int dissect_loop_device(const LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, DissectImageFlags flags, DissectedImage **ret) {
         assert(loop);
-        return dissect_image(loop->fd, loop->backing_file ?: loop->node, verity, mount_options, flags, ret);
+        return dissect_image(loop->fd, loop->node, loop->backing_file ?: loop->node, verity, mount_options, flags, ret);
 }
 int dissect_loop_device_and_warn(const LoopDevice *loop, const VeritySettings *verity, const MountOptions *mount_options, DissectImageFlags flags, DissectedImage **ret);