From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ejo@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH RESEND 1/2] cdev: allow overriding partition overlap check
Date: Fri, 20 Dec 2024 11:52:12 +0100 [thread overview]
Message-ID: <20241220105213.297539-1-a.fatoum@pengutronix.de> (raw)
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>
---
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
next reply other threads:[~2024-12-20 11:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 10:52 Ahmad Fatoum [this message]
2024-12-20 10:52 ` [PATCH RESEND 2/2] commands: addpart: allow force creation of overlapping partition Ahmad Fatoum
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=20241220105213.297539-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