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@xxxxxxxxxxxxxx> --- v0 -> v1 RESEND: - actually send out both patches --- fs/devfs-core.c | 23 +++++++++++++++-------- include/driver.h | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/fs/devfs-core.c b/fs/devfs-core.c index 0651be3d8fc4..b143620ba2a0 100644 --- a/fs/devfs-core.c +++ b/fs/devfs-core.c @@ -493,11 +493,11 @@ static struct cdev *check_overlap(struct cdev *cdev, const char *name, loff_t of static struct cdev *__devfs_add_partition(struct cdev *cdev, const struct devfs_partition *partinfo, loff_t *end) { + unsigned inherited_flags = partinfo->flags; loff_t offset, size; loff_t _end = end ? *end : 0; static struct cdev *new; struct cdev *overlap; - unsigned inherited_flags = 0; if (cdev_by_name(partinfo->name)) return ERR_PTR(-EEXIST); @@ -530,14 +530,21 @@ 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); + /* DEVFS_PARTITION_CAN_OVERLAP is only allowed for partitions that have + * a defined offset. Everything else must pass the overlap check + */ + if (!(partinfo->offset > 0 && (inherited_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; + inherited_flags &= ~DEVFS_PARTITION_CAN_OVERLAP; } /* Filter flags that we want to pass along to children */ @@ -547,7 +554,7 @@ static struct cdev *__devfs_add_partition(struct cdev *cdev, struct mtd_info *mtd; mtd = mtd_add_partition(cdev->mtd, offset, size, - partinfo->flags | inherited_flags, partinfo->name); + inherited_flags, partinfo->name); if (IS_ERR(mtd)) return (void *)mtd; 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