]> git.proxmox.com Git - grub2.git/blob - grub-core/normal/autofs.c
Move platform-dependent files from $prefix to $prefix/$platform.
[grub2.git] / grub-core / normal / autofs.c
1 /* autofs.c - support auto-loading from fs.lst */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
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>
26
27 /* This is used to store the names of filesystem modules for auto-loading. */
28 static grub_named_list_t fs_module_list;
29
30 /* The auto-loading hook for filesystems. */
31 static int
32 autoload_fs_module (void)
33 {
34 grub_named_list_t p;
35
36 while ((p = fs_module_list) != NULL)
37 {
38 if (! grub_dl_get (p->name) && grub_dl_load (p->name))
39 return 1;
40
41 if (grub_errno)
42 grub_print_error ();
43
44 fs_module_list = p->next;
45 grub_free (p->name);
46 grub_free (p);
47 }
48
49 return 0;
50 }
51
52 /* Read the file fs.lst for auto-loading. */
53 void
54 read_fs_list (const char *prefix)
55 {
56 if (prefix)
57 {
58 char *filename;
59
60 filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM
61 "/fs.lst", prefix);
62 if (filename)
63 {
64 grub_file_t file;
65 grub_fs_autoload_hook_t tmp_autoload_hook;
66
67 /* This rules out the possibility that read_fs_list() is invoked
68 recursively when we call grub_file_open() below. */
69 tmp_autoload_hook = grub_fs_autoload_hook;
70 grub_fs_autoload_hook = NULL;
71
72 file = grub_file_open (filename);
73 if (file)
74 {
75 /* Override previous fs.lst. */
76 while (fs_module_list)
77 {
78 grub_named_list_t tmp;
79 tmp = fs_module_list->next;
80 grub_free (fs_module_list);
81 fs_module_list = tmp;
82 }
83
84 while (1)
85 {
86 char *buf;
87 char *p;
88 char *q;
89 grub_named_list_t fs_mod;
90
91 buf = grub_file_getline (file);
92 if (! buf)
93 break;
94
95 p = buf;
96 q = buf + grub_strlen (buf) - 1;
97
98 /* Ignore space. */
99 while (grub_isspace (*p))
100 p++;
101
102 while (p < q && grub_isspace (*q))
103 *q-- = '\0';
104
105 /* If the line is empty, skip it. */
106 if (p >= q)
107 continue;
108
109 fs_mod = grub_malloc (sizeof (*fs_mod));
110 if (! fs_mod)
111 continue;
112
113 fs_mod->name = grub_strdup (p);
114 if (! fs_mod->name)
115 {
116 grub_free (fs_mod);
117 continue;
118 }
119
120 fs_mod->next = fs_module_list;
121 fs_module_list = fs_mod;
122 }
123
124 grub_file_close (file);
125 grub_fs_autoload_hook = tmp_autoload_hook;
126 }
127
128 grub_free (filename);
129 }
130 }
131
132 /* Ignore errors. */
133 grub_errno = GRUB_ERR_NONE;
134
135 /* Set the hook. */
136 grub_fs_autoload_hook = autoload_fs_module;
137 }