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

« back to all changes in this revision

Viewing changes to commands/parttool.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Evan Broder, Mario Limonciello
  • Date: 2010-11-24 13:59:55 UTC
  • mfrom: (1.17.6 upstream) (17.6.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20101124135955-r6ii5sepayr7jt53
Tags: 1.99~20101124-1ubuntu1
[ Colin Watson ]
* Resynchronise with Debian experimental.  Remaining changes:
  - Adjust for default Ubuntu boot options ("quiet splash").
  - Default to hiding the menu; holding down Shift at boot will show it.
  - Set a monochromatic theme for Ubuntu.
  - Apply Ubuntu GRUB Legacy changes to legacy update-grub script: title,
    recovery mode, quiet option, tweak how memtest86+ is displayed, and
    use UUIDs where appropriate.
  - Fix backslash-escaping in merge_debconf_into_conf.
  - Remove "GNU/Linux" from default distributor string.
  - Add crashkernel= options if kdump and makedumpfile are available.
  - If other operating systems are installed, then automatically unhide
    the menu.  Otherwise, if GRUB_HIDDEN_TIMEOUT is 0, then use keystatus
    if available to check whether Shift is pressed.  If it is, show the
    menu, otherwise boot immediately.  If keystatus is not available, then
    fall back to a short delay interruptible with Escape.
  - Allow Shift to interrupt 'sleep --interruptible'.
  - Don't display introductory message about line editing unless we're
    actually offering a shell prompt.  Don't clear the screen just before
    booting if we never drew the menu in the first place.
  - Remove some verbose messages printed before reading the configuration
    file.
  - Suppress progress messages as the kernel and initrd load for
    non-recovery kernel menu entries.
  - Change prepare_grub_to_access_device to handle filesystems
    loop-mounted on file images.
  - Ignore devices loop-mounted from files in 10_linux.
  - Show the boot menu if the previous boot failed, that is if it failed
    to get to the end of one of the normal runlevels.
  - Don't generate /boot/grub/device.map during grub-install or
    grub-mkconfig by default.
  - Adjust upgrade version checks for Ubuntu.
  - Don't display "GRUB loading" unless Shift is held down.
  - Adjust versions of grub-doc and grub-legacy-doc conflicts to tolerate
    our backport of the grub-doc split.
  - Fix LVM/RAID probing in the absence of /boot/grub/device.map.
  - Look for .mo files in /usr/share/locale-langpack as well, in
    preference.
  - Make sure GRUB_TIMEOUT isn't quoted unnecessarily.
  - Probe all devices in 'grub-probe --target=drive' if
    /boot/grub/device.map is missing.
  - Build-depend on qemu-kvm rather than qemu-system for grub-pc tests.
  - Use qemu rather than qemu-system-i386.
  - Program vesafb on BIOS systems rather than efifb.
  - Add a grub-rescue-efi-amd64 package containing a rescue CD-ROM image
    for EFI-AMD64.
  - On Wubi, don't ask for an install device, but just update wubildr
    using the diverted grub-install.
  - When embedding the core image in a post-MBR gap, check for and avoid
    sectors matching any of a list of known signatures.
  - Disable video_bochs and video_cirrus on PC BIOS systems, as probing
    PCI space seems to break on some systems.
* Downgrade "ACPI shutdown failed" error to a debug message, since it can
  cause spurious test failures.

[ Evan Broder ]
* Enable lua from grub-extras.
* Incorporate the bitop library into lua.
* Add enum_pci function to grub module in lua.
* Switch back to gfxpayload=keep by default, unless the video hardware
  is known to not support it.

[ Mario Limonciello ]
* Built part_msdos and vfat into bootx64.efi (LP: #677758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* parttool.c - common dispatcher and parser for partition operations */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2009  Free Software Foundation, Inc.
5
 
 *
6
 
 *  This program 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 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program 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 this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
 
 */
20
 
 
21
 
#include <grub/types.h>
22
 
#include <grub/misc.h>
23
 
#include <grub/mm.h>
24
 
#include <grub/err.h>
25
 
#include <grub/dl.h>
26
 
#include <grub/normal.h>
27
 
#include <grub/device.h>
28
 
#include <grub/disk.h>
29
 
#include <grub/partition.h>
30
 
#include <grub/parttool.h>
31
 
#include <grub/command.h>
32
 
#include <grub/i18n.h>
33
 
 
34
 
static struct grub_parttool *parts = 0;
35
 
static int curhandle = 0;
36
 
static grub_dl_t mymod;
37
 
static char helpmsg[] =
38
 
  "Perform COMMANDS on partition.\n"
39
 
  "Use \"parttool PARTITION help\" for the list "
40
 
  "of available commands.";
41
 
 
42
 
int
43
 
grub_parttool_register(const char *part_name,
44
 
                       const grub_parttool_function_t func,
45
 
                       const struct grub_parttool_argdesc *args)
46
 
{
47
 
  struct grub_parttool *cur;
48
 
  int nargs = 0;
49
 
 
50
 
  if (! parts)
51
 
    grub_dl_ref (mymod);
52
 
 
53
 
  cur = (struct grub_parttool *) grub_malloc (sizeof (struct grub_parttool));
54
 
  cur->next = parts;
55
 
  cur->name = grub_strdup (part_name);
56
 
  cur->handle = curhandle++;
57
 
  for (nargs = 0; args[nargs].name != 0; nargs++);
58
 
  cur->nargs = nargs;
59
 
  cur->args = (struct grub_parttool_argdesc *)
60
 
    grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc));
61
 
  grub_memcpy (cur->args, args,
62
 
               (nargs + 1) * sizeof (struct grub_parttool_argdesc));
63
 
 
64
 
  cur->func = func;
65
 
  parts = cur;
66
 
  return cur->handle;
67
 
}
68
 
 
69
 
