2N/A/* autofs.c - support auto-loading from fs.lst */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2009 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/mm.h>
2N/A#include <grub/dl.h>
2N/A#include <grub/env.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/fs.h>
2N/A#include <grub/normal.h>
2N/A
2N/A/* This is used to store the names of filesystem modules for auto-loading. */
2N/Astatic grub_named_list_t fs_module_list;
2N/A
2N/A/* The auto-loading hook for filesystems. */
2N/Astatic int
2N/Aautoload_fs_module (void)
2N/A{
2N/A grub_named_list_t p;
2N/A
2N/A while ((p = fs_module_list) != NULL)
2N/A {
2N/A if (! grub_dl_get (p->name) && grub_dl_load (p->name))
2N/A return 1;
2N/A
2N/A if (grub_errno)
2N/A grub_print_error ();
2N/A
2N/A fs_module_list = p->next;
2N/A grub_free (p->name);
2N/A grub_free (p);
2N/A }
2N/A
2N/A return 0;
2N/A}
2N/A
2N/A/* Read the file fs.lst for auto-loading. */
2N/Avoid
2N/Aread_fs_list (const char *prefix)
2N/A{
2N/A if (prefix)
2N/A {
2N/A char *filename;
2N/A
2N/A filename = grub_xasprintf ("%s/fs.lst", prefix);
2N/A if (filename)
2N/A {
2N/A grub_file_t file;
2N/A grub_fs_autoload_hook_t tmp_autoload_hook;
2N/A
2N/A /* This rules out the possibility that read_fs_list() is invoked
2N/A recursively when we call grub_file_open() below. */
2N/A tmp_autoload_hook = grub_fs_autoload_hook;
2N/A grub_fs_autoload_hook = NULL;
2N/A
2N/A file = grub_file_open (filename);
2N/A if (file)
2N/A {
2N/A /* Override previous fs.lst. */
2N/A while (fs_module_list)
2N/A {
2N/A grub_named_list_t tmp;
2N/A tmp = fs_module_list->next;
2N/A grub_free (fs_module_list);
2N/A fs_module_list = tmp;
2N/A }
2N/A
2N/A while (1)
2N/A {
2N/A char *buf;
2N/A char *p;
2N/A char *q;
2N/A grub_named_list_t fs_mod;
2N/A
2N/A buf = grub_file_getline (file);
2N/A if (! buf)
2N/A break;
2N/A
2N/A p = buf;
2N/A q = buf + grub_strlen (buf) - 1;
2N/A
2N/A /* Ignore space. */
2N/A while (grub_isspace (*p))
2N/A p++;
2N/A
2N/A while (p < q && grub_isspace (*q))
2N/A *q-- = '\0';
2N/A
2N/A /* If the line is empty, skip it. */
2N/A if (p >= q)
2N/A continue;
2N/A
2N/A fs_mod = grub_malloc (sizeof (*fs_mod));
2N/A if (! fs_mod)
2N/A continue;
2N/A
2N/A fs_mod->name = grub_strdup (p);
2N/A if (! fs_mod->name)
2N/A {
2N/A grub_free (fs_mod);
2N/A continue;
2N/A }
2N/A
2N/A fs_mod->next = fs_module_list;
2N/A fs_module_list = fs_mod;
2N/A }
2N/A
2N/A grub_file_close (file);
2N/A grub_fs_autoload_hook = tmp_autoload_hook;
2N/A }
2N/A
2N/A grub_free (filename);
2N/A }
2N/A }
2N/A
2N/A /* Ignore errors. */
2N/A grub_errno = GRUB_ERR_NONE;
2N/A
2N/A /* Set the hook. */
2N/A grub_fs_autoload_hook = autoload_fs_module;
2N/A}