From: Lennart Poettering Date: Mon, 4 Dec 2023 17:04:44 +0000 (+0100) Subject: dissect-image: also store the image size in DissectedImage X-Git-Tag: v256-rc1~1490^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51778dea0dd84f0564f77cce4a69983da12a9ce5;p=thirdparty%2Fsystemd.git dissect-image: also store the image size in DissectedImage That way we can easily access it the same way regardless if we operate on a block device or on a regular file. --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 5869843c42e..98690367a15 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1547,6 +1547,7 @@ int dissect_image_file( #if HAVE_BLKID _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL; _cleanup_close_ int fd = -EBADF; + struct stat st; int r; assert(path); @@ -1555,7 +1556,10 @@ int dissect_image_file( if (fd < 0) return -errno; - r = fd_verify_regular(fd); + if (fstat(fd, &st) < 0) + return -errno; + + r = stat_verify_regular(&st); if (r < 0) return r; @@ -1563,6 +1567,8 @@ int dissect_image_file( if (r < 0) return r; + m->image_size = st.st_size; + r = probe_sector_size(fd, &m->sector_size); if (r < 0) return r; @@ -3699,6 +3705,7 @@ int dissect_loop_device( return r; m->loop = loop_device_ref(loop); + m->image_size = m->loop->device_size; m->sector_size = m->loop->sector_size; r = dissect_image(m, loop->fd, loop->node, verity, mount_options, image_policy, flags); diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 15c0bf72194..ed02049ed0c 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -102,6 +102,7 @@ struct DissectedImage { DecryptedImage *decrypted_image; uint32_t sector_size; + uint64_t image_size; char *image_name; sd_id128_t image_uuid;