~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to commands/terminal.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2009,2010  Free Software Foundation, Inc.
4
 
 *
5
 
 *  GRUB is free software: you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation, either version 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  GRUB is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <grub/mm.h>
20
 
#include <grub/dl.h>
21
 
#include <grub/command.h>
22
 
#include <grub/term.h>
23
 
#include <grub/i18n.h>
24
 
#include <grub/misc.h>
25
 
 
26
 
struct grub_term_autoload *grub_term_input_autoload = NULL;
27
 
struct grub_term_autoload *grub_term_output_autoload = NULL;
28
 
 
29
 
static grub_err_t
30
 
grub_cmd_terminal_input (grub_command_t cmd __attribute__ ((unused)),
31
 
                         int argc, char **args)
32
 
{
33
 
  int i;
34
 
  grub_term_input_t term;
35
 
  struct grub_term_autoload *aut;
36
 
 
37
 
  if (argc == 0)
38
 
    {
39
 
      grub_puts_ (N_ ("Active input terminals:"));
40
 
      FOR_ACTIVE_TERM_INPUTS(term)
41
 
        grub_printf ("%s ", term->name);
42
 
      grub_printf ("\n");
43
 
      grub_puts_ (N_ ("Available input terminals:"));
44
 
      FOR_DISABLED_TERM_INPUTS(term)
45
 
        grub_printf ("%s ", term->name);
46
 
      /* This is quadratic but we don't expect mode than 30 terminal
47
 
         modules ever.  */
48
 
      for (aut = grub_term_input_autoload; aut; aut = aut->next)
49
 
        {
50
 
          FOR_DISABLED_TERM_INPUTS(term)
51
 
            if (grub_strcmp (term->name, aut->name) == 0)
52
 
              break;
53
 
          if (!term)
54
 
            FOR_ACTIVE_TERM_INPUTS(term)
55
 
              if (grub_strcmp (term->name, aut->name) == 0)
56
 
                break;
57
 
          if (!term)
58
 
            grub_printf ("%s ", aut->name);
59
 
        }
60
 
      grub_printf ("\n");
61
 
      return GRUB_ERR_NONE;
62
 
    }
63
 
  i = 0;
64
 
 
65
 
  if (grub_strcmp (args[0], "--append") == 0
66
 
      || grub_strcmp (args[0], "--remove") == 0)
67
 
    i++;
68
 
 
69
 
  if (i == argc)
70
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no terminal specified"));
71
 
 
72
 
  for (; i < argc; i++)
73
 
    {
74
 
      int again = 0;
75
 
      while (1)
76
 
        {
77
 
          FOR_DISABLED_TERM_INPUTS(term)
78
 
            if (grub_strcmp (args[i], term->name) == 0)
79
 
              break;
80
 
          if (term == 0)
81
 
            FOR_ACTIVE_TERM_INPUTS(term)
82
 
              if (grub_strcmp (args[i], term->name) == 0)
83
 
                break;
84
 
          if (term)
85
 
            break;
86
 
          if (again)
87
 
            return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
88
 
                               args[i]);
89
 
          for (aut = grub_term_input_autoload; aut; aut = aut->next)
90
 
            if (grub_strcmp (args[i], aut->name) == 0)
91
 
              {
92
 
                grub_dl_t mod;
93
 
                mod = grub_dl_load (aut->modname);
94
 
                if (mod)
95
 
                  grub_dl_ref (mod);
96
 
                grub_errno = GRUB_ERR_NONE;
97
 
                break;
98
 
              }
99
 
          if (!aut)
100
 
            return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
101
 
                               args[i]);
102
 
          again = 1;
103
 
        }
104
 
    }
105
 
 
106
 
  if (grub_strcmp (args[0], "--append") == 0)
107
 
    {
108
 
      for (i = 1; i < argc; i++)
109
 
        {
110
 
          FOR_DISABLED_TERM_INPUTS(term)
111
 
            if (grub_strcmp (args[i], term->name) == 0)
112
 
              break;
113
 
          if (term)
114
 
            {
115
 
              if (term->init && term->init () != GRUB_ERR_NONE)
116
 
                return grub_errno;
117
 
 
118
 
              grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)),
119
 
                                GRUB_AS_LIST (term));
120
 
              grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs),
121
 
                              GRUB_AS_LIST (term));
122
 
            }
123
 
        }
124
 
      return GRUB_ERR_NONE;
125
 
    }
126
 
 
127
 
  if (grub_strcmp (args[0], "--remove") == 0)
