_x > UINT64_MAX - 4095U ? UINT64_MAX : (_x + 4095U) & ~UINT64_C(4095); \
})
+/* How much larger will the image on disk be than the fs inside it, i.e. the space we pay for the GPT and
+ * LUKS2 envelope. (As measured on cryptsetup 2.4.1) */
+#define GPT_LUKS2_OVERHEAD UINT64_C(18874368)
+
static int resize_image_loop(UserRecord *h, HomeSetup *setup, uint64_t old_image_size, uint64_t new_image_size, uint64_t *ret_image_size);
int run_mark_dirty(int fd, bool b) {
assert(first_lba <= UINT64_MAX/512);
start = DISK_SIZE_ROUND_UP(first_lba * 512); /* Round up to multiple of 4K */
+ log_debug("Starting partition at offset %" PRIu64, start);
+
if (start == UINT64_MAX)
return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "Overflow while rounding up start LBA.");
}
lower_boundary = minimal_size_by_fs_name(fstype);
+ if (lower_boundary != UINT64_MAX) {
+ assert(GPT_LUKS2_OVERHEAD < UINT64_MAX - lower_boundary);
+ lower_boundary += GPT_LUKS2_OVERHEAD;
+ }
if (lower_boundary == UINT64_MAX || lower_boundary < USER_DISK_SIZE_MIN)
lower_boundary = USER_DISK_SIZE_MIN;
else
host_size = DISK_SIZE_ROUND_DOWN(h->disk_size);
- if (!supported_fs_size(fstype, host_size))
+ if (!supported_fs_size(fstype, LESS_BY(host_size, GPT_LUKS2_OVERHEAD)))
return log_error_errno(SYNTHETIC_ERRNO(ERANGE),
"Selected file system size too small for %s.", fstype);
print_size_summary(host_size, encrypted_size, &sfs);
+ log_debug("GPT + LUKS2 overhead is %" PRIu64 " (expected %" PRIu64 ")", host_size - encrypted_size, GPT_LUKS2_OVERHEAD);
+
*ret_home = TAKE_PTR(new_home);
return 0;
}