void
70
 
grub_parttool_unregister (int handle)
71
 
{
72
 
  struct grub_parttool *prev = 0, *cur, *t;
73
 
  for (cur = parts; cur; )
74
 
    if (cur->handle == handle)
75
 
      {
76
 
        grub_free (cur->args);
77
 
        grub_free (cur->name);
78
 
        if (prev)
79
 
          prev->next = cur->next;
80
 
        else
81
 
          parts = cur->next;
82
 
        t = cur;
83
 
        cur = cur->next;
84
 
        grub_free (t);
85
 
      }
86
 
    else
87
 
      {
88
 
        prev = cur;
89
 
        cur = cur->next;
90
 
      }
91
 
  if (! parts)
92
 
    grub_dl_unref (mymod);
93
 
}
94
 
 
95
 
static grub_err_t
96
 
grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
97
 
                   int argc, char **args)
98
 
{
99
 
  grub_device_t dev;
100
 
  struct grub_parttool *cur, *ptool;
101
 
  int *parsed;
102
 
  int i, j;
103
 
  grub_err_t err = GRUB_ERR_NONE;
104
 
 
105
 
  auto grub_err_t show_help (void);
106
 
  grub_err_t show_help (void)
107
 
  {
108
 
    int found = 0;
109
 
    for (cur = parts; cur; cur = cur->next)
110
 
      if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0)
111
 
        {
112
 
          struct grub_parttool_argdesc *curarg;
113
 
          found = 1;
114
 
          for (curarg = cur->args; curarg->name; curarg++)
115
 
            {
116
 
              int spacing = 20;
117
 
 
118
 
              spacing -= grub_strlen (curarg->name);
119
 
              grub_printf ("%s", curarg->name);
120
 
 
121
 
              switch (curarg->type)
122
 
                {
123
 
                case GRUB_PARTTOOL_ARG_BOOL:
124
 
                  grub_printf ("+/-");
125
 
                  spacing -= 3;
126
 
                  break;
127
 
 
128
 
                case GRUB_PARTTOOL_ARG_VAL:
129
 
                  grub_printf ("=VAL");
130
 
                  spacing -= 4;
131
 
                  break;
132
 
 
133
 
                    case GRUB_PARTTOOL_ARG_END:
134
 
                      break;
135
 
                }
136
 
              while (spacing-- > 0)
137
 
                grub_printf (" ");
138
 
              grub_printf ("%s\n", curarg->desc);
139
 
            }
140
 
        }
141
 
    if (! found)
142
 
      grub_printf ("Sorry no parttool is available for %s\n",
143
 
                   dev->disk->partition->partmap->name);
144
 
    return GRUB_ERR_NONE;
145
 
  }
