~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/commands/search_wrap.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
     N_("Set a variable to the first device found."), "VAR", ARG_TYPE_STRING},
 
40
     N_("Set a variable to the first device found."), N_("VARNAME"),
 
41
     ARG_TYPE_STRING},
41
42
    {"no-floppy",       'n', 0, N_("Do not probe any floppy drive."), 0, 0},
42
43
    {"hint",            'h', GRUB_ARG_OPTION_REPEATABLE,
43
44
     N_("First try the device HINT. If HINT ends in comma, "
44
45
        "also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
 
46
    {"hint-ieee1275",   0, GRUB_ARG_OPTION_REPEATABLE,
 
47
     N_("First try the device HINT if currently running on IEEE1275. "
 
48
        "If HINT ends in comma, also try subpartitions"),
 
49
     N_("HINT"), ARG_TYPE_STRING},
 
50
    {"hint-bios",   0, GRUB_ARG_OPTION_REPEATABLE,
 
51
     N_("First try the device HINT if currently running on BIOS. "
 
52
        "If HINT ends in comma, also try subpartitions"),
 
53
     N_("HINT"), ARG_TYPE_STRING},
 
54
    {"hint-baremetal",   0, GRUB_ARG_OPTION_REPEATABLE,
 
55
     N_("First try the device HINT if direct hardware access is supported. "
 
56
        "If HINT ends in comma, also try subpartitions"),
 
57
     N_("HINT"), ARG_TYPE_STRING},
 
58
    {"hint-efi",   0, GRUB_ARG_OPTION_REPEATABLE,
 
59
     N_("First try the device HINT if currently running on EFI. "
 
60
        "If HINT ends in comma, also try subpartitions"),
 
61
     N_("HINT"), ARG_TYPE_STRING},
 
62
    {"hint-arc",   0, GRUB_ARG_OPTION_REPEATABLE,
 
63
     N_("First try the device HINT if currently running on ARC."
 
64
        " If HINT ends in comma, also try subpartitions"),
 
65
     N_("HINT"), ARG_TYPE_STRING},
45
66
    {0, 0, 0, 0, 0, 0}
46
67
  };
47
68
 
52
73
    SEARCH_FS_UUID,
53
74
    SEARCH_SET,
54
75
    SEARCH_NO_FLOPPY,
55
 
    SEARCH_HINT
 
76
    SEARCH_HINT,
 
77
    SEARCH_HINT_IEEE1275,
 
78
    SEARCH_HINT_BIOS,
 
79
    SEARCH_HINT_BAREMETAL,
 
80
    SEARCH_HINT_EFI,
 
81
    SEARCH_HINT_ARC,
56
82
 };
57
83
 
58
84
static grub_err_t
60
86
{
61
87
  struct grub_arg_list *state = ctxt->state;
62
88
  const char *var = 0;
63
 
  int nhints = 0;
64
 
 
65
 
  if (state[SEARCH_HINT].set)
66
 
    while (state[SEARCH_HINT].args[nhints])
67
 
      nhints++;
68
 
 
69
 
  if (argc == 0)
70
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
 
89
  const char *id = 0;
 
90
  int i = 0, j = 0, nhints = 0;
 
91
  char **hints = NULL;
 
92
 
 
93
  if (state[SEARCH_HINT].set)
 
94
    for (i = 0; state[SEARCH_HINT].args[i]; i++)
 
95
      nhints++;
 
96
 
 
97
#ifdef GRUB_MACHINE_IEEE1275
 
98
  if (state[SEARCH_HINT_IEEE1275].set)
 
99
    for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++)
 
100
      nhints++;
 
101
#endif
 
102
 
 
103
#ifdef GRUB_MACHINE_EFI
 
104
  if (state[SEARCH_HINT_EFI].set)
 
105
    for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++)
 
106
      nhints++;
 
107
#endif
 
108
 
 
109
#ifdef GRUB_MACHINE_PCBIOS
 
110
  if (state[SEARCH_HINT_BIOS].set)
 
111
    for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++)
 
112
      nhints++;
 
113
#endif
 
114
 
 
115
#ifdef GRUB_MACHINE_ARC
 
116
  if (state[SEARCH_HINT_ARC].set)
 
117
    for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++)
 
118
      nhints++;
 
119
#endif
 
120
 
 
121
  if (state[SEARCH_HINT_BAREMETAL].set)
 
122
    for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++)
 
123
      nhints++;
 
124
 
 
125
  hints = grub_malloc (sizeof (hints[0]) * nhints);
 
