summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2010-06-09 11:07:19 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2010-06-09 17:52:44 -0700
commit598c4856c0080d44085dd58f39a76ad0816843cf (patch)
tree0b1d79e5e0d2b3ba88a9733ee1e67b6442189918 /core
parenta556d59a601697857e8a034d97cb4347f766cddd (diff)
downloadsyslinux-598c4856c0080d44085dd58f39a76ad0816843cf.tar.gz
loadconfig: fold FAT pathname search into generic_load_config
Fold the FAT pathname searching into generic_load_config; make it a simple set of loops. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'core')
-rw-r--r--core/fs/fat/fat.c36
-rw-r--r--core/fs/lib/loadconfig.c51
2 files changed, 36 insertions, 51 deletions
diff --git a/core/fs/fat/fat.c b/core/fs/fat/fat.c
index 54cd3b57..6850993a 100644
--- a/core/fs/fat/fat.c
+++ b/core/fs/fat/fat.c
@@ -20,7 +20,6 @@ static struct inode * new_fat_inode(struct fs_info *fs)
return inode;
}
-
/*
* Check for a particular sector in the FAT cache
*/
@@ -697,39 +696,6 @@ got:
return 0;
}
-/* Load the config file, return 1 if failed, or 0 */
-static int vfat_load_config(void)
-{
- const char *search_directories[] = {
- "/boot/syslinux",
- "/syslinux",
- "/",
- NULL
- };
- com32sys_t regs;
- int i;
-
- /* If path filled by installer, then use that to load config*/
- if (*CurrentDirName && !generic_load_config())
- return 0;
-
- for (i = 0; search_directories[i]; i++) {
- memset(&regs, 0, sizeof regs);
- snprintf(ConfigName, FILENAME_MAX, "%s/syslinux.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;
-}
-
/* init. the fs meta data, return the block size in bits */
static int vfat_fs_init(struct fs_info *fs)
{
@@ -803,7 +769,7 @@ const struct fs_ops vfat_fs_ops = {
.getfssec = generic_getfssec,
.close_file = generic_close_file,
.mangle_name = vfat_mangle_name,
- .load_config = vfat_load_config,
+ .load_config = generic_load_config,
.readdir = vfat_readdir,
.iget_root = vfat_iget_root,
.iget = vfat_iget,
diff --git a/core/fs/lib/loadconfig.c b/core/fs/lib/loadconfig.c
index d84bdef9..c4876dd7 100644
--- a/core/fs/lib/loadconfig.c
+++ b/core/fs/lib/loadconfig.c
@@ -5,26 +5,45 @@
#include <fs.h>
/*
- * Standard version of load_config for extlinux/syslinux filesystems
+ * Standard version of load_config for extlinux/syslinux filesystems.
+ *
+ * This searches for extlinux.conf and syslinux.cfg in the install
+ * directory, followed by a set of fallback directories. If found,
+ * set the current working directory to match.
*/
int generic_load_config(void)
{
+ static const char *search_directories[] = {
+ NULL, /* CurrentDirName */
+ "/boot/syslinux",
+ "/syslinux",
+ "/",
+ NULL
+ };
+ static const char *filenames[] = {
+ "extlinux.conf",
+ "syslinux.cfg",
+ NULL
+ };
com32sys_t regs;
+ int i, j;
- chdir(CurrentDirName);
- /* try extlinux.conf first */
- realpath(ConfigName, "extlinux.conf", FILENAME_MAX);
- dprintf("Try config = %s\n", ConfigName);
- memset(&regs, 0, sizeof regs);
- regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
- call16(core_open, &regs, &regs);
- /* give syslinux.cfg a chance ? */
- if (regs.eflags.l & EFLAGS_ZF) {
- realpath(ConfigName, "syslinux.cfg", FILENAME_MAX);
- dprintf("Then try config = %s\n", ConfigName);
- memset(&regs, 0, sizeof regs);
- regs.edi.w[0] = OFFS_WRT(ConfigName, 0);
- call16(core_open, &regs, &regs);
+ search_directories[0] = CurrentDirName;
+
+ for (i = *CurrentDirName ? 0 : 1; search_directories[i]; i++) {
+ for (j = 0; filenames[j]; j++) {
+ memset(&regs, 0, sizeof regs);
+ snprintf(ConfigName, FILENAME_MAX, "%s/%s",
+ search_directories[i], filenames[j]);
+ 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 (regs.eflags.l & EFLAGS_ZF) ? -1 : 0;
+
+ return -1;
}