summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2010-07-02 16:13:44 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2010-07-02 16:13:44 -0700
commit92371f2735d9dd82adfa6c16ef65a27f9263da7c (patch)
tree609cbcf4f5c6f21a4c09b20ad7a44f9596d8a3c3
parentf88518c9b3538b229bc4e877fcc64a5e1515da8b (diff)
downloadsyslinux-92371f2735d9dd82adfa6c16ef65a27f9263da7c.tar.gz
syslinux-92371f2735d9dd82adfa6c16ef65a27f9263da7c.tar.xz
syslinux-92371f2735d9dd82adfa6c16ef65a27f9263da7c.zip
core: merge the configfile-searching code, isolinux generic names
Merge the config file searching code between syslinux and isolinux, and make isolinux also recognize the generic names "syslinux" and "syslinux.cfg". Thus, isolinux now searches for configuration files in the following order: /boot/isolinux/isolinux.cfg /boot/isolinux/syslinux.cfg /isolinux/isolinux.cfg /isolinux/syslinux.cfg /boot/syslinux/isolinux.cfg /boot/syslinux/syslinux.cfg /syslinux/isolinux.cfg /syslinux/syslinux.cfg /isolinux.cfg /syslinux.cfg Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--core/fs/iso9660/iso9660.c29
-rw-r--r--core/fs/lib/loadconfig.c52
-rw-r--r--core/include/fs.h1
3 files changed, 40 insertions, 42 deletions
diff --git a/core/fs/iso9660/iso9660.c b/core/fs/iso9660/iso9660.c
index d695e439..62137d0d 100644
--- a/core/fs/iso9660/iso9660.c
+++ b/core/fs/iso9660/iso9660.c
@@ -273,30 +273,21 @@ static int iso_readdir(struct file *file, struct dirent *dirent)
/* Load the config file, return 1 if failed, or 0 */
static int iso_load_config(void)
{
- const char *search_directories[] = {
+ static const char *search_directories[] = {
"/boot/isolinux",
"/isolinux",
+ "/boot/syslinux",
+ "/syslinux",
"/",
NULL
};
- com32sys_t regs;
- int i;
-
- for (i = 0; search_directories[i]; i++) {
- memset(&regs, 0, sizeof regs);
- snprintf(ConfigName, FILENAME_MAX, "%s/isolinux.cfg",
- search_directories[i]);
- regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
- call16(core_open, &regs, &regs);
- if (!(regs.eflags.l & EFLAGS_ZF))
- break;
- }
- if (!search_directories[i])
- return -1;
-
- /* Set the current working directory */
- chdir(search_directories[i]);
- return 0;
+ static const char *filenames[] = {
+ "isolinux.cfg",
+ "syslinux.cfg",
+ NULL
+ };
+
+ return search_config(search_directories, filenames);
}
static int iso_fs_init(struct fs_info *fs)
diff --git a/core/fs/lib/loadconfig.c b/core/fs/lib/loadconfig.c
index db538b87..c2fd9721 100644
--- a/core/fs/lib/loadconfig.c
+++ b/core/fs/lib/loadconfig.c
@@ -4,6 +4,34 @@
#include <core.h>
#include <fs.h>
+int search_config(const char *search_directories[], const char *filenames[])
+{
+ char confignamebuf[FILENAME_MAX];
+ com32sys_t regs;
+ const char *sd, **sdp;
+ const char *sf, **sfp;
+
+ for (sdp = search_directories; (sd = *sdp); sdp++) {
+ for (sfp = filenames; (sf = *sfp); sfp++) {
+ memset(&regs, 0, sizeof regs);
+ snprintf(confignamebuf, sizeof confignamebuf,
+ "%s%s%s",
+ sd, (*sd && sd[strlen(sd)-1] == '/') ? "" : "/",
+ sf);
+ realpath(ConfigName, confignamebuf, FILENAME_MAX);
+ regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
+ dprintf("Config search: %s\n", ConfigName);
+ call16(core_open, &regs, &regs);
+ if (!(regs.eflags.l & EFLAGS_ZF)) {
+ chdir(sd);
+ return 0; /* Got it */
+ }
+ }
+ }
+
+ return -1;
+}
+
/*
* Standard version of load_config for extlinux/syslinux filesystems.
*
@@ -13,7 +41,6 @@
*/
int generic_load_config(void)
{
- char confignamebuf[FILENAME_MAX];
static const char *search_directories[] = {
NULL, /* CurrentDirName */
"/boot/syslinux",
@@ -26,31 +53,10 @@ int generic_load_config(void)
"syslinux.cfg",
NULL
};
- com32sys_t regs;
- int i, j;
search_directories[0] = CurrentDirName;
dprintf("CurrentDirName: \"%s\"\n", CurrentDirName);
- for (i = *CurrentDirName ? 0 : 1; search_directories[i]; i++) {
- const char *sd = search_directories[i];
- for (j = 0; filenames[j]; j++) {
- memset(&regs, 0, sizeof regs);
- snprintf(confignamebuf, sizeof confignamebuf,
- "%s%s%s",
- sd, (*sd && sd[strlen(sd)-1] == '/') ? "" : "/",
- filenames[j]);
- realpath(ConfigName, confignamebuf, FILENAME_MAX);
- regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
- dprintf("Config search: %s\n", ConfigName);
- call16(core_open, &regs, &regs);
- if (!(regs.eflags.l & EFLAGS_ZF)) {
- chdir(search_directories[i]);
- return 0; /* Got it */
- }
- }
- }
-
- return -1;
+ return search_config(search_directories, filenames);
}
diff --git a/core/include/fs.h b/core/include/fs.h
index a01f9984..da247a98 100644
--- a/core/include/fs.h
+++ b/core/include/fs.h
@@ -213,6 +213,7 @@ char *getcwd(char *buf, size_t size);
void generic_mangle_name(char *, const char *);
/* loadconfig.c */
+int search_config(const char *search_directores[], const char *filenames[]);
int generic_load_config(void);
/* close.c */