126
  if (!hints)
 
127
    return grub_errno;
 
128
  j = 0;
 
129
 
 
130
  if (state[SEARCH_HINT].set)
 
131
    for (i = 0; state[SEARCH_HINT].args[i]; i++)
 
132
      hints[j++] = state[SEARCH_HINT].args[i];
 
133
 
 
134
#ifdef GRUB_MACHINE_IEEE1275
 
135
  if (state[SEARCH_HINT_IEEE1275].set)
 
136
    for (i = 0; state[SEARCH_HINT_IEEE1275].args[i]; i++)
 
137
      hints[j++] = state[SEARCH_HINT_IEEE1275].args[i];
 
138
#endif
 
139
 
 
140
#ifdef GRUB_MACHINE_EFI
 
141
  if (state[SEARCH_HINT_EFI].set)
 
142
    for (i = 0; state[SEARCH_HINT_EFI].args[i]; i++)
 
143
      hints[j++] = state[SEARCH_HINT_EFI].args[i];
 
144
#endif
 
145
 
 
146
#ifdef GRUB_MACHINE_ARC
 
147
  if (state[SEARCH_HINT_ARC].set)
 
148
    for (i = 0; state[SEARCH_HINT_ARC].args[i]; i++)
 
149
      hints[j++] = state[SEARCH_HINT_ARC].args[i];
 
150
#endif
 
151
 
 
152
#ifdef GRUB_MACHINE_PCBIOS
 
153
  if (state[SEARCH_HINT_BIOS].set)
 
154
    for (i = 0; state[SEARCH_HINT_BIOS].args[i]; i++)
 
155
      hints[j++] = state[SEARCH_HINT_BIOS].args[i];
 
156
#endif
 
157
 
 
158
  if (state[SEARCH_HINT_BAREMETAL].set)
 
159
    for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++)
 
160
      hints[j++] = state[SEARCH_HINT_BAREMETAL].args[i];
 
161
 
 
162
  /* Skip hints for future platforms.  */
 
163
  for (j = 0; j < argc; j++)
 
164
    if (grub_memcmp (args[j], "--hint-", sizeof ("--hint-") - 1) != 0)
 
165
      break;
71
166
 
72
167
  if (state[SEARCH_SET].set)
73
168
    var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
74
169
 
 
170
  if (argc != j)
 
171
    id = args[j];
 
172
  else if (state[SEARCH_SET].set && state[SEARCH_SET].arg)
 
173
    {
 
174
      id = state[SEARCH_SET].arg;
 
175
      var = "root";
 
176
    }
 
177
  else
 
178
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
 
179
 
75
180
  if (state[SEARCH_LABEL].set)
76
 
    grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set, 
77
 
                       state[SEARCH_HINT].args, nhints);
 
181
    grub_search_label (id, var, state[SEARCH_NO_FLOPPY].set, 
 
182
                       hints, nhints);
78
183
  else if (state[SEARCH_FS_UUID].set)
79
 
    grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set,
80
 
                         state[SEARCH_HINT].args, nhints);
 
184
    grub_search_fs_uuid (id, var, state[SEARCH_NO_FLOPPY].set,
 
185
                         hints, nhints);
81
186
  else if (state[SEARCH_FILE].set)
82
 
    grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set, 
83
 
                         state[SEARCH_HINT].args, nhints);
 
187
    grub_search_fs_file (id, var, state[SEARCH_NO_FLOPPY].set, 
 
188
                         hints, nhints);
84
189
  else
85
190
    return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
86
191
 
92
197
GRUB_MOD_INIT(search)
93
198
{
94
199
  cmd =
95
 
    grub_register_extcmd ("search", grub_cmd_search, GRUB_COMMAND_FLAG_EXTRACTOR,
 
200
    grub_register_extcmd ("search", grub_cmd_search,
 
201
                          GRUB_COMMAND_FLAG_EXTRACTOR | GRUB_COMMAND_ACCEPT_DASH,
96
202
                          N_("[-f|-l|-u|-s|-n] [--hint HINT [--hint HINT] ...]"
97
203
                             " NAME"),
98
204
                          N_("Search devices by file, filesystem label"
99
205
                             " or filesystem UUID."
100
206
                             " If --set is specified, the first device found is"
101
207
                             " set to a variable. If no variable name is"
102
 
                             " specified, \"root\" is used."),
 
208
                             " specified, `root' is used."),
103
209
                          options);
104
210
}
105
211