From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ejo@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] commands: addpart: allow force creation of overlapping partition
Date: Fri, 20 Dec 2024 11:46:41 +0100 [thread overview]
Message-ID: <20241220104641.294328-1-a.fatoum@pengutronix.de> (raw)
While we have the guard rails for good reason, a user on the shell
should be able to override them and create partitions as they see fit,
e.g. if they have a MBR they don't care about anyway, it should still
be possible to force create a new fixed partition that overlaps it
and pass that to Fastboot for example.
Let's add a new -f (force) parameter that enables this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/Kconfig | 3 ++-
commands/partition.c | 8 ++++++--
include/cmdlinepart.h | 1 +
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/commands/Kconfig b/commands/Kconfig
index 7d45a13becd9..67116ec9fcf0 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -612,7 +612,7 @@ config CMD_PARTITION
help
addpart - add a partition description to a device
- Usage: addpart [-n] DEVICE PART
+ Usage: addpart [-nf] DEVICE PART
The size and the offset can be given in decimal (without any prefix) and
in hex (prefixed with 0x). Both can have an optional suffix K, M or G.
@@ -622,6 +622,7 @@ config CMD_PARTITION
Options:
-n do not use the device name as prefix of the partition name
+ -f force partition creation, even if it overlaps existing ones
DEVICE device being worked on
PART SIZE1[@OFFSET1](NAME1)[RO],SIZE2[@OFFSET2](NAME2)[RO],...
diff --git a/commands/partition.c b/commands/partition.c
index 1b655f853b3b..3176398497dc 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -33,11 +33,14 @@ static int do_addpart(int argc, char *argv[])
int opt;
unsigned int flags = CMDLINEPART_ADD_DEVNAME;
- while ((opt = getopt(argc, argv, "n")) > 0) {
+ while ((opt = getopt(argc, argv, "nf")) > 0) {
switch (opt) {
case 'n':
flags &= ~CMDLINEPART_ADD_DEVNAME;
break;
+ case 'f':
+ flags |= CMDLINEPART_FORCE;
+ break;
}
}
@@ -59,6 +62,7 @@ BAREBOX_CMD_HELP_START(addpart)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-n", "do not use the device name as prefix of the partition name")
+BAREBOX_CMD_HELP_OPT ("-f", "force partition creation, even if it overlaps existing ones")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Create partitions on device DEVICE using the partition description")
BAREBOX_CMD_HELP_TEXT("from PART.")
@@ -74,7 +78,7 @@ BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(addpart)
.cmd = do_addpart,
BAREBOX_CMD_DESC("add a partition description to a device")
- BAREBOX_CMD_OPTS("[-n] DEVICE PART")
+ BAREBOX_CMD_OPTS("[-nf] DEVICE PART")
BAREBOX_CMD_GROUP(CMD_GRP_PART)
BAREBOX_CMD_HELP(cmd_addpart_help)
BAREBOX_CMD_END
diff --git a/include/cmdlinepart.h b/include/cmdlinepart.h
index 9f5bdf610a11..1f9af22d3b76 100644
--- a/include/cmdlinepart.h
+++ b/include/cmdlinepart.h
@@ -3,6 +3,7 @@
#define __CMD_LINE_PART_H
#define CMDLINEPART_ADD_DEVNAME (1 << 0)
+#define CMDLINEPART_FORCE (1 << 1)
int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
const char **endp, loff_t *offset,
--
2.39.5
reply other threads:[~2024-12-20 12:25 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=20241220104641.294328-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=ejo@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