From 6db162492b33be55bcff6317a3c03ac7a3d4f36a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 3 Sep 2025 10:40:21 +0200 Subject: [PATCH 1/4] openssl-util: make openssl_load_private_key()'s ret_ui parameter optional --- src/shared/openssl-util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/openssl-util.c b/src/shared/openssl-util.c index 4b5c495df6..8bc6c5c2d6 100644 --- a/src/shared/openssl-util.c +++ b/src/shared/openssl-util.c @@ -1726,13 +1726,15 @@ int openssl_load_private_key( assert(private_key); assert(request); + assert(ret_private_key); if (private_key_source_type == OPENSSL_KEY_SOURCE_FILE) { r = openssl_load_private_key_from_file(private_key, ret_private_key); if (r < 0) return r; - *ret_user_interface = NULL; + if (ret_user_interface) + *ret_user_interface = NULL; } else { _cleanup_(openssl_ask_password_ui_freep) OpenSSLAskPasswordUI *ui = NULL; r = openssl_ask_password_ui_new(request, &ui); @@ -1757,7 +1759,8 @@ int openssl_load_private_key( private_key, private_key_source); - *ret_user_interface = TAKE_PTR(ui); + if (ret_user_interface) + *ret_user_interface = TAKE_PTR(ui); } return 0; From bc54521855043c08c8948b5e0137a7407a1fce9c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 Aug 2025 10:42:33 +0200 Subject: [PATCH 2/4] repart: never use a grain size below sector size --- src/repart/repart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repart/repart.c b/src/repart/repart.c index 433798fa57..9463bd613c 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -3445,7 +3445,7 @@ static int context_load_partition_table(Context *context) { /* Use the fallback values if we have no better idea */ context->sector_size = fdisk_get_sector_size(c); context->default_fs_sector_size = fs_secsz; - context->grain_size = 4096; + context->grain_size = MAX(context->sector_size, 4096U); return /* from_scratch = */ true; } From 222dcf3bc250d267bb96de1d373a6a28355bf800 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 28 Aug 2025 10:54:41 +0200 Subject: [PATCH 3/4] repart: add some line breaks --- src/repart/repart.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/repart/repart.c b/src/repart/repart.c index 9463bd613c..1ffa9e9c3e 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -789,7 +789,11 @@ static Partition* partition_unlink_and_free(Context *context, Partition *p) { DEFINE_TRIVIAL_CLEANUP_FUNC(Partition*, partition_free); -static Context* context_new(sd_id128_t seed, X509 *certificate, EVP_PKEY *private_key) { +static Context* context_new( + sd_id128_t seed, + X509 *certificate, + EVP_PKEY *private_key) { + Context *context; /* Note: This function takes ownership of the certificate and private_key arguments. */ @@ -8666,7 +8670,13 @@ static int help(void) { return 0; } -static int parse_argv(int argc, char *argv[], X509 **ret_certificate, EVP_PKEY **ret_private_key, OpenSSLAskPasswordUI **ret_ui) { +static int parse_argv( + int argc, + char *argv[], + X509 **ret_certificate, + EVP_PKEY **ret_private_key, + OpenSSLAskPasswordUI **ret_ui) { + enum { ARG_VERSION = 0x100, ARG_NO_PAGER, From 2f5fb752a6f5b19e279220238ef882ad3ecb8848 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 Sep 2025 22:52:45 +0200 Subject: [PATCH 4/4] repart: tweak byte value output So far, when outputing information about copy progress we'd suppress the digit after the dot if it is zero. That makes the progress bar a bit "jumpy", because sometimes there are two more character cells used than other times. Let's just always output one digit after the dot here hence, to avoid this. --- src/basic/format-util.c | 3 ++- src/basic/format-util.h | 10 +++++---- src/repart/repart.c | 10 ++++----- src/test/test-format-util.c | 43 ++++++++++++++++++++++--------------- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/basic/format-util.c b/src/basic/format-util.c index 021ece9eeb..4c601e553f 100644 --- a/src/basic/format-util.c +++ b/src/basic/format-util.c @@ -39,7 +39,8 @@ char* format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) { (t / table[i + 1].factor * 10 / table[n - 1].factor) % 10 : (t * 10 / table[i].factor) % 10; - if (FLAGS_SET(flag, FORMAT_BYTES_BELOW_POINT) && remainder > 0) + if (FLAGS_SET(flag, FORMAT_BYTES_ALWAYS_POINT) || + (FLAGS_SET(flag, FORMAT_BYTES_BELOW_POINT) && remainder > 0)) (void) snprintf(buf, l, "%" PRIu64 ".%" PRIu64 "%s", t / table[i].factor, diff --git a/src/basic/format-util.h b/src/basic/format-util.h index e42f788ce6..ab3328e1d2 100644 --- a/src/basic/format-util.h +++ b/src/basic/format-util.h @@ -64,9 +64,10 @@ assert_cc(sizeof(gid_t) == sizeof(uint32_t)); #endif typedef enum { - FORMAT_BYTES_USE_IEC = 1 << 0, - FORMAT_BYTES_BELOW_POINT = 1 << 1, - FORMAT_BYTES_TRAILING_B = 1 << 2, + FORMAT_BYTES_USE_IEC = 1 << 0, /* use base 1024 rather than 1000 */ + FORMAT_BYTES_BELOW_POINT = 1 << 1, /* show one digit after the point, if non-zero */ + FORMAT_BYTES_ALWAYS_POINT = 1 << 2, /* show one digit after the point, always */ + FORMAT_BYTES_TRAILING_B = 1 << 3, /* suffix the expression with a "B" for "bytes" */ } FormatBytesFlag; #define FORMAT_BYTES_MAX 16U @@ -82,6 +83,7 @@ static inline char* format_bytes(char *buf, size_t l, uint64_t t) { * see C11 ยง6.5.2.5, and * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks */ #define FORMAT_BYTES(t) format_bytes((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t) -#define FORMAT_BYTES_FULL(t, flag) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, flag) +#define FORMAT_BYTES_FULL(t, flags) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, flags) +#define FORMAT_BYTES_WITH_POINT(t) format_bytes_full((char[FORMAT_BYTES_MAX]){}, FORMAT_BYTES_MAX, t, FORMAT_BYTES_USE_IEC|FORMAT_BYTES_ALWAYS_POINT|FORMAT_BYTES_TRAILING_B) #define FORMAT_BYTES_CGROUP_PROTECTION(t) (t == CGROUP_LIMIT_MAX ? "infinity" : FORMAT_BYTES(t)) diff --git a/src/repart/repart.c b/src/repart/repart.c index 1ffa9e9c3e..5e312ce086 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -5493,9 +5493,9 @@ static int progress_bytes(uint64_t n_bytes, uint64_t bps, void *userdata) { strna(p->copy_blocks_path), glyph(GLYPH_ARROW_RIGHT), strna(p->definition_path), - FORMAT_BYTES(p->copy_blocks_done), - FORMAT_BYTES(p->copy_blocks_size), - FORMAT_BYTES(bps)); + FORMAT_BYTES_WITH_POINT(p->copy_blocks_done), + FORMAT_BYTES_WITH_POINT(p->copy_blocks_size), + FORMAT_BYTES_WITH_POINT(bps)); else (void) draw_progress_barf( percent, @@ -5503,8 +5503,8 @@ static int progress_bytes(uint64_t n_bytes, uint64_t bps, void *userdata) { strna(p->copy_blocks_path), glyph(GLYPH_ARROW_RIGHT), strna(p->definition_path), - FORMAT_BYTES(p->copy_blocks_done), - FORMAT_BYTES(p->copy_blocks_size)); + FORMAT_BYTES_WITH_POINT(p->copy_blocks_done), + FORMAT_BYTES_WITH_POINT(p->copy_blocks_size)); p->last_percent = percent; diff --git a/src/test/test-format-util.c b/src/test/test-format-util.c index 0a95837dbe..1216180e11 100644 --- a/src/test/test-format-util.c +++ b/src/test/test-format-util.c @@ -28,32 +28,41 @@ assert_cc(DECIMAL_STR_MAX(signed char) == STRLEN("-127")+1); assert_cc(DECIMAL_STR_MAX(unsigned char) == STRLEN("255")+1); assert_cc(CONST_MAX(DECIMAL_STR_MAX(int8_t), STRLEN("xxx")) == 5); -static void test_format_bytes_one(uint64_t val, bool trailing_B, const char *iec_with_p, const char *iec_without_p, - const char *si_with_p, const char *si_without_p) { +static void test_format_bytes_one( + uint64_t val, + bool trailing_B, + const char *iec_with_p, + const char *iec_without_p, + const char *iec_always_p, + const char *si_with_p, + const char *si_without_p, + const char *si_always_p) { char buf[FORMAT_BYTES_MAX]; ASSERT_STREQ(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_BELOW_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), iec_with_p); ASSERT_STREQ(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_USE_IEC | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), iec_without_p); + ASSERT_STREQ(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_ALWAYS_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), iec_always_p); ASSERT_STREQ(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_BELOW_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), si_with_p); ASSERT_STREQ(format_bytes_full(buf, sizeof buf, val, trailing_B ? FORMAT_BYTES_TRAILING_B : 0), si_without_p); + ASSERT_STREQ(format_bytes_full(buf, sizeof buf, val, FORMAT_BYTES_ALWAYS_POINT | (trailing_B ? FORMAT_BYTES_TRAILING_B : 0)), si_always_p); } TEST(format_bytes) { - test_format_bytes_one(900, true, "900B", "900B", "900B", "900B"); - test_format_bytes_one(900, false, "900", "900", "900", "900"); - test_format_bytes_one(1023, true, "1023B", "1023B", "1K", "1K"); - test_format_bytes_one(1023, false, "1023", "1023", "1K", "1K"); - test_format_bytes_one(1024, true, "1K", "1K", "1K", "1K"); - test_format_bytes_one(1024, false, "1K", "1K", "1K", "1K"); - test_format_bytes_one(1100, true, "1K", "1K", "1.1K", "1K"); - test_format_bytes_one(1500, true, "1.4K", "1K", "1.5K", "1K"); - test_format_bytes_one(UINT64_C(3)*1024*1024, true, "3M", "3M", "3.1M", "3M"); - test_format_bytes_one(UINT64_C(3)*1024*1024*1024, true, "3G", "3G", "3.2G", "3G"); - test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024, true, "3T", "3T", "3.2T", "3T"); - test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024, true, "3P", "3P", "3.3P", "3P"); - test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024*1024, true, "3E", "3E", "3.4E", "3E"); - test_format_bytes_one(UINT64_MAX, true, NULL, NULL, NULL, NULL); - test_format_bytes_one(UINT64_MAX, false, NULL, NULL, NULL, NULL); + test_format_bytes_one(900, true, "900B", "900B", "900B", "900B", "900B", "900B"); + test_format_bytes_one(900, false, "900", "900", "900", "900", "900", "900"); + test_format_bytes_one(1023, true, "1023B", "1023B", "1023B", "1K", "1K", "1.0K"); + test_format_bytes_one(1023, false, "1023", "1023", "1023", "1K", "1K", "1.0K"); + test_format_bytes_one(1024, true, "1K", "1K", "1.0K", "1K", "1K", "1.0K"); + test_format_bytes_one(1024, false, "1K", "1K", "1.0K", "1K", "1K", "1.0K"); + test_format_bytes_one(1100, true, "1K", "1K", "1.0K", "1.1K", "1K", "1.1K"); + test_format_bytes_one(1500, true, "1.4K", "1K", "1.4K", "1.5K", "1K", "1.5K"); + test_format_bytes_one(UINT64_C(3)*1024*1024, true, "3M", "3M", "3.0M", "3.1M", "3M", "3.1M"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024, true, "3G", "3G", "3.0G", "3.2G", "3G", "3.2G"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024, true, "3T", "3T", "3.0T", "3.2T", "3T", "3.2T"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024, true, "3P", "3P", "3.0P", "3.3P", "3P", "3.3P"); + test_format_bytes_one(UINT64_C(3)*1024*1024*1024*1024*1024*1024, true, "3E", "3E", "3.0E", "3.4E", "3E", "3.4E"); + test_format_bytes_one(UINT64_MAX, true, NULL, NULL, NULL, NULL, NULL, NULL); + test_format_bytes_one(UINT64_MAX, false, NULL, NULL, NULL, NULL, NULL, NULL); } DEFINE_TEST_MAIN(LOG_INFO);