summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2021-10-11 09:30:25 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-10-12 10:41:09 +0200
commit7f9f45b9bfef2ce8706f25c46dcbd109e4181164 (patch)
tree609b77c80282ce58adb850ab7920ac04c1e6cdb9 /common
parentf246029ca6949b25a94ad7acd76241125da76b29 (diff)
downloadbarebox-7f9f45b9bfef2ce8706f25c46dcbd109e4181164.tar.gz
barebox-7f9f45b9bfef2ce8706f25c46dcbd109e4181164.tar.xz
devfs: Do not create overlapping partitions
Until now it has been possible to create overlapping partitions. Go away from that and allow to create partitions only in unallocated areas of a device. This lowers the risk of having inconsistent partitioning and increases the chance that inconsistent partitioning is recognized by the user. We had explicit overlap checking for the environment partition which becomes unnecessary with this change and is removed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20211011073025.4187545-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/startup.c70
1 files changed, 1 insertions, 69 deletions
diff --git a/common/startup.c b/common/startup.c
index f72902fc53..f53b73f81a 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -68,70 +68,6 @@ static int mount_root(void)
fs_initcall(mount_root);
#endif
-#ifdef CONFIG_ENV_HANDLING
-static bool region_overlap(loff_t starta, loff_t lena,
- loff_t startb, loff_t lenb)
-{
- if (starta + lena <= startb)
- return 0;
- if (startb + lenb <= starta)
- return 0;
- return 1;
-}
-
-static int check_overlap(const char *path)
-{
- struct cdev *cenv, *cdisk, *cpart;
- const char *name;
-
- name = devpath_to_name(path);
-
- if (name == path)
- /*
- * no /dev/ in front, so *path is some file. No need to
- * check further.
- */
- return 0;
-
- cenv = cdev_by_name(name);
- if (!cenv)
- return -EINVAL;
-
- if (cenv->mtd)
- return 0;
-
- cdisk = cenv->master;
-
- if (!cdisk)
- return 0;
-
- list_for_each_entry(cpart, &cdisk->partitions, partition_entry) {
- if (cpart == cenv)
- continue;
-
- if (region_overlap(cpart->offset, cpart->size,
- cenv->offset, cenv->size))
- goto conflict;
- }
-
- return 0;
-
-conflict:
- pr_err("Environment partition (0x%08llx-0x%08llx) "
- "overlaps with partition %s (0x%08llx-0x%08llx), not using it\n",
- cenv->offset, cenv->offset + cenv->size - 1,
- cpart->name,
- cpart->offset, cpart->offset + cpart->size - 1);
-
- return -EINVAL;
-}
-#else
-static int check_overlap(const char *path)
-{
- return 0;
-}
-#endif
-
static int load_environment(void)
{
const char *default_environment_path;
@@ -143,11 +79,7 @@ static int load_environment(void)
defaultenv_load("/env", 0);
if (IS_ENABLED(CONFIG_ENV_HANDLING)) {
- ret = check_overlap(default_environment_path);
- if (ret)
- default_environment_path_set(NULL);
- else
- envfs_load(default_environment_path, "/env", 0);
+ envfs_load(default_environment_path, "/env", 0);
} else {
if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT))
pr_notice("No support for persistent environment. Using default environment\n");