146
 
 
147
 
  if (argc < 1)
148
 
    {
149
 
      grub_printf ("%s\n", helpmsg);
150
 
      return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments");
151
 
    }
152
 
 
153
 
  if (args[0][0] == '(' && args[0][grub_strlen (args[0]) - 1] == ')')
154
 
    {
155
 
      args[0][grub_strlen (args[0]) - 1] = 0;
156
 
      dev = grub_device_open (args[0] + 1);
157
 
      args[0][grub_strlen (args[0]) - 1] = ')';
158
 
    }
159
 
  else
160
 
    dev = grub_device_open (args[0]);
161
 
 
162
 
  if (! dev)
163
 
    return grub_errno;
164
 
 
165
 
  if (! dev->disk)
166
 
    {
167
 
      grub_device_close (dev);
168
 
      return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a disk");
169
 
    }
170
 
 
171
 
  if (! dev->disk->partition)
172
 
    {
173
 
      grub_device_close (dev);
174
 
      return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a partition");
175
 
    }
176
 
 
177
 
  /* Load modules. */
178
 
#if !GRUB_NO_MODULES
179
 
  {
180
 
    const char *prefix;
181
 
    prefix = grub_env_get ("prefix");
182
 
    if (prefix)
183
 
      {
184
 
        char *filename;
185
 
 
186
 
        filename = grub_xasprintf ("%s/parttool.lst", prefix);
187
 
        if (filename)
188
 
          {
189
 
            grub_file_t file;
190
 
 
191
 
            file = grub_file_open (filename);
192
 
            if (file)
193
 
              {
194
 
                char *buf = 0;
195
 
                for (;; grub_free(buf))
196
 
                  {
197
 
                    char *p, *name;
198
 
 
199
 
                    buf = grub_file_getline (file);
200
 
 
201
 
                    if (! buf)
202
 
                      break;
203
 
 
204
 
                    name = buf;
205
 
 
206
 
                    if (! grub_isgraph (name[0]))
207
 
                      continue;
208
 
 
209
 
                    p = grub_strchr (name, ':');
210
 
                    if (! p)
211
 
                      continue;
212
 
 
213
 
                    *p = '\0';
214
 
                    while (*++p == ' ')
215
 
                      ;
216
 
 
217
 
                    if (! grub_isgraph (*p))
218
 
                      continue;
219
 
 
220
 
                    if (grub_strcmp (name, dev->disk->partition->partmap->name)
221
 
                        != 0)
222
 
                      continue;
223
 
 
224
 
                    grub_dl_load (p);
225
 
                  }
226
 
 
227
 
                grub_file_close (file);
228
 
              }
229
 
 
230
 
            grub_free (filename);
231
 
          }
232
 
      }
233
 
    /* Ignore errors.  */
234
 
    grub_errno = GRUB_ERR_NONE;
235
 
  }
236
 
#endif
237
 
 
238
 
  if (argc == 1)
239
 
    return show_help ();
240
 
 
241
 
  for (i = 1; i < argc; i++)
242
 
    if (grub_strcmp (args[i], "help") == 0)
243
 
      return show_help ();
