[PATCH v2 2/4] parted: add support for gpt-location
Marco Felsch
m.felsch at pengutronix.de
Wed Apr 23 07:09:11 PDT 2025
Add support to place the GPT partition entries to random places instead
of LBA2.
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
v2:
- new
commands/parted.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/commands/parted.c b/commands/parted.c
index 90cee1ede10e..895c06524d4c 100644
--- a/commands/parted.c
+++ b/commands/parted.c
@@ -224,6 +224,30 @@ static int do_mklabel(struct block_device *blk, int argc, char *argv[])
return -EINVAL;
}
+ if (argc == 3) {
+ uint64_t mult;
+ int ret;
+
+ if (!strcmp(argv[1], "msdos")) {
+ printf("gpt-location not supported for msdos partitions\n");
+ return -EINVAL;
+ }
+
+ ret = parted_strtoull(argv[2], &gpt_location, &mult);
+ if (ret)
+ return ret;
+
+ if (!mult)
+ mult = gunit;
+
+ gpt_location *= mult;
+
+ /* Ensure alignment */
+ gpt_location = ALIGN(gpt_location, SECTOR_SIZE);
+ /* convert to LBA */
+ gpt_location >>= SECTOR_SHIFT;
+ }
+
pdesc = partition_table_new(blk, argv[1], gpt_location);
if (IS_ERR(pdesc)) {
printf("Error: Cannot create partition table: %pe\n", pdesc);
@@ -236,7 +260,7 @@ static int do_mklabel(struct block_device *blk, int argc, char *argv[])
partition_table_free(gpdesc);
gpdesc = pdesc;
- return 2;
+ return argc > 2 ? 3 : 2;
}
static int do_refresh(struct block_device *blk, int argc, char *argv[])
@@ -352,7 +376,7 @@ BAREBOX_CMD_HELP_TEXT("GNU Parted")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("commands:")
BAREBOX_CMD_HELP_OPT ("print", "print partitions")
-BAREBOX_CMD_HELP_OPT ("mklabel <type>", "create a new partition table")
+BAREBOX_CMD_HELP_OPT ("mklabel <type> <gpt-location>", "create a new partition table")
BAREBOX_CMD_HELP_OPT ("rm <num>", "remove a partition")
BAREBOX_CMD_HELP_OPT ("mkpart <name> <fstype> <start> <end>", "create a new partition")
BAREBOX_CMD_HELP_OPT ("unit <unit>", "change display/input units")
@@ -361,6 +385,7 @@ BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("<unit> can be one of \"s\" (sectors), \"B\" (bytes), \"kB\", \"MB\", \"GB\", \"TB\",")
BAREBOX_CMD_HELP_TEXT("\"KiB\", \"MiB\", \"GiB\" or \"TiB\"")
BAREBOX_CMD_HELP_TEXT("<type> must be \"gpt\" or \"msdos\"")
+BAREBOX_CMD_HELP_TEXT("<gpt-location> Location of the GPT table, ignored for MBR. Specified in <unit> size.")
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.")
--
2.39.5
More information about the barebox
mailing list