From: Maud Spierings via B4 Relay <devnull+maud_spierings.hotmail.com@kernel.org>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Maud Spierings <maud_spierings@hotmail.com>
Subject: [PATCH v2] parted: add max option to mkpart <end>
Date: Mon, 20 Oct 2025 19:34:06 +0200 [thread overview]
Message-ID: <20251020-parted-v2-1-63b8490ec9f4@hotmail.com> (raw)
From: Maud Spierings <maud_spierings@hotmail.com>
Add the option to specify "max" as the end location, this will fill the
block device up to the end of its available space.
A secondary effect is that it is now possible to use two different size
units for start and end
mkpart root ext4 66MiB 3866111KiB
previously it would read 66MiB as 66KiB as it only used the last read
unit.
Signed-off-by: Maud Spierings <maud_spierings@hotmail.com>
---
Changes in v2:
- Remove rounding down of the end point to the nearest MiB boundary
- remove the else if and make it the else continue to get rid of
assignment in if condition.
- Link to v1: https://lore.kernel.org/r/20251019-parted-v1-1-93b0501b40d9@hotmail.com
---
commands/parted.c | 55 +++++++++++++++++++++++++++++++++++--------------------
1 file changed, 35 insertions(+), 20 deletions(-)
diff --git a/commands/parted.c b/commands/parted.c
index 7ec56da4c15f..f03dc37c05b3 100644
--- a/commands/parted.c
+++ b/commands/parted.c
@@ -138,6 +138,10 @@ static int do_mkpart(struct block_device *blk, int argc, char *argv[])
int ret;
uint64_t mult;
+ pdesc = pdesc_get(blk);
+ if (!pdesc)
+ return -EINVAL;
+
if (argc < 5) {
printf("Error: Missing required arguments\n");
return -EINVAL;
@@ -150,40 +154,50 @@ static int do_mkpart(struct block_device *blk, int argc, char *argv[])
if (ret)
return ret;
- ret = parted_strtoull(argv[4], &end, &mult);
- if (ret)
- return ret;
-
if (!mult)
mult = gunit;
-
start *= mult;
- end *= mult;
- /* If not on sector boundaries move start up and end down */
+ /* If not on sector boundaries round start up */
start = ALIGN(start, SZ_1M);
- end = ALIGN_DOWN(end, SZ_1M);
/* convert to LBA */
start >>= SECTOR_SHIFT;
- end >>= SECTOR_SHIFT;
+
+ if (!strcmp(argv[4], "max")) {
+ /* gpt requires 34 blocks at the end */
+ if (pdesc->parser->type == filetype_gpt)
+ end = blk->num_blocks - 35;
+ else if (pdesc->parser->type == filetype_mbr)
+ end = blk->num_blocks - 1;
+ else
+ return -ENOSYS;
+ } else {
+ ret = parted_strtoull(argv[4], &end, &mult);
+ if (ret)
+ return ret;
+
+ if (!mult)
+ mult = gunit;
+ end *= mult;
+
+ /* convert to LBA */
+ end >>= SECTOR_SHIFT;
+
+ /*
+ * When unit is >= KB then subtract one sector for user
+ * convenience. It allows to start the next partition where the
+ * previous ends
+ */
+ if (mult >= 1000)
+ end -= 1;
+ }
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
- */
- if (mult >= 1000)
- end -= 1;
-
- pdesc = pdesc_get(blk);
- if (!pdesc)
- return -EINVAL;
-
ret = partition_create(pdesc, name, fs_type, start, end);
if (!ret)
@@ -424,6 +438,7 @@ BAREBOX_CMD_HELP_TEXT("<type> must be \"gpt\" or \"msdos\"")
BAREBOX_CMD_HELP_TEXT("<fstype> can be one of \"ext2\", \"ext3\", \"ext4\", \"fat16\", \"fat32\" or \"bbenv\"")
BAREBOX_CMD_HELP_TEXT("<name> for MBR partition tables can be one of \"primary\", \"extended\" or")
BAREBOX_CMD_HELP_TEXT("\"logical\". For GPT this is a name string.")
+BAREBOX_CMD_HELP_TEXT("<end> can be \"max\" it will take all remaining space")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(parted)
---
base-commit: 8defba1d0ab1aef9dd5d57710e18d0d02e2c48e2
change-id: 20251019-parted-b0d637580e80
Best regards,
--
Maud Spierings <maud_spierings@hotmail.com>
reply other threads:[~2025-10-20 17:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20251020-parted-v2-1-63b8490ec9f4@hotmail.com \
--to=devnull+maud_spierings.hotmail.com@kernel.org \
--cc=barebox@lists.infradead.org \
--cc=maud_spierings@hotmail.com \
--cc=s.hauer@pengutronix.de \
/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