vaseboot/VasEBoot-core/normal/autofs.c

149 lines
3.4 KiB
C

/* autofs.c - support auto-loading from fs.lst */
/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#include <VasEBoot/mm.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/env.h>
#include <VasEBoot/misc.h>
#include <VasEBoot/fs.h>
#include <VasEBoot/normal.h>
/* This is used to store the names of filesystem modules for auto-loading. */
static VasEBoot_named_list_t fs_module_list;
/* The auto-loading hook for filesystems. */
static int
autoload_fs_module (void)
{
VasEBoot_named_list_t p;
int ret = 0;
while ((p = fs_module_list) != NULL)
{
if (! VasEBoot_dl_get (p->name) && VasEBoot_dl_load (p->name))
{
ret = 1;
break;
}
if (VasEBoot_errno)
VasEBoot_print_error ();
fs_module_list = p->next;
VasEBoot_free (p->name);
VasEBoot_free (p);
}
return ret;
}
/* Read the file fs.lst for auto-loading. */
void
read_fs_list (const char *prefix)
{
if (prefix)
{
char *filename;
filename = VasEBoot_xasprintf ("%s/" VAS_EBOOT_TARGET_CPU "-" VAS_EBOOT_PLATFORM
"/fs.lst", prefix);
if (filename)
{
VasEBoot_file_t file;
VasEBoot_fs_autoload_hook_t tmp_autoload_hook;
/* This rules out the possibility that read_fs_list() is invoked
recursively when we call VasEBoot_file_open() below. */
tmp_autoload_hook = VasEBoot_fs_autoload_hook;
VasEBoot_fs_autoload_hook = NULL;
file = VasEBoot_file_open (filename, VAS_EBOOT_FILE_TYPE_VAS_EBOOT_MODULE_LIST);
if (file)
{
/* Override previous fs.lst. */
while (fs_module_list)
{
VasEBoot_named_list_t tmp;
tmp = fs_module_list->next;
VasEBoot_free (fs_module_list);
fs_module_list = tmp;
}
while (1)
{
char *buf;
char *p;
char *q;
VasEBoot_named_list_t fs_mod;
buf = VasEBoot_file_getline (file);
if (! buf)
break;
p = buf;
q = buf + VasEBoot_strlen (buf) - 1;
/* Ignore space. */
while (VasEBoot_isspace (*p))
p++;
while (p < q && VasEBoot_isspace (*q))
*q-- = '\0';
/* If the line is empty, skip it. */
if (p >= q)
{
VasEBoot_free (buf);
continue;
}
fs_mod = VasEBoot_malloc (sizeof (*fs_mod));
if (! fs_mod)
{
VasEBoot_free (buf);
continue;
}
fs_mod->name = VasEBoot_strdup (p);
VasEBoot_free (buf);
if (! fs_mod->name)
{
VasEBoot_free (fs_mod);
continue;
}
fs_mod->next = fs_module_list;
fs_module_list = fs_mod;
}
VasEBoot_file_close (file);
VasEBoot_fs_autoload_hook = tmp_autoload_hook;
}
VasEBoot_free (filename);
}
}
/* Ignore errors. */
VasEBoot_errno = VAS_EBOOT_ERR_NONE;
/* Set the hook. */
VasEBoot_fs_autoload_hook = autoload_fs_module;
}