]>
git.proxmox.com Git - grub2.git/blob - commands/search_wrap.c
1 /* search.c - search devices based on a file or a filesystem label */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2007,2008,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/>.
20 #include <grub/types.h>
21 #include <grub/misc.h>
26 #include <grub/extcmd.h>
27 #include <grub/search.h>
28 #include <grub/i18n.h>
30 static const struct grub_arg_option options
[] =
32 {"file", 'f', 0, N_("Search devices by a file."), 0, 0},
33 {"label", 'l', 0, N_("Search devices by a filesystem label."),
35 {"fs-uuid", 'u', 0, N_("Search devices by a filesystem UUID."),
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},
53 grub_cmd_search (grub_extcmd_t cmd
, int argc
, char **args
)
55 struct grub_arg_list
*state
= cmd
->state
;
59 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "no argument specified");
61 if (state
[SEARCH_SET
].set
)
62 var
= state
[SEARCH_SET
].arg
? state
[SEARCH_SET
].arg
: "root";
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
);
71 return grub_error (GRUB_ERR_INVALID_COMMAND
, "unspecified search type");
76 static grub_extcmd_t 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."),
94 grub_unregister_extcmd (cmd
);