parted: add max option to mkpart <end>
PATCH v2 1/1 parted: add max option to mkpart <end>
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.
---
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/[email protected]
--- commands/parted.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-)
commands/parted.c +35 -20
@@ -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,
Signature · 1 line
Maud Spierings <[email protected]>
Sascha Hauer
AppliedQuoted 9 lines · On Mon, 20 Oct 2025 19:34:06 +0200, Maud Spierings via B4 Relay wrote:
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
[...]
Applied, thanks!
[1/1] parted: add max option to mkpart <end>
https://git.pengutronix.de/cgit/barebox/commit/?id=1e03748aafd2 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>