From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 2/3] parted: align partitions to 1MiB
Date: Thu, 22 May 2025 15:40:23 +0200 [thread overview]
Message-ID: <20250522-parted-size-v1-2-369d146aa100@pengutronix.de> (raw)
In-Reply-To: <20250522-parted-size-v1-0-369d146aa100@pengutronix.de>
Common partitioning tools align partition start offsets and sizes to
1MiB. Do likewise in barebox parted to avoid unnecessary write
amplification due to unaligned partition starts.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/parted.c | 10 ++++++++--
include/partitions.h | 4 ++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/commands/parted.c b/commands/parted.c
index 68b056a0758a14e597d72f76cdc4ba6781a06051..221c6fc98601f1532ea85e000d1e2147f7a5af63 100644
--- a/commands/parted.c
+++ b/commands/parted.c
@@ -8,6 +8,7 @@
#include <linux/sizes.h>
#include <partitions.h>
#include <linux/math64.h>
+#include <range.h>
static struct partition_desc *gpdesc;
static bool table_needs_write;
@@ -160,13 +161,18 @@ static int do_mkpart(struct block_device *blk, int argc, char *argv[])
end *= mult;
/* If not on sector boundaries move start up and end down */
- start = ALIGN(start, SECTOR_SIZE);
- end = ALIGN_DOWN(end, SECTOR_SIZE);
+ start = ALIGN(start, SZ_1M);
+ end = ALIGN_DOWN(end, SZ_1M);
/* convert to LBA */
start >>= SECTOR_SHIFT;
end >>= SECTOR_SHIFT;
+ if (end == start) {
+ printf("Error: After alignment the partition has zero size\n");
+ return -EINVAL;
+ }
+
/*
* When unit is >= KB then substract one sector for user convenience.
* It allows to start the next partition where the previous ends
diff --git a/include/partitions.h b/include/partitions.h
index 7fd6899bd3b88f691385c330bb7900d9ec1547ac..dd3e631c5aa337d752312cd94be5e7dbb4f527a5 100644
--- a/include/partitions.h
+++ b/include/partitions.h
@@ -11,6 +11,7 @@
#include <filetype.h>
#include <linux/uuid.h>
#include <linux/list.h>
+#include <linux/sizes.h>
#define MAX_PARTITION 128
#define MAX_PARTITION_NAME 38
@@ -55,6 +56,9 @@ struct partition_parser {
const char *name;
};
+#define PARTITION_ALIGN_SIZE SZ_1M
+#define PARTITION_ALIGN_SECTORS (PARTITION_ALIGN_SIZE >> SECTOR_SHIFT)
+
void partition_desc_init(struct partition_desc *pd, struct block_device *blk);
int partition_parser_register(struct partition_parser *p);
struct partition_desc *partition_table_read(struct block_device *blk);
--
2.39.5
next prev parent reply other threads:[~2025-05-22 13:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 13:40 [PATCH 0/3] parted: add command to create partitions specifying the size Sascha Hauer
2025-05-22 13:40 ` [PATCH 1/3] partitions: add function to find free space on partition table Sascha Hauer
2025-05-22 13:40 ` Sascha Hauer [this message]
2025-05-22 13:40 ` [PATCH 3/3] parted: implement mkpart_size command Sascha Hauer
2025-05-26 13:48 ` [PATCH 0/3] parted: add command to create partitions specifying the size Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250522-parted-size-v1-2-369d146aa100@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox