]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Stat temporary file again after mkfs
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 5 Aug 2023 17:31:09 +0000 (19:31 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 5 Aug 2023 22:08:05 +0000 (23:08 +0100)
This makes sure we use the actual size after mkfs which seems to be
important for btrfs as it refuses to mount the partition otherwise.

Follow-up for 2843df3e5734aa07b82b96ba46b799921a6495b8

src/partition/repart.c

index 1a316012e7edd8cea18157cd8d3a8145756b887a..4a40a05ee85772e16c36dce0c69370704890db48 100644 (file)
@@ -5844,6 +5844,7 @@ static int context_minimize(Context *context) {
                 _cleanup_close_ int fd = -EBADF;
                 _cleanup_free_ char *hint = NULL;
                 sd_id128_t fs_uuid;
+                struct stat st;
                 uint64_t fsz;
 
                 if (p->dropped)
@@ -5932,8 +5933,6 @@ static int context_minimize(Context *context) {
                 /* Read-only filesystems are minimal from the first try because they create and size the
                  * loopback file for us. */
                 if (fstype_is_ro(p->format)) {
-                        struct stat st;
-
                         assert(fd < 0);
 
                         fd = open(temp, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
@@ -6012,12 +6011,13 @@ static int context_minimize(Context *context) {
                                 return r;
                 }
 
-                assert(fd >= 0);
+                if (fstat(fd, &st) < 0)
+                        return log_error_errno(errno, "Failed to stat temporary file: %m");
 
                 p->copy_blocks_path = TAKE_PTR(temp);
                 p->copy_blocks_path_is_our_file = true;
                 p->copy_blocks_fd = TAKE_FD(fd);
-                p->copy_blocks_size = fsz;
+                p->copy_blocks_size = st.st_size;
         }
 
         /* Now that we've done the data partitions, do the verity hash partitions. We do these in a separate