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 static grub_named_list_t fs_module_list
;
30 /* The auto-loading hook for filesystems. */
32 autoload_fs_module (void)
36 while ((p
= fs_module_list
) != NULL
)
38 if (! grub_dl_get (p
->name
) && grub_dl_load (p
->name
))
44 fs_module_list
= p
->next
;
52 /* Read the file fs.lst for auto-loading. */
54 read_fs_list (const char *prefix
)
60 filename
= grub_xasprintf ("%s/" GRUB_TARGET_CPU
"-" GRUB_PLATFORM
65 grub_fs_autoload_hook_t tmp_autoload_hook
;
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
;
72 file
= grub_file_open (filename
);
75 /* Override previous fs.lst. */
76 while (fs_module_list
)
78 grub_named_list_t tmp
;
79 tmp
= fs_module_list
->next
;
80 grub_free (fs_module_list
);
89 grub_named_list_t fs_mod
;
91 buf
= grub_file_getline (file
);
96 q
= buf
+ grub_strlen (buf
) - 1;
99 while (grub_isspace (*p
))
102 while (p
< q
&& grub_isspace (*q
))
105 /* If the line is empty, skip it. */
109 fs_mod
= grub_malloc (sizeof (*fs_mod
));
113 fs_mod
->name
= grub_strdup (p
);
120 fs_mod
->next
= fs_module_list
;
121 fs_module_list
= fs_mod
;
124 grub_file_close (file
);
125 grub_fs_autoload_hook
= tmp_autoload_hook
;
128 grub_free (filename
);
133 grub_errno
= GRUB_ERR_NONE
;
136 grub_fs_autoload_hook
= autoload_fs_module
;