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 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
))
54 fs_module_list
= p
->next
;
59 grub_memcpy (grub_file_filters_enabled
, grub_file_filters_was
,
60 sizeof (grub_file_filters_enabled
));
65 /* Read the file fs.lst for auto-loading. */
67 read_fs_list (const char *prefix
)
73 filename
= grub_xasprintf ("%s/" GRUB_TARGET_CPU
"-" GRUB_PLATFORM
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
);
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
);
102 grub_named_list_t fs_mod
;
104 buf
= grub_file_getline (file
);
109 q
= buf
+ grub_strlen (buf
) - 1;
112 while (grub_isspace (*p
))
115 while (p
< q
&& grub_isspace (*q
))
118 /* If the line is empty, skip it. */
125 fs_mod
= grub_malloc (sizeof (*fs_mod
));
132 fs_mod
->name
= grub_strdup (p
);
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
);
153 grub_errno
= GRUB_ERR_NONE
;
156 grub_fs_autoload_hook
= autoload_fs_module
;