Print this page
fixes + mirror
Split |
Close |
Expand all |
Collapse all |
--- old/grub/grub-core/commands/search_wrap.c
+++ new/grub/grub-core/commands/search_wrap.c
1 1 /* search.c - search devices based on a file or a filesystem label */
2 2 /*
3 3 * GRUB -- GRand Unified Bootloader
4 4 * Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc.
5 5 *
6 6 * GRUB is free software: you can redistribute it and/or modify
7 7 * it under the terms of the GNU General Public License as published by
8 8 * the Free Software Foundation, either version 3 of the License, or
9 9 * (at your option) any later version.
10 10 *
11 11 * GRUB is distributed in the hope that it will be useful,
12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 * GNU General Public License for more details.
15 15 *
16 16 * You should have received a copy of the GNU General Public License
17 17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 18 */
19 19
20 20 #include <grub/types.h>
21 21 #include <grub/misc.h>
22 22 #include <grub/mm.h>
23 23 #include <grub/err.h>
24 24 #include <grub/dl.h>
25 25 #include <grub/env.h>
26 26 #include <grub/extcmd.h>
27 27 #include <grub/search.h>
28 28 #include <grub/i18n.h>
29 29
30 30 GRUB_MOD_LICENSE ("GPLv3+");
31 31
32 32 static const struct grub_arg_option options[] =
33 33 {
34 34 {"file", 'f', 0, N_("Search devices by a file."), 0, 0},
35 35 {"label", 'l', 0, N_("Search devices by a filesystem label."),
36 36 0, 0},
37 37 {"fs-uuid", 'u', 0, N_("Search devices by a filesystem UUID."),
38 38 0, 0},
39 39 {"set", 's', GRUB_ARG_OPTION_OPTIONAL,
40 40 N_("Set a variable to the first device found."), N_("VARNAME"),
41 41 ARG_TYPE_STRING},
42 42 {"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0},
43 43 {"hint", 'h', GRUB_ARG_OPTION_REPEATABLE,
44 44 N_("First try the device HINT. If HINT ends in comma, "
45 45 "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
46 46 {"hint-ieee1275", 0, GRUB_ARG_OPTION_REPEATABLE,
47 47 N_("First try the device HINT if currently running on IEEE1275. "
48 48 "If HINT ends in comma, also try subpartitions"),
49 49 N_("HINT"), ARG_TYPE_STRING},
50 50 {"hint-bios", 0, GRUB_ARG_OPTION_REPEATABLE,
51 51 N_("First try the device HINT if currently running on BIOS. "
52 52 "If HINT ends in comma, also try subpartitions"),
53 53 N_("HINT"), ARG_TYPE_STRING},
54 54 {"hint-baremetal", 0, GRUB_ARG_OPTION_REPEATABLE,
55 55 N_("First try the device HINT if direct hardware access is supported. "
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
56 56 "If HINT ends in comma, also try subpartitions"),
57 57 N_("HINT"), ARG_TYPE_STRING},
58 58 {"hint-efi", 0, GRUB_ARG_OPTION_REPEATABLE,
59 59 N_("First try the device HINT if currently running on EFI. "
60 60 "If HINT ends in comma, also try subpartitions"),
61 61 N_("HINT"), ARG_TYPE_STRING},
62 62 {"hint-arc", 0, GRUB_ARG_OPTION_REPEATABLE,
63 63 N_("First try the device HINT if currently running on ARC."
64 64 " If HINT ends in comma, also try subpartitions"),
65 65 N_("HINT"), ARG_TYPE_STRING},
66 + {"zfs-mirror", 'z', 0, N_("Handle zfs-mirror disk"), 0, 0},
66 67 {0, 0, 0, 0, 0, 0}
67 68 };
68 69
69 70 enum options
70 71 {
71 72 SEARCH_FILE,
72 73 SEARCH_LABEL,
73 74 SEARCH_FS_UUID,
74 75 SEARCH_SET,
75 76 SEARCH_NO_FLOPPY,
76 77 SEARCH_HINT,
77 78 SEARCH_HINT_IEEE1275,
78 79 SEARCH_HINT_BIOS,
79 80 SEARCH_HINT_BAREMETAL,
80 81 SEARCH_HINT_EFI,
81 82 SEARCH_HINT_ARC,
83 + SEARCH_ZFS_MIRROR,
82 84 };
83 85
84 86 static grub_err_t
85 87 grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
86 88 {
87 89 struct grub_arg_list *state = ctxt->state;
88 90 const char *var = 0;
89 91 const char *id = 0;
90 92 int i = 0, j = 0, nhints = 0;
91 93 char **hints = NULL;
94 + int mirror_mode = 0;
92 95
93 96 if (state[SEARCH_HINT].set)
94 97 for (i = 0; state[SEARCH_HINT].args[i]; i++)
95 98 nhints++;
96 99
97 100 #ifdef GRUB_MACHINE_IEEE1275
98 101 if (state[SEARCH_HINT_IEEE1275].set)
99 102 for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++)
100 103 nhints++;
101 104 #endif
102 105
103 106 #ifdef GRUB_MACHINE_EFI
104 107 if (state[SEARCH_HINT_EFI].set)
105 108 for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++)
106 109 nhints++;
107 110 #endif
108 111
109 112 #ifdef GRUB_MACHINE_PCBIOS
110 113 if (state[SEARCH_HINT_BIOS].set)
111 114 for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++)
112 115 nhints++;
113 116 #endif
114 117
115 118 #ifdef GRUB_MACHINE_ARC
116 119 if (state[SEARCH_HINT_ARC].set)
117 120 for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++)
118 121 nhints++;
119 122 #endif
120 123
121 124 if (state[SEARCH_HINT_BAREMETAL].set)
122 125 for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++)
123 126 nhints++;
124 127
125 128 hints = grub_malloc (sizeof (hints[0]) * nhints);
126 129 if (!hints)
127 130 return grub_errno;
128 131 j = 0;
129 132
130 133 if (state[SEARCH_HINT].set)
131 134 for (i = 0; state[SEARCH_HINT].args[i]; i++)
132 135 hints[j++] = state[SEARCH_HINT].args[i];
133 136
134 137 #ifdef GRUB_MACHINE_IEEE1275
135 138 if (state[SEARCH_HINT_IEEE1275].set)
136 139 for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++)
137 140 hints[j++] = state[SEARCH_HINT_IEEE1275].args[i];
138 141 #endif
139 142
140 143 #ifdef GRUB_MACHINE_EFI
141 144 if (state[SEARCH_HINT_EFI].set)
142 145 for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++)
143 146 hints[j++] = state[SEARCH_HINT_EFI].args[i];
144 147 #endif
145 148
146 149 #ifdef GRUB_MACHINE_ARC
147 150 if (state[SEARCH_HINT_ARC].set)
148 151 for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++)
149 152 hints[j++] = state[SEARCH_HINT_ARC].args[i];
150 153 #endif
151 154
152 155 #ifdef GRUB_MACHINE_PCBIOS
153 156 if (state[SEARCH_HINT_BIOS].set)
154 157 for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++)
155 158 hints[j++] = state[SEARCH_HINT_BIOS].args[i];
156 159 #endif
157 160
158 161 if (state[SEARCH_HINT_BAREMETAL].set)
159 162 for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++)
160 163 hints[j++] = state[SEARCH_HINT_BAREMETAL].args[i];
161 164
162 165 /* Skip hints for future platforms. */
163 166 for (j = 0; j < argc; j++)
164 167 if (grub_memcmp (args[j], "--hint-", sizeof ("--hint-") - 1) != 0)
165 168 break;
166 169
167 170 if (state[SEARCH_SET].set)
168 171 var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
169 172
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
170 173 if (argc != j)
171 174 id = args[j];
172 175 else if (state[SEARCH_SET].set && state[SEARCH_SET].arg)
173 176 {
174 177 id = state[SEARCH_SET].arg;
175 178 var = "root";
176 179 }
177 180 else
178 181 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
179 182
183 + if (state[SEARCH_ZFS_MIRROR].set)
184 + mirror_mode = 1;
185 +
180 186 if (state[SEARCH_LABEL].set)
181 187 grub_search_label (id, var, state[SEARCH_NO_FLOPPY].set,
182 - hints, nhints);
188 + hints, nhints, mirror_mode);
183 189 else if (state[SEARCH_FS_UUID].set)
184 190 grub_search_fs_uuid (id, var, state[SEARCH_NO_FLOPPY].set,
185 - hints, nhints);
191 + hints, nhints, mirror_mode);
186 192 else if (state[SEARCH_FILE].set)
187 193 grub_search_fs_file (id, var, state[SEARCH_NO_FLOPPY].set,
188 - hints, nhints);
194 + hints, nhints, mirror_mode);
189 195 else
190 196 return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
191 197
192 198 return grub_errno;
193 199 }
194 200
195 201 static grub_extcmd_t cmd;
196 202
197 203 GRUB_MOD_INIT(search)
198 204 {
199 205 cmd =
200 206 grub_register_extcmd ("search", grub_cmd_search,
201 207 GRUB_COMMAND_FLAG_EXTRACTOR | GRUB_COMMAND_ACCEPT_DASH,
202 208 N_("[-f|-l|-u|-s|-n] [--hint HINT [--hint HINT] ...]"
203 209 " NAME"),
204 210 N_("Search devices by file, filesystem label"
205 211 " or filesystem UUID."
206 212 " If --set is specified, the first device found is"
207 213 " set to a variable. If no variable name is"
208 214 " specified, `root' is used."),
209 215 options);
210 216 }
211 217
212 218 GRUB_MOD_FINI(search)
213 219 {
214 220 grub_unregister_extcmd (cmd);
215 221 }
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX