1 /* autofs.c - support auto-loading from fs.lst */
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/>.
23 #include <grub/misc.h>
25 #include <grub/normal.h>
27 /* This is used to store the names of filesystem modules for auto-loading. */
28 struct grub_fs_module_list
31 struct grub_fs_module_list
*next
;
33 typedef struct grub_fs_module_list
*grub_fs_module_list_t
;
35 static grub_fs_module_list_t fs_module_list
= 0;
37 /* The auto-loading hook for filesystems. */
39 autoload_fs_module (void)
41 grub_fs_module_list_t p
;
43 while ((p
= fs_module_list
) != 0)
45 if (! grub_dl_get (p
->name
) && grub_dl_load (p
->name
))
48 fs_module_list
= p
->next
;
56 /* Read the file fs.lst for auto-loading. */
61 static int first_time
= 1;
63 /* Make sure that this function does not get executed twice. */
68 prefix
= grub_env_get ("prefix");
73 filename
= grub_malloc (grub_strlen (prefix
) + sizeof ("/fs.lst"));
78 grub_sprintf (filename
, "%s/fs.lst", prefix
);
79 file
= grub_file_open (filename
);
87 grub_fs_module_list_t fs_mod
;
89 buf
= grub_file_getline (file
);
94 q
= buf
+ grub_strlen (buf
) - 1;
97 while (grub_isspace (*p
))
100 while (p
< q
&& grub_isspace (*q
))
103 /* If the line is empty, skip it. */
107 fs_mod
= grub_malloc (sizeof (*fs_mod
));
111 fs_mod
->name
= grub_strdup (p
);
118 fs_mod
->next
= fs_module_list
;
119 fs_module_list
= fs_mod
;
122 grub_file_close (file
);
125 grub_free (filename
);
130 grub_errno
= GRUB_ERR_NONE
;
133 grub_fs_autoload_hook
= autoload_fs_module
;