diff options
Diffstat (limited to 'src/shared/dissect-image.c')
-rw-r--r-- | src/shared/dissect-image.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 5ede8923fa..dc7cf817f3 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 *original_path, const VeritySettings *verity, const MountOptions *mount_options, uint64_t diskseq, @@ -307,15 +308,29 @@ int dissect_image( r = sd_device_get_sysname(d, &sysname); if (r < 0) return log_debug_errno(r, "Failed to get device sysname: %m"); - if (startswith(sysname, "loop")) { - _cleanup_free_ char *name_stripped = NULL; + if (original_path) { + _cleanup_free_ char *extracted_filename = NULL, *name_stripped = NULL; + r = path_extract_filename(original_path, &extracted_filename); + if (r < 0) + return r; + r = raw_strip_suffixes(extracted_filename, &name_stripped); + if (r < 0) + return r; + + free_and_replace(m->image_name, name_stripped); + } else if (startswith(sysname, "loop")) { + _cleanup_free_ char *extracted_filename = NULL, *name_stripped = NULL; const char *full_path; + /* Note that the backing_file reference resolves symlinks, while for sysext images we want the original path */ r = sd_device_get_sysattr_value(d, "loop/backing_file", &full_path); if (r < 0) log_debug_errno(r, "Failed to lookup image name via loop device backing file sysattr, ignoring: %m"); else { - r = raw_strip_suffixes(basename(full_path), &name_stripped); + r = path_extract_filename(full_path, &extracted_filename); + if (r < 0) + return r; + r = raw_strip_suffixes(extracted_filename, &name_stripped); if (r < 0) return r; } @@ -2812,7 +2827,7 @@ int dissect_loop_device_and_warn( if (!name) name = ASSERT_PTR(loop->node); - r = dissect_loop_device(loop, verity, mount_options, flags, ret); + r = dissect_loop_device(loop, name, verity, mount_options, flags, ret); switch (r) { case -EOPNOTSUPP: @@ -3078,6 +3093,7 @@ int verity_dissect_and_mount( r = dissect_loop_device( loop_device, + src, &verity, options, dissect_image_flags, @@ -3086,6 +3102,7 @@ int verity_dissect_and_mount( if (!verity.data_path && r == -ENOPKG) r = dissect_loop_device( loop_device, + src, &verity, options, dissect_image_flags | DISSECT_IMAGE_NO_PARTITION_TABLE, |