From: Daan De Meyer Date: Sat, 23 Nov 2024 10:36:54 +0000 (+0100) Subject: repart: Take configured minimum and maximum size into account for Minimize= X-Git-Tag: v258-rc1~1868 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d218ecc7337a4689e7d589df7fd146f4aaab3809;p=thirdparty%2Fsystemd.git repart: Take configured minimum and maximum size into account for Minimize= - Let's check if the minimum size we got is larger than the configured maximum partition size and fail early if it is. - Let's make sure for writable filesystems that we make the minimal filesystem at least as large as the minimum partition size, to allow creating minimal filesystems with a minimum size. --- diff --git a/src/repart/repart.c b/src/repart/repart.c index 9515b7539ff..1a88185c475 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -7625,6 +7625,11 @@ static int context_minimize(Context *context) { if (fstat(fd, &st) < 0) return log_error_errno(errno, "Failed to stat temporary file: %m"); + if ((uint64_t) st.st_size > partition_max_size(context, p)) + return log_error_errno(SYNTHETIC_ERRNO(E2BIG), + "Minimal partition size of %s filesystem of partition %s exceeds configured maximum size (%s > %s)", + p->format, strna(hint), FORMAT_BYTES(st.st_size), FORMAT_BYTES(partition_max_size(context, p))); + log_info("Minimal partition size of %s filesystem of partition %s is %s", p->format, strna(hint), FORMAT_BYTES(st.st_size)); @@ -7661,8 +7666,12 @@ static int context_minimize(Context *context) { * fool-proof. */ uint64_t heuristic = streq(p->format, "xfs") ? fsz : fsz / 2; fsz = round_up_size(fsz + heuristic, context->grain_size); - if (minimal_size_by_fs_name(p->format) != UINT64_MAX) - fsz = MAX(minimal_size_by_fs_name(p->format), fsz); + fsz = MAX(partition_min_size(context, p), fsz); + + if (fsz > partition_max_size(context, p)) + return log_error_errno(SYNTHETIC_ERRNO(E2BIG), + "Minimal partition size of %s filesystem of partition %s exceeds configured maximum size (%s > %s)", + p->format, strna(hint), FORMAT_BYTES(fsz), FORMAT_BYTES(partition_max_size(context, p))); log_info("Minimal partition size of %s filesystem of partition %s is %s", p->format, strna(hint), FORMAT_BYTES(fsz));