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

« back to all changes in this revision

Viewing changes to util/grub-probe.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:
19
19
 
20
20
#include <config.h>
21
21
#include <grub/types.h>
 
22
#include <grub/emu/misc.h>
 
23
#include <grub/util/misc.h>
22
24
#include <grub/util/misc.h>
23
25
#include <grub/device.h>
24
26
#include <grub/disk.h>
26
28
#include <grub/fs.h>
27
29
#include <grub/partition.h>
28
30
#include <grub/msdos_partition.h>
29
 
#include <grub/util/hostdisk.h>
30
 
#include <grub/util/getroot.h>
 
31
#include <grub/emu/hostdisk.h>
 
32
#include <grub/emu/getroot.h>
31
33
#include <grub/term.h>
32
34
#include <grub/env.h>
33
35
#include <grub/raid.h>
34
36
#include <grub/i18n.h>
35
37
 
36
 
#include <grub_probe_init.h>
37
 
 
38
38
#include <stdio.h>
39
39
#include <unistd.h>
40
40
#include <string.h>
49
49
enum {
50
50
  PRINT_FS,
51
51
  PRINT_FS_UUID,
 
52
  PRINT_FS_LABEL,
52
53
  PRINT_DRIVE,
53
54
  PRINT_DEVICE,
54
55
  PRINT_PARTMAP,
58
59
int print = PRINT_FS;
59
60
static unsigned int argument_is_device = 0;
60
61
 
61
 
void
62
 
grub_putchar (int c)
63
 
{
64
 
  putchar (c);
65
 
}
66
 
 
67
 
int
68
 
grub_getkey (void)
69
 
{
70
 
  return -1;
71
 
}
72
 
 
73
 
struct grub_handler_class grub_term_input_class;
74
 
struct grub_handler_class grub_term_output_class;
75
 
 
76
 
void
77
 
grub_refresh (void)
78
 
{
79
 
  fflush (stdout);
80
 
}
81
 
 
82
62
static void
83
63
probe_partmap (grub_disk_t disk)
84
64
{
 
65
  grub_partition_t part;
 
66
 
85
67
  if (disk->partition == NULL)
86
68
    {
87
69
      grub_util_info ("no partition map found for %s", disk->name);
88
70
      return;
89
71
    }
90
72
 
91
 
  printf ("%s\n", disk->partition->partmap->name);
 
73
  for (part = disk->partition; part; part = part->parent)
 
74
    printf ("%s\n", part->partmap->name);
92
75
}
93
76
 
94
77
static int
116
99
 
117
100
  if (path == NULL)
118
101
    {
119
 
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 
102
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
120
103
      if (! grub_util_check_char_device (device_name))
121
104
        grub_util_error ("%s is not a character device", device_name);
122
105
#else
192
175
            printf ("raid5rec ");
193
176
          if (is_raid6)
194
177
            printf ("raid6rec ");
195
 
          printf ("mdraid ");
 
178
          if (dev->disk->dev->raidname)
 
179
            printf ("%s ", dev->disk->dev->raidname (dev->disk));
196
180
        }
197
181
 
198
182
      if (is_lvm)
243
227
 
244
228
  if (print == PRINT_FS)
245
229
    {
246
 
      if (path)
247
 
        {
248
 
          struct stat st;
249
 
 
250
 
          stat (path, &st);
251
 
 
252
 
          if (S_ISREG (st.st_mode))
253
 
            {
254
 
              /* Regular file.  Verify that we can read it properly.  */
255
 
 
256
 
              grub_file_t file;
257
 
              char *rel_path;
258
 
              grub_util_info ("reading %s via OS facilities", path);
259
 
              filebuf_via_sys = grub_util_read_image (path);
260
 
 
261
 
              rel_path = make_system_path_relative_to_its_root (path);
262
 
              grub_path = xasprintf ("(%s)%s", drive_name, rel_path);
263
 
              free (rel_path);
264
 
              grub_util_info ("reading %s via GRUB facilities", grub_path);
265
 
              file = grub_file_open (grub_path);
266
 
              if (! file)
267
 
                grub_util_error ("cannot open %s via GRUB facilities", grub_path);
268
 
              filebuf_via_grub = xmalloc (file->size);
269
 
              grub_file_read (file, filebuf_via_grub, file->size);
270
 
 
271
 
              grub_util_info ("comparing");
272
 
 
273
 
              if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
274
 
                grub_util_error ("files differ");
275
 
            }
276
 
        }
277
 
 
278
230
      printf ("%s\n", fs->name);
279
231
    }
280
 
 
281
 
  if (print == PRINT_FS_UUID)
 
232
  else if (print == PRINT_FS_UUID)
282
233
    {
283
234
      char *uuid;
284
235
      if (! fs->uuid)
285
236
        grub_util_error ("%s does not support UUIDs", fs->name);
286
237
 
287
 
      fs->uuid (dev, &uuid);
 
238
      if (fs->uuid (dev, &uuid) != GRUB_ERR_NONE)
 
239
        grub_util_error ("%s", grub_errmsg);
288
240
 
289
241
      printf ("%s\n", uuid);
290
242
    }
 
243
  else if (print == PRINT_FS_LABEL)
 
244
    {
 
245
      char *label;
 
246
      if (! fs->label)
 
247
        grub_util_error ("%s does not support labels", fs->name);
 
248
 
 
249
      if (fs->label (dev, &label) != GRUB_ERR_NONE)
 
250
        grub_util_error ("%s", grub_errmsg);
 
251
 
 
252
      printf ("%s\n", label);
 
253
    }
291
254
 
292
255
 end:
293
256
  if (dev)
323
286
\n\
324
287
  -d, --device              given argument is a system device, not a path\n\
325
288
  -m, --device-map=FILE     use FILE as the device map [default=%s]\n\
326
 
  -t, --target=(fs|fs_uuid|drive|device|partmap|abstraction)\n\
 
289
  -t, --target=(fs|fs_uuid|fs_label|drive|device|partmap|abstraction)\n\
327
290
                            print filesystem module, GRUB drive, system device, partition map module or abstraction module [default=fs]\n\
328
291
  -h, --help                display this message and exit\n\
329
292
  -V, --version             print version information and exit\n\
372
335
              print = PRINT_FS;
373
336
            else if (!strcmp (optarg, "fs_uuid"))
374
337
              print = PRINT_FS_UUID;
 
338
            else if (!strcmp (optarg, "fs_label"))
 
339
              print = PRINT_FS_LABEL;
375
340
            else if (!strcmp (optarg, "drive"))
376
341
              print = PRINT_DRIVE;
377
342
            else if (!strcmp (optarg, "device"))
426
391
  /* Initialize all modules. */
427
392
  grub_init_all ();
428
393
 
 
394
  grub_lvm_fini ();
 
395
  grub_mdraid09_fini ();
 
396
  grub_mdraid1x_fini ();
 
397
  grub_raid_fini ();
 
398
  grub_raid_init ();
 
399
  grub_mdraid09_init ();
 
400
  grub_mdraid1x_init ();
 
401
  grub_lvm_init ();
 
402
 
429
403
  /* Do it.  */
430
404
  if (argument_is_device)
431
405
    probe (NULL, argument);