244
 
 
245
 
  parsed = (int *) grub_zalloc (argc * sizeof (int));
246
 
 
247
 
  for (i = 1; i < argc; i++)
248
 
    if (! parsed[i])
249
 
      {
250
 
        struct grub_parttool_argdesc *curarg;
251
 
        struct grub_parttool_args *pargs;
252
 
        for (cur = parts; cur; cur = cur->next)
253
 
          if (grub_strcmp (dev->disk->partition->partmap->name, cur->name) == 0)
254
 
            {
255
 
              for (curarg = cur->args; curarg->name; curarg++)
256
 
                if (grub_strncmp (curarg->name, args[i],
257
 
                                  grub_strlen (curarg->name)) == 0
258
 
                    && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL
259
 
                         && (args[i][grub_strlen (curarg->name)] == '+'
260
 
                             || args[i][grub_strlen (curarg->name)] == '-'
261
 
                             || args[i][grub_strlen (curarg->name)] == 0))
262
 
                        || (curarg->type == GRUB_PARTTOOL_ARG_VAL
263
 
                            && args[i][grub_strlen (curarg->name)] == '=')))
264
 
 
265
 
                  break;
266
 
              if (curarg->name)
267
 
                break;
268
 
            }
269
 
        if (! cur)
270
 
          return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised argument %s",
271
 
                             args[i]);
272
 
        ptool = cur;
273
 
        pargs = (struct grub_parttool_args *)
274
 
          grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args));
275
 
        for (j = i; j < argc; j++)
276
 
          if (! parsed[j])
277
 
            {
278
 
              for (curarg = ptool->args; curarg->name; curarg++)
279
 
                if (grub_strncmp (curarg->name, args[i],
280
 
                                   grub_strlen (curarg->name)) == 0
281
 
                    && ((curarg->type == GRUB_PARTTOOL_ARG_BOOL
282
 
                         && (args[j][grub_strlen (curarg->name)] == '+'
283
 
                             || args[j][grub_strlen (curarg->name)] == '-'
284
 
                             || args[j][grub_strlen (curarg->name)] == 0))
285
 
                        || (curarg->type == GRUB_PARTTOOL_ARG_VAL
286
 
                            && args[j][grub_strlen (curarg->name)] == '=')))
287
 
                  {
288
 
                    parsed[j] = 1;
289
 
                    pargs[curarg - ptool->args].set = 1;
290
 
                    switch (curarg->type)
291
 
                      {
292
 
                      case GRUB_PARTTOOL_ARG_BOOL:
293
 
                        pargs[curarg - ptool->args].bool
294
 
                          = (args[j][grub_strlen (curarg->name)] != '-');
295
 
                        break;
296
 
 
297
 
                      case GRUB_PARTTOOL_ARG_VAL:
298
 
                        pargs[curarg - ptool->args].str
299
 
                          = (args[j] + grub_strlen (curarg->name) + 1);
300
 
                        break;
301
 
 
302
 
                      case GRUB_PARTTOOL_ARG_END:
303
 
                        break;
304
 
                      }
305
 
                  }
306
 
            }
307
 
 
308
 
        err = ptool->func (dev, pargs);
309
 
        grub_free (pargs);
310
 
        if (err)
311
 
          break;
312
 
      }
313
 
 
314
 
  grub_free (parsed);
315
 
  grub_device_close (dev);
316
 
  return err;
317
 
}
318
 
 
319
 
static grub_command_t cmd;
320
 
 
321
 
GRUB_MOD_INIT(parttool)
322
 
{
323
 
  mymod = mod;
324
 
  cmd = grub_register_command ("parttool", grub_cmd_parttool,
325
 
                               N_("PARTITION COMMANDS"),
326
 
                               helpmsg);
327
 
}
328
 
 
329
 
GRUB_MOD_FINI(parttool)
330
 
{
331
 
  grub_unregister_command (cmd);
332
 
}