[syslinux:elflink] ldlinux: PATH-based module lookup

syslinux-bot for Matt Fleming matt.fleming at linux.intel.com
Tue Jul 12 20:03:17 PDT 2011


Commit-ID:  ef3cb76bffc52b40b9a013f5b16835e062a5db4b
Gitweb:     http://syslinux.zytor.com/commit/ef3cb76bffc52b40b9a013f5b16835e062a5db4b
Author:     Matt Fleming <matt.fleming at linux.intel.com>
AuthorDate: Mon, 6 Jun 2011 11:09:42 +0100
Committer:  Matt Fleming <matt.fleming at linux.intel.com>
CommitDate: Mon, 6 Jun 2011 11:09:42 +0100

ldlinux: PATH-based module lookup

Add support for specifying directories to search when loading
modules. A new config directive, "PATH", instructs the module loading
code to search the directories listed in a colon-separated list when
loading a module.

Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com>


---
 com32/elflink/ldlinux/readconfig.c |   18 ++++++++++++++++++
 com32/lib/sys/module/common.c      |   35 ++++++++++++++++++++++++++++++++++-
 core/fs/fs.c                       |    2 ++
 core/include/fs.h                  |    2 ++
 mk/lib.mk                          |    3 ++-
 5 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index 8ded92a..067b370 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -23,6 +23,7 @@
 #include <syslinux/adv.h>
 #include <syslinux/config.h>
 #include <dprintf.h>
+#include <fs.h>
 
 #include "menu.h"
 #include "config.h"
@@ -1132,6 +1133,23 @@ do_include:
 
 	} else if (looking_at(p, "say")) {
 		printf("%s\n", p + 4);
+	} else if (looking_at(p, "path")) {
+		/* PATH-based lookup */
+		char *new_path, *_p;
+		size_t len, new_len;
+
+		new_path = refstrdup(skipspace(p + 4));
+		len = strlen(PATH);
+		new_len = strlen(new_path);
+		_p = realloc(PATH, len + new_len + 2);
+		if (_p) {
+			strncpy(_p, PATH, len);
+			_p[len++] = ':';
+			strncpy(_p + len, new_path, new_len);
+			_p[len + new_len] = '\0';
+			PATH = _p;
+		} else
+			printf("Failed to realloc PATH\n");
 	}
     }
 }
diff --git a/com32/lib/sys/module/common.c b/com32/lib/sys/module/common.c
index 431f5cd..1afdbf5 100644
--- a/com32/lib/sys/module/common.c
+++ b/com32/lib/sys/module/common.c
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <elf.h>
 #include <string.h>
+#include <fs.h>
 
 #include <linux/list.h>
 #include <sys/module.h>
@@ -56,13 +57,45 @@ void print_elf_symbols(struct elf_module *module) {
 }
 #endif //ELF_DEBUG
 
+static FILE *findpath(char *name)
+{
+	char path[FILENAME_MAX];
+	FILE *f;
+	char *p, *n;
+	int i;
+
+	p = PATH;
+again:
+	i = 0;
+	while (*p && *p != ':' && i < FILENAME_MAX) {
+		path[i++] = *p++;
+	}
+
+	if (*p == ':')
+		p++;
+
+	n = name;
+	while (*n && i < FILENAME_MAX)
+		path[i++] = *n++;
+	path[i] = '\0';
+
+	f = fopen(path, "rb");
+	if (f)
+		return f;
+
+	if (p >= PATH && p < PATH + strlen(PATH))
+		goto again;
+
+	return NULL;
+}
+
 /*
  * Image files manipulation routines
  */
 
 int image_load(struct elf_module *module)
 {
-	module->u.l._file = fopen(module->name, "rb");
+	module->u.l._file = findpath(module->name);
 
 	if (module->u.l._file == NULL) {
 		DBG_PRINT("Could not open object file '%s'\n", module->name);
diff --git a/core/fs/fs.c b/core/fs/fs.c
index 39ba09e..c743dca 100644
--- a/core/fs/fs.c
+++ b/core/fs/fs.c
@@ -6,6 +6,8 @@
 #include "fs.h"
 #include "cache.h"
 
+char *PATH = "/:/bin/";
+
 /* The currently mounted filesystem */
 struct fs_info *this_fs = NULL;		/* Root filesystem */
 
diff --git a/core/include/fs.h b/core/include/fs.h
index e9e4548..04451ed 100644
--- a/core/include/fs.h
+++ b/core/include/fs.h
@@ -178,6 +178,8 @@ static inline struct file *handle_to_file(uint16_t handle)
     return handle ? &files[handle-1] : NULL;
 }
 
+extern char *PATH;
+
 /* fs.c */
 void pm_mangle_name(com32sys_t *);
 void pm_searchdir(com32sys_t *);
diff --git a/mk/lib.mk b/mk/lib.mk
index 1792ea1..604b91a 100644
--- a/mk/lib.mk
+++ b/mk/lib.mk
@@ -32,7 +32,8 @@ LIBFLAGS = -DDYNAMIC_CRC_TABLE -DPNG_NO_CONSOLE_IO \
 # LIBFLAGS += -DPNG_NO_FLOATING_POINT_SUPPORTED
 
 REQFLAGS  = $(GCCOPT) -g -mregparm=3 -DREGPARM=3 -D__COM32__ \
-	    -nostdinc -iwithprefix include -I. -I./sys -I../include
+	    -nostdinc -iwithprefix include -I. -I./sys -I../include \
+	    -I../../core/include
 OPTFLAGS  = -Os -march=i386 -falign-functions=0 -falign-jumps=0 \
 	    -falign-labels=0 -ffast-math -fomit-frame-pointer
 WARNFLAGS = $(GCCWARN) -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline



More information about the Syslinux-commits mailing list