Skip to contentSkip to conversation

extlinux: resolve absolute paths against the partition root

PATCH Applied Stephano Cetola 2 participants 2 messages Aug 26 – Aug 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 extlinux: resolve absolute paths against the partition root

extlinux_boot() always joined a path with '/' against rootpath, which holds the config file's own directory, not the partition root. A KERNEL/INITRD/FDT value starting with '/', the normal syslinux way to name a path from the partition root, got treated as relative instead. The extlinux.conf file itself can live in a different directory than the partition root (extlinux_scan_directory() looks in both boot/extlinux/ and extlinux/), so this produced a wrong, nonexistent path whenever a config used an absolute KERNEL/INITRD/FDT entry.

Track the partition root and the config file's own directory as two separate fields, cfgdir and rootpath, and resolve a path against rootpath if it starts with '/', or cfgdir otherwise.

Fixes b912fa9fc3ca ("Add support for extlinux.conf")
---
 common/extlinux.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)
common/extlinux.c +21 -5
index caa62923da..7a92c15e4d 100644
@@ -17,6 +17,7 @@
 struct extlinux_entry {
 	struct bootentry entry;
 	char *rootpath;
+	char *cfgdir;
 	char *label;
 	char *kernel;
 	char *initrd;
@@ -25,6 +26,19 @@ struct extlinux_entry {
 	char *append;
 };
 
+/*
+ * A path starting with '/' is absolute and resolves against the
+ * partition root. Anything else is relative to the extlinux.conf
+ * file's own directory, per syslinux convention.
+ */
+static char *extlinux_make_abs(const char *rootpath, const char *cfgdir,
+				const char *relpath)
+{
+	if (relpath[0] == '/')
+		return basprintf("%s%s", rootpath, relpath);
+	return basprintf("%s/%s", cfgdir, relpath);
+}
+
 static int extlinux_boot(struct bootentry *entry, int verbose, int dryrun)
 {
 	struct extlinux_entry *e =
@@ -38,18 +52,18 @@ static int extlinux_boot(struct bootentry *entry, int verbose, int dryrun)
 	data.dryrun = max_t(int, dryrun, data.dryrun);
 	data.verbose = max(verbose, data.verbose);
 
-	kernel_abs = basprintf("%s/%s", e->rootpath, e->kernel);
+	kernel_abs = extlinux_make_abs(e->rootpath, e->cfgdir, e->kernel);
 	data.os_file = kernel_abs;
 
 	if (e->initrd) {
-		initrd_abs = basprintf("%s/%s", e->rootpath, e->initrd);
+		initrd_abs = extlinux_make_abs(e->rootpath, e->cfgdir, e->initrd);
 		data.initrd_file = initrd_abs;
 	}
 
 	if (e->fdt) {
-		char *fdtdir = e->fdtdir ? : e->rootpath;
+		char *fdtdir = e->fdtdir ? : e->cfgdir;
 
-		fdt_abs = basprintf("%s/%s", fdtdir, e->fdt);
+		fdt_abs = extlinux_make_abs(e->rootpath, fdtdir, e->fdt);
 		data.oftree_file = fdt_abs;
 	}
 
@@ -76,6 +90,7 @@ static void extlinux_entry_free(struct bootentry *entry)
 		container_of(entry, struct extlinux_entry, entry);
 
 	free(e->rootpath);
+	free(e->cfgdir);
 	free(e->label);
 	free(e->kernel);
 	free(e->initrd);
@@ -124,7 +139,8 @@ static struct extlinux_entry *parse_extlinux_conf(const char *abspath,
 			if (!strcmp(val, default_label)) {
 				entry = xzalloc(sizeof(*entry));
 				entry->label = xstrdup(val);
-				entry->rootpath = dirname(xstrdup(abspath));
+				entry->rootpath = xstrdup(rootpath);
+				entry->cfgdir = dirname(xstrdup(abspath));
 			} else if (entry) {
 				break;
 			}

---
base-commit: 9bc1a26592a59919d2ee8c60c273d87d3d9f2e81
change-id: 20260822-send-extlinux-abs-path-bd9809e3dda8

Applied
#1 lore raw
Quoted 10 lines · Stephano Cetola

extlinux_boot() always joined a path with '/' against rootpath, which holds the config file's own directory, not the partition root. A KERNEL/INITRD/FDT value starting with '/', the normal syslinux way to name a path from the partition root, got treated as relative instead. The extlinux.conf file itself can live in a different directory than the partition root (extlinux_scan_directory() looks in both boot/extlinux/ and extlinux/), so this produced a wrong, nonexistent path whenever a config used an absolute KERNEL/INITRD/FDT entry.

[...]

Applied, thanks!

[1/1] extlinux: resolve absolute paths against the partition root
https://git.pengutronix.de/cgit/barebox/commit/?id=1cbbf0e06cf2 (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>