mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP
@ 2025-02-16 15:07 Ahmad Fatoum
  2025-02-16 15:07 ` [PATCH 2/2] cmdlinepart: refuse partitions with empty name Ahmad Fatoum
  2025-02-17  7:36 ` [PATCH 1/2] cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-02-16 15:07 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

When a partition is created that's exactly the same size and offset as
an existing partition, barebox will create the new partition as link to
the existing partition.

Maintain this behavior, even if DEVFS_PARTITION_CAN_OVERLAP is set.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/devfs-core.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 133fd9ec026a..c9313ed73167 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -440,7 +440,7 @@ int devfs_remove(struct cdev *cdev)
 /**
  * check_overlap() - check overlap with existing partitions
  * @cdev: parent cdev
- * @name: partition name for informational purposes on conflict
+ * @partinfo: partition information
  * @offset: offset of new partition to be added
  * @size: size of new partition to be added
  *
@@ -448,7 +448,9 @@ int devfs_remove(struct cdev *cdev)
  *         partition if and only if it's identical in offset and size
  *         to an existing partition. Otherwise, PTR_ERR(-EINVAL).
  */
-static struct cdev *check_overlap(struct cdev *cdev, const char *name, loff_t offset, loff_t size)
+static struct cdev *check_overlap(struct cdev *cdev,
+				  const struct devfs_partition *partinfo,
+				  loff_t offset, loff_t size)
 {
 	struct cdev *cpart;
 	loff_t cpart_offset;
@@ -471,6 +473,8 @@ static struct cdev *check_overlap(struct cdev *cdev, const char *name, loff_t of
 		}
 
 		if (region_overlap_size(cpart_offset, cpart->size, offset, size)) {
+			if (partinfo->flags & DEVFS_PARTITION_CAN_OVERLAP)
+				return NULL;
 			ret = -EINVAL;
 			goto conflict;
 		}
@@ -483,7 +487,7 @@ static struct cdev *check_overlap(struct cdev *cdev, const char *name, loff_t of
 	__pr_printk(ret ? MSG_WARNING : MSG_DEBUG,
 		    "New partition %s (0x%08llx-0x%08llx) on %s "
 		    "%s with partition %s (0x%08llx-0x%08llx), not creating it\n",
-		    name, offset, offset + size - 1, cdev->name,
+		    partinfo->name, offset, offset + size - 1, cdev->name,
 		    ret ? "conflicts" : "identical",
 		    cpart->name, cpart_offset, cpart_offset + cpart->size - 1);
 
@@ -530,16 +534,14 @@ static struct cdev *__devfs_add_partition(struct cdev *cdev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	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;
+	overlap = check_overlap(cdev, partinfo, offset, size);
+	if (overlap) {
+		if (!IS_ERR(overlap)) {
+			/* only fails with -EEXIST, which is fine */
+			(void)devfs_create_link(overlap, partinfo->name);
 		}
+
+		return overlap;
 	}
 
 	/* Filter flags that we want to pass along to children */
-- 
2.39.5




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

end of thread, other threads:[~2025-02-17  7:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-16 15:07 [PATCH 1/2] cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP Ahmad Fatoum
2025-02-16 15:07 ` [PATCH 2/2] cmdlinepart: refuse partitions with empty name Ahmad Fatoum
2025-02-17  7:36 ` [PATCH 1/2] cdev: merge identical partitions despite DEVFS_PARTITION_CAN_OVERLAP Sascha Hauer

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