mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] blspec: derive root prefix from blspec config path instead of mountpoint
@ 2025-11-14  5:00 chalianis1
  2025-11-14 10:11 ` Marco Felsch
  0 siblings, 1 reply; 4+ messages in thread
From: chalianis1 @ 2025-11-14  5:00 UTC (permalink / raw)
  To: s.hauer; +Cc: barebox, Chali Anis

From: Chali Anis <chalianis1@gmail.com>

Add get_prefix_path() to compute the filesystem prefix of a BLSpec
entry by locating the deepest /loader/entries/ component in the
configuration path. This ensures correct rootpath extraction for
nested loader directories, mixed path layouts, duplicate segments,
and paths without valid loader entries. If no prefix is found,
fall back to get_mounted_path().

Signed-off-by: Chali Anis <chalianis1@gmail.com>
---
 common/blspec.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/common/blspec.c b/common/blspec.c
index 80ebe256ceaf..ad94d4d6be64 100644
--- a/common/blspec.c
+++ b/common/blspec.c
@@ -391,6 +391,29 @@ static bool entry_is_match_machine_id(struct blspec_entry *entry)
 	return ret;
 }
 
+/*
+ * Return the path prefix before the deepest "/loader/entries/" component
+ * in @configname. Falls back to the mounted path if none is found.
+ */
+static char *get_blspec_prefix_path(char *configname)
+{
+	char *p;
+	char *scfg = configname;
+	char *save = NULL;
+
+	while ((p = strstr(scfg, "/loader/entries/")) != NULL) {
+		if (p - configname > 0)
+			save = p;
+
+		scfg = p + 1;
+	}
+
+	if (save && save - configname > 0)
+		return xstrndup(configname, save - configname);
+
+	return get_mounted_path(configname);
+}
+
 static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 			      const char *configname)
 {
@@ -404,7 +427,7 @@ static int __blspec_scan_file(struct bootentries *bootentries, const char *root,
 	if (IS_ERR(entry))
 		return PTR_ERR(entry);
 
-	root = root ?: get_mounted_path(configname);
+	root = root ?: get_blspec_prefix_path(configname);
 	entry->rootpath = xstrdup_const(root);
 	entry->configpath = xstrdup_const(configname);
 	entry->cdev = get_cdev_by_mountpath(root);
-- 
2.49.0




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

end of thread, other threads:[~2025-11-14 16:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-14  5:00 [PATCH] blspec: derive root prefix from blspec config path instead of mountpoint chalianis1
2025-11-14 10:11 ` Marco Felsch
2025-11-14 13:51   ` Ahmad Fatoum
     [not found]     ` <CAL+1fyCeZdxMhpDNYjpvbteGre+mgDi0pRyUn_24wUkKJa_+4w@mail.gmail.com>
2025-11-14 16:49       ` anis chali

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