From 118cccf97fa39e46a8f84f57c8bb73bb436e74b0 Mon Sep 17 00:00:00 2001 From: scarlet-storm <12461256+scarlet-storm@users.noreply.github.com> Date: Fri, 27 Dec 2024 21:34:36 +0530 Subject: [PATCH] homework: Align partitions to 1MiB Align partitions to 1MiB for consistency with regular partition tools which use 1MiB alignment by default --- src/home/homework-luks.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/home/homework-luks.c b/src/home/homework-luks.c index 44f020d8ae4..3ee16fe8159 100644 --- a/src/home/homework-luks.c +++ b/src/home/homework-luks.c @@ -66,16 +66,16 @@ #include "user-record.h" #include "user-util.h" -/* Round down to the nearest 4K size. Given that newer hardware generally prefers 4K sectors, let's align our - * partitions to that too. In the worst case we'll waste 3.5K per partition that way, but I think I can live +/* Round down to the nearest 1 MiB size. Given that most tools generally align partitions to 1 MiB boundaries, let's align our + * partitions to that too. In the worst case we'll waste 1 MiB per partition that way, but I think I can live * with that. */ -#define DISK_SIZE_ROUND_DOWN(x) ((x) & ~UINT64_C(4095)) +#define DISK_SIZE_ROUND_DOWN(x) ((x) & ~(U64_MB - 1)) -/* Rounds up to the nearest 4K boundary. Returns UINT64_MAX on overflow */ +/* Rounds up to the nearest 1 MiB boundary. Returns UINT64_MAX on overflow */ #define DISK_SIZE_ROUND_UP(x) \ ({ \ uint64_t _x = (x); \ - _x > UINT64_MAX - 4095U ? UINT64_MAX : (_x + 4095U) & ~UINT64_C(4095); \ + _x > UINT64_MAX - (U64_MB - 1) ? UINT64_MAX : (DISK_SIZE_ROUND_DOWN(_x + U64_MB - 1)); \ }) /* How much larger will the image on disk be than the fs inside it, i.e. the space we pay for the GPT and -- 2.47.3