128
 
    {
129
 
      for (i = 1; i < argc; i++)
130
 
        {
131
 
          FOR_ACTIVE_TERM_INPUTS(term)
132
 
            if (grub_strcmp (args[i], term->name) == 0)
133
 
              break;
134
 
          if (term)
135
 
            {
136
 
              if (!term->next && term == grub_term_inputs)
137
 
                return grub_error (GRUB_ERR_BAD_ARGUMENT,
138
 
                                   "can't remove the last terminal");
139
 
              grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)),
140
 
                                GRUB_AS_LIST (term));
141
 
              if (term->fini)
142
 
                term->fini ();
143
 
              grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled),
144
 
                              GRUB_AS_LIST (term));
145
 
            }
146
 
        }
147
 
      return GRUB_ERR_NONE;
148
 
    }
149
 
  for (i = 0; i < argc; i++)
150
 
    {
151
 
      FOR_DISABLED_TERM_INPUTS(term)
152
 
        if (grub_strcmp (args[i], term->name) == 0)
153
 
          break;
154
 
      if (term)
155
 
        {
156
 
          if (term->init && term->init () != GRUB_ERR_NONE)
157
 
            return grub_errno;
158
 
 
159
 
          grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs_disabled)),
160
 
                            GRUB_AS_LIST (term));
161
 
          grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs),
162
 
                          GRUB_AS_LIST (term));
163
 
        }       
164
 
    }
165
 
 
166
 
  FOR_ACTIVE_TERM_INPUTS(term)
167
 
  {
168
 
    for (i = 0; i < argc; i++)
169
 
      if (grub_strcmp (args[i], term->name) == 0)
170
 
        break;
171
 
    if (i == argc)
172
 
      {
173
 
        if (!term->next && term == grub_term_inputs)
174
 
          return grub_error (GRUB_ERR_BAD_ARGUMENT,
175
 
                             "can't remove the last terminal");
176
 
        grub_list_remove (GRUB_AS_LIST_P (&(grub_term_inputs)),
177
 
                          GRUB_AS_LIST (term));
178
 
        if (term->fini)
179
 
          term->fini ();
180
 
        grub_list_push (GRUB_AS_LIST_P (&grub_term_inputs_disabled),
181
 
                        GRUB_AS_LIST (term));
182
 
      }
183
 
  }
184
 
 
185
 
  return GRUB_ERR_NONE;
186
 
}
187
 
 
188
 
static grub_err_t
189
 
grub_cmd_terminal_output (grub_command_t cmd __attribute__ ((unused)),
190
 
                         int argc, char **args)
191
 
{
192
 
  int i;
193
 
  grub_term_output_t term;
194
 
  struct grub_term_autoload *aut;
195
 
 
196
 
  if (argc == 0)
197
 
    {
198
 
      grub_puts_ (N_ ("Active output terminals:"));
199
 
      FOR_ACTIVE_TERM_OUTPUTS(term)
200
 
        grub_printf ("%s ", term->name);
201
 
      grub_printf ("\n");
202
 
      grub_puts_ (N_ ("Available output terminals:"));
203
 
      FOR_DISABLED_TERM_OUTPUTS(term)
204
 
        grub_printf ("%s ", term->name);
205
 
      /* This is quadratic but we don't expect mode than 30 terminal
206
 
         modules ever.  */
207
 
      for (aut = grub_term_output_autoload; aut; aut = aut->next)
208
 
        {
209
 
          FOR_DISABLED_TERM_OUTPUTS(term)
210
 
            if (grub_strcmp (term->name, aut->name) == 0)
211
 
              break;
212
 
          if (!term)
213
 
            FOR_ACTIVE_TERM_OUTPUTS(term)
214
 
              if (grub_strcmp (term->name, aut->name) == 0)
215
 
                break;
216
 
          if (!term)
217
 
            grub_printf ("%s ", aut->name);
218
 
        }
219
 
      grub_printf ("\n");
220
 
      return GRUB_ERR_NONE;
221
 
    }
222
 
  i = 0;
223
 
 
224
 
  if (grub_strcmp (args[0], "--append") == 0
225
 
      || grub_strcmp (args[0], "--remove") == 0)
226
 
    i++;
227
 
 
228
 
  if (i == argc)
229
 
    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_ ("no terminal specified"));
230
 
 
231
 
  for (; i < argc; i++)
232
 
    {
233
 
      int again = 0;
234
 
      while (1)
235
 
        {
236
 
          FOR_DISABLED_TERM_OUTPUTS(term)
237
 
            if (grub_strcmp (args[i], term->name) == 0)
238
 
              break;
239
 
          if (term == 0)
240
 
            FOR_ACTIVE_TERM_OUTPUTS(term)
241
 
              if (grub_strcmp (args[i], term->name) == 0)
242
 
                break;
243
 
          if (term)
244
 
            break;
245
 
          if (again)
246
 
            return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
247
 
                               args[i]);
248
 
          for (aut = grub_term_output_autoload; aut; aut = aut->next)
249
 
            if (grub_strcmp (args[i], aut->name) == 0)
250
 
              {
251
 
                grub_dl_t mod;
252
 
                mod = grub_dl_load (aut->modname);
253
 
                if (mod)
254
 
                  grub_dl_ref (mod);
255
 
                grub_errno = GRUB_ERR_NONE;
256
 
                break;
257
 
              }
258
 
          if (!aut)
259
 
            return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminal '%s'\n",
260
 
                               args[i]);
261
 
          again = 1;
262
 
        }
263
 
    }
264
 
 
265
 
  if (grub_strcmp (args[0], "--append") == 0)
266
 
    {
267
 
      for (i = 1; i < argc; i++)
268
 
        {
269
 
          FOR_DISABLED_TERM_OUTPUTS(term)
270
 
            if (grub_strcmp (args[i], term->name) == 0)
271
 
              break;
272
 
          if (term)
273
 
            {
274
 
              if (term->init && term->init () != GRUB_ERR_NONE)
275
 
                return grub_errno;
276
 
 
277
 
              grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)),
278
 
                                GRUB_AS_LIST (term));
279
 
              grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
280
 
                              GRUB_AS_LIST (term));
281
 
            }
282
 
        }
283
 
      return GRUB_ERR_NONE;
284
 
    }
285
 
 
286
 
  if (grub_strcmp (args[0], "--remove") == 0)
287
 
    {
288
 
      for (i = 1; i < argc; i++)
289
 
        {
290
 
          FOR_ACTIVE_TERM_OUTPUTS(term)
291
 
            if (grub_strcmp (args[i], term->name) == 0)
292
 
              break;
293
 
          if (term)
294
 
            {
295
 
              if (!term->next && term == grub_term_outputs)
296
 
                return grub_error (GRUB_ERR_BAD_ARGUMENT,
297
 
                                   "can't remove the last terminal");
298
 
              grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs)),
299
 
                                GRUB_AS_LIST (term));
300
 
              if (term->fini)
301
 
                term->fini ();
302
 
              grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled),
303
 
                              GRUB_AS_LIST (term));
304
 
            }
305
 
        }
306
 
      return GRUB_ERR_NONE;
307
 
    }
308
 
 
309
 
  for (i = 0; i < argc; i++)
310
 
    {
311
 
      FOR_DISABLED_TERM_OUTPUTS(term)
312
 
        if (grub_strcmp (args[i], term->name) == 0)
313
 
          break;
314
 
      if (term)
315
 
        {
316
 
          if (term->init && term->init () != GRUB_ERR_NONE)
317
 
            return grub_errno;
318
 
 
319
 
          grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs_disabled)),
320
 
                            GRUB_AS_LIST (term));
321
 
          grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs),
322
 
                          GRUB_AS_LIST (term));
323
 
        }       
324
 
    }
325
 
 
326
 
  FOR_ACTIVE_TERM_OUTPUTS(term)
327
 
  {
328
 
    for (i = 0; i < argc; i++)
329
 
      if (grub_strcmp (args[i], term->name) == 0)
330
 
        break;
331
 
    if (i == argc)
332
 
      {
333
 
        if (!term->next && term == grub_term_outputs)
334
 
          return grub_error (GRUB_ERR_BAD_ARGUMENT,
335
 
                             "can't remove the last terminal");
336
 
        grub_list_remove (GRUB_AS_LIST_P (&(grub_term_outputs)),
337
 
                          GRUB_AS_LIST (term));
338
 
        if (term->fini)
339
 
          term->fini ();
340
 
        grub_list_push (GRUB_AS_LIST_P (&grub_term_outputs_disabled),
341
 
                        GRUB_AS_LIST (term));
342
 
      }
343
 
  }
344
 
 
345
 
  return GRUB_ERR_NONE;
346
 
}
347
 
 
348
 
static grub_command_t cmd_terminal_input, cmd_terminal_output;
349
 
 
350
 
GRUB_MOD_INIT(terminal)
351
 
{
352
 
  cmd_terminal_input =
353
 
    grub_register_command ("terminal_input", grub_cmd_terminal_input,
354
 
                           "[--append|--remove] "
355
 
                           "[TERMINAL1] [TERMINAL2] ...",
356
 
                           "List or select an input terminal.");
357
 
  cmd_terminal_output =
358
 
    grub_register_command ("terminal_output", grub_cmd_terminal_output,
359
 
                           "[--append|--remove] "
360
 
                           "[TERMINAL1] [TERMINAL2] ...",
361
 
                           "List or select an output terminal.");
362
 
}
363
 
 
364
 
GRUB_MOD_FINI(terminal)
365
 
{
366
 
  grub_unregister_command (cmd_terminal_input);
367
 
  grub_unregister_command (cmd_terminal_output);
368
 
}