/* autofs.c - support auto-loading from fs.lst */ /* * VasEBoot -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * VasEBoot 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. * * VasEBoot 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 VasEBoot. If not, see . */ #include #include #include #include #include #include /* 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; VasEBoot_file_filter_t VasEBoot_file_filters_was[VasEBoot_FILE_FILTER_MAX]; VasEBoot_memcpy (VasEBoot_file_filters_was, VasEBoot_file_filters_enabled, sizeof (VasEBoot_file_filters_enabled)); VasEBoot_memcpy (VasEBoot_file_filters_enabled, VasEBoot_file_filters_all, sizeof (VasEBoot_file_filters_enabled)); 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); } VasEBoot_memcpy (VasEBoot_file_filters_enabled, VasEBoot_file_filters_was, sizeof (VasEBoot_file_filters_enabled)); 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/" VasEBoot_TARGET_CPU "-" VasEBoot_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); 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 = VasEBoot_ERR_NONE; /* Set the hook. */ VasEBoot_fs_autoload_hook = autoload_fs_module; }