Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / normal / autofs.c
blob721b9c3256db793da31ab9c51ed7a3d688baf91e
1 /* autofs.c - support auto-loading from fs.lst */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/mm.h>
21 #include <grub/dl.h>
22 #include <grub/env.h>
23 #include <grub/misc.h>
24 #include <grub/fs.h>
25 #include <grub/normal.h>
27 /* This is used to store the names of filesystem modules for auto-loading. */
28 static grub_named_list_t fs_module_list;
30 /* The auto-loading hook for filesystems. */
31 static int
32 autoload_fs_module (void)
34 grub_named_list_t p;
35 int ret = 0;
36 grub_file_filter_t grub_file_filters_was[GRUB_FILE_FILTER_MAX];
38 grub_memcpy (grub_file_filters_was, grub_file_filters_enabled,
39 sizeof (grub_file_filters_enabled));
40 grub_memcpy (grub_file_filters_enabled, grub_file_filters_all,
41 sizeof (grub_file_filters_enabled));
43 while ((p = fs_module_list) != NULL)
45 if (! grub_dl_get (p->name) && grub_dl_load (p->name))
47 ret = 1;
48 break;
51 if (grub_errno)
52 grub_print_error ();
54 fs_module_list = p->next;
55 grub_free (p->name);
56 grub_free (p);
59 grub_memcpy (grub_file_filters_enabled, grub_file_filters_was,
60 sizeof (grub_file_filters_enabled));
62 return ret;
65 /* Read the file fs.lst for auto-loading. */
66 void
67 read_fs_list (const char *prefix)
69 if (prefix)
71 char *filename;
73 filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM
74 "/fs.lst", prefix);
75 if (filename)
77 grub_file_t file;
78 grub_fs_autoload_hook_t tmp_autoload_hook;
80 /* This rules out the possibility that read_fs_list() is invoked
81 recursively when we call grub_file_open() below. */
82 tmp_autoload_hook = grub_fs_autoload_hook;
83 grub_fs_autoload_hook = NULL;
85 file = grub_file_open (filename);
86 if (file)
88 /* Override previous fs.lst. */
89 while (fs_module_list)
91 grub_named_list_t tmp;
92 tmp = fs_module_list->next;
93 grub_free (fs_module_list);
94 fs_module_list = tmp;
97 while (1)
99 char *buf;
100 char *p;
101 char *q;
102 grub_named_list_t fs_mod;
104 buf = grub_file_getline (file);
105 if (! buf)
106 break;
108 p = buf;
109 q = buf + grub_strlen (buf) - 1;
111 /* Ignore space. */
112 while (grub_isspace (*p))
113 p++;
115 while (p < q && grub_isspace (*q))
116 *q-- = '\0';
118 /* If the line is empty, skip it. */
119 if (p >= q)
121 grub_free (buf);
122 continue;
125 fs_mod = grub_malloc (sizeof (*fs_mod));
126 if (! fs_mod)
128 grub_free (buf);
129 continue;
132 fs_mod->name = grub_strdup (p);
133 grub_free (buf);
134 if (! fs_mod->name)
136 grub_free (fs_mod);
137 continue;
140 fs_mod->next = fs_module_list;
141 fs_module_list = fs_mod;
144 grub_file_close (file);
145 grub_fs_autoload_hook = tmp_autoload_hook;
148 grub_free (filename);
152 /* Ignore errors. */
153 grub_errno = GRUB_ERR_NONE;
155 /* Set the hook. */
156 grub_fs_autoload_hook = autoload_fs_module;