From: Yu Watanabe Date: Tue, 6 Sep 2022 13:43:47 +0000 (+0900) Subject: dissect-image: reuse LoopDevice.node in dissect_image() X-Git-Tag: v252-rc1~236^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b214aa0d0f287f14cca91b66ff7f0c253d22172;p=thirdparty%2Fsystemd.git dissect-image: reuse LoopDevice.node in dissect_image() 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(). --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 06f2037952f..d5425c4de48 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -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)) { diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index b9aa3ad63ac..fe478bde493 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -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);