mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] cdev: allow overriding partition overlap check
@ 2025-01-06  9:00 Ahmad Fatoum
  2025-01-06  9:00 ` [PATCH v2 2/2] commands: addpart: allow force creation of overlapping partition Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH v2 1/2] cdev: allow overriding partition overlap check Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

barebox will refuse to create overlapping partitions that are not
completely identical to an existing one.

The user on the shell may still want to allocate partitions that are
known to overlap, e.g. because they place multiple fixed partition into
one MBR partition or because we want to operate as a part of a cdev
interactively as if it were once device.

Don't preclude such use cases by adding a flag that just disables
overlap checks.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - allow force creation of partition at offset 0
---
 fs/devfs-core.c  | 16 +++++++++-------
 include/driver.h |  1 +
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 0651be3d8fc4..133fd9ec026a 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -530,14 +530,16 @@ static struct cdev *__devfs_add_partition(struct cdev *cdev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	overlap = check_overlap(cdev, partinfo->name, offset, size);
-	if (overlap) {
-		if (!IS_ERR(overlap)) {
-			/* only fails with -EEXIST, which is fine */
-			(void)devfs_create_link(overlap, partinfo->name);
-		}
+	if (!(partinfo->flags & DEVFS_PARTITION_CAN_OVERLAP)) {
+		overlap = check_overlap(cdev, partinfo->name, offset, size);
+		if (overlap) {
+			if (!IS_ERR(overlap)) {
+				/* only fails with -EEXIST, which is fine */
+				(void)devfs_create_link(overlap, partinfo->name);
+			}
 
-		return overlap;
+			return overlap;
+		}
 	}
 
 	/* Filter flags that we want to pass along to children */
diff --git a/include/driver.h b/include/driver.h
index 3aef385bc837..267e34294511 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -583,6 +583,7 @@ extern struct list_head cdev_list;
 #define DEVFS_PARTITION_BOOTABLE_ESP	(1U << 12)
 #define DEVFS_PARTITION_FOR_FIXUP	(1U << 13)
 #define DEVFS_WRITE_AUTOERASE		(1U << 14)
+#define DEVFS_PARTITION_CAN_OVERLAP	(1U << 15)
 
 /**
  * cdev_write_requires_erase - Check whether writes must be done to erased blocks
-- 
2.39.5




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] commands: addpart: allow force creation of overlapping partition
  2025-01-06  9:00 [PATCH v2 1/2] cdev: allow overriding partition overlap check Ahmad Fatoum
@ 2025-01-06  9:00 ` Ahmad Fatoum
  2025-01-06  9:18 ` [PATCH v2 1/2] cdev: allow overriding partition overlap check Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-01-06  9:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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>
---
v1 -> v2:
  - actually translate CMDLINEPART_FORCE to DEVFS_PARTITION_CAN_OVERLAP
---
 commands/Kconfig      | 3 ++-
 commands/partition.c  | 8 ++++++--
 include/cmdlinepart.h | 1 +
 lib/cmdlinepart.c     | 3 +++
 4 files changed, 12 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,
diff --git a/lib/cmdlinepart.c b/lib/cmdlinepart.c
index f1bfda641c1c..afba544965b4 100644
--- a/lib/cmdlinepart.c
+++ b/lib/cmdlinepart.c
@@ -77,6 +77,9 @@ int cmdlinepart_do_parse_one(const char *devname, const char *partstr,
 		end = (char *)(partstr + 2);
 	}
 
+	if (partition_flags & CMDLINEPART_FORCE)
+		flags |= DEVFS_PARTITION_CAN_OVERLAP;
+
 	if (endp)
 		*endp = end;
 
-- 
2.39.5




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2] cdev: allow overriding partition overlap check
  2025-01-06  9:00 [PATCH v2 1/2] cdev: allow overriding partition overlap check Ahmad Fatoum
  2025-01-06  9:00 ` [PATCH v2 2/2] commands: addpart: allow force creation of overlapping partition Ahmad Fatoum
@ 2025-01-06  9:18 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-01-06  9:18 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 06 Jan 2025 10:00:47 +0100, Ahmad Fatoum wrote:
> barebox will refuse to create overlapping partitions that are not
> completely identical to an existing one.
> 
> The user on the shell may still want to allocate partitions that are
> known to overlap, e.g. because they place multiple fixed partition into
> one MBR partition or because we want to operate as a part of a cdev
> interactively as if it were once device.
> 
> [...]

Applied, thanks!

[1/2] cdev: allow overriding partition overlap check
      https://git.pengutronix.de/cgit/barebox/commit/?id=c87254a2fd50 (link may not be stable)
[2/2] commands: addpart: allow force creation of overlapping partition
      https://git.pengutronix.de/cgit/barebox/commit/?id=80128b38547e (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-06  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-06  9:00 [PATCH v2 1/2] cdev: allow overriding partition overlap check Ahmad Fatoum
2025-01-06  9:00 ` [PATCH v2 2/2] commands: addpart: allow force creation of overlapping partition Ahmad Fatoum
2025-01-06  9:18 ` [PATCH v2 1/2] cdev: allow overriding partition overlap check Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox