]> git.proxmox.com Git - grub2.git/blob - commands/search_wrap.c
merge mainline into bidi
[grub2.git] / commands / search_wrap.c
1 /* search.c - search devices based on a file or a filesystem label */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2007,2008,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/types.h>
21 #include <grub/misc.h>
22 #include <grub/mm.h>
23 #include <grub/err.h>
24 #include <grub/dl.h>
25 #include <grub/env.h>
26 #include <grub/extcmd.h>
27 #include <grub/search.h>
28 #include <grub/i18n.h>
29
30 static const struct grub_arg_option options[] =
31 {
32 {"file", 'f', 0, N_("Search devices by a file."), 0, 0},
33 {"label", 'l', 0, N_("Search devices by a filesystem label."),
34 0, 0},
35 {"fs-uuid", 'u', 0, N_("Search devices by a filesystem UUID."),
36 0, 0},
37 {"set", 's', GRUB_ARG_OPTION_OPTIONAL,
38 N_("Set a variable to the first device found."), "VAR", ARG_TYPE_STRING},
39 {"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0},
40 {0, 0, 0, 0, 0, 0}
41 };
42
43 enum options
44 {
45 SEARCH_FILE,
46 SEARCH_LABEL,
47 SEARCH_FS_UUID,
48 SEARCH_SET,
49 SEARCH_NO_FLOPPY,
50 };
51
52 static grub_err_t
53 grub_cmd_search (grub_extcmd_t cmd, int argc, char **args)
54 {
55 struct grub_arg_list *state = cmd->state;
56 const char *var = 0;
57
58 if (argc == 0)
59 return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
60
61 if (state[SEARCH_SET].set)
62 var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
63
64 if (state[SEARCH_LABEL].set)
65 grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set);
66 else if (state[SEARCH_FS_UUID].set)
67 grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set);
68 else if (state[SEARCH_FILE].set)
69 grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set);
70 else
71 return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
72
73 return grub_errno;
74 }
75
76 static grub_extcmd_t cmd;
77
78 GRUB_MOD_INIT(search)
79 {
80 cmd =
81 grub_register_extcmd ("search", grub_cmd_search,
82 GRUB_COMMAND_FLAG_BOTH,
83 N_("search [-f|-l|-u|-s|-n] NAME"),
84 N_("Search devices by file, filesystem label"
85 " or filesystem UUID."
86 " If --set is specified, the first device found is"
87 " set to a variable. If no variable name is"
88 " specified, \"root\" is used."),
89 options);
90 }
91
92 GRUB_MOD_FINI(search)
93 {
94 grub_unregister_extcmd (cmd);
95 }