~ilya-yanok/ubuntu/precise/grub2/fix-for-948716

« back to all changes in this revision

Viewing changes to util/i386/pc/grub-setup.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2009-07-25 19:00:53 UTC
  • mfrom: (1.6.3 upstream)
  • mto: (17.4.13 sid)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: james.westby@ubuntu.com-20090725190053-uv3lm6ya3zxs77ep
ImportĀ upstreamĀ versionĀ 1.96+20090725

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <grub/file.h>
26
26
#include <grub/fs.h>
27
27
#include <grub/partition.h>
28
 
#include <grub/msdos_partition.h>
 
28
#include <grub/pc_partition.h>
29
29
#include <grub/gpt_partition.h>
30
30
#include <grub/env.h>
31
31
#include <grub/util/hostdisk.h>
86
86
static void
87
87
setup (const char *dir,
88
88
       const char *boot_file, const char *core_file,
89
 
       const char *root, const char *dest, int must_embed, int force, int fs_probe)
 
89
       const char *root, const char *dest, int must_embed, int force)
90
90
{
91
91
  char *boot_path, *core_path, *core_path_dev;
92
92
  char *boot_img, *core_img;
121
121
  int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk __attribute__ ((unused)),
122
122
                                                 const grub_partition_t p)
123
123
    {
124
 
      struct grub_msdos_partition *pcdata = p->data;
 
124
      struct grub_pc_partition *pcdata = p->data;
125
125
 
126
126
      /* There's always an embed region, and it starts right after the MBR.  */
127
127
      embed_region.start = 1;
128
128
 
129
129
      /* For its end offset, include as many dummy partitions as we can.  */
130
 
      if (! grub_msdos_partition_is_empty (pcdata->dos_type)
131
 
          && ! grub_msdos_partition_is_bsd (pcdata->dos_type)
 
130
      if (! grub_pc_partition_is_empty (pcdata->dos_type)
 
131
          && ! grub_pc_partition_is_bsd (pcdata->dos_type)
132
132
          && embed_region.end > p->start)
133
133
        embed_region.end = p->start;
134
134
 
135
 
      return 0;
 
135
      return 1;
136
136
    }
137
137
 
138
138
  auto int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk,
251
251
  if (grub_disk_read (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, tmp_img))
252
252
    grub_util_error ("%s", grub_errmsg);
253
253
 
254
 
  if (dest_dev->disk->partition && fs_probe)
255
 
    {
256
 
      grub_fs_t fs;
257
 
      fs = grub_fs_probe (dest_dev);
258
 
      if (! fs)
259
 
        grub_util_error ("Unable to identify a filesystem in %s; safety check can't be performed.",
260
 
                         dest_dev->disk->name);
261
 
 
262
 
      if (! fs->reserved_first_sector)
263
 
        grub_util_error ("%s appears to contain a %s filesystem which isn't known to "
264
 
                         "reserve space for DOS-style boot.  Installing GRUB there could "
265
 
                         "result in FILESYSTEM DESTRUCTION if valuable data is overwritten "
266
 
                         "by grub-setup (--skip-fs-probe disables this "
267
 
                         "check, use at your own risk).", dest_dev->disk->name, fs->name);
268
 
    }
269
 
 
270
254
  /* Copy the possible DOS BPB.  */
271
255
  memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START,
272
256
          tmp_img + GRUB_BOOT_MACHINE_BPB_START,
295
279
      if (root_dev->disk->partition)
296
280
        {
297
281
          if (strcmp (root_dev->disk->partition->partmap->name,
298
 
                      "part_msdos") == 0)
 
282
                      "pc_partition_map") == 0)
299
283
            {
300
 
              struct grub_msdos_partition *pcdata =
 
284
              struct grub_pc_partition *pcdata =
301
285
                root_dev->disk->partition->data;
302
286
              dos_part = pcdata->dos_part;
303
287
              bsd_part = pcdata->bsd_part;
304
288
            }
305
289
          else if (strcmp (root_dev->disk->partition->partmap->name,
306
 
                           "part_gpt") == 0)
 
290
                           "gpt_partition_map") == 0)
307
291
            {
308
292
              dos_part = root_dev->disk->partition->index;
309
293
              bsd_part = -1;
354
338
      goto unable_to_embed;
355
339
    }
356
340
 
357
 
  grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, "part_msdos") ?
 
341
  grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, "pc_partition_map") ?
358
342
                                           find_usable_region_gpt : find_usable_region_msdos));
359
343
 
360
344
  if (embed_region.end == embed_region.start)
361
345
    {
362
 
      if (! strcmp (dest_partmap, "part_msdos"))
 
346
      if (! strcmp (dest_partmap, "pc_partition_map"))
363
347
        grub_util_warn ("This msdos-style partition label has no post-MBR gap; embedding won't be possible!");
364
348
      else
365
349
        grub_util_warn ("This GPT partition label has no BIOS Boot Partition; embedding won't be possible!");
368
352
 
369
353
  if ((unsigned long) core_sectors > embed_region.end - embed_region.start)
370
354
    {
371
 
      if (core_sectors > 62)
 
355
      if (core_sectors > 62 * 512)
372
356
        grub_util_warn ("Your core.img is unusually large.  It won't fit in the embedding area.");
373
 
      else if (embed_region.end - embed_region.start < 62)
 
357
      else if (embed_region.end - embed_region.start < 62 * 512)
374
358
        grub_util_warn ("Your embedding area is unusually small.  core.img won't fit in it.");
375
359
      else
376
360
        grub_util_warn ("Embedding area is too small for core.img.");
572
556
    {"device-map", required_argument, 0, 'm'},
573
557
    {"root-device", required_argument, 0, 'r'},
574
558
    {"force", no_argument, 0, 'f'},
575
 
    {"skip-fs-probe", no_argument, 0, 's'},
576
559
    {"help", no_argument, 0, 'h'},
577
560
    {"version", no_argument, 0, 'V'},
578
561
    {"verbose", no_argument, 0, 'v'},
597
580
  -m, --device-map=FILE   use FILE as the device map [default=%s]\n\
598
581
  -r, --root-device=DEV   use DEV as the root device [default=guessed]\n\
599
582
  -f, --force             install even if problems are detected\n\
600
 
  -s, --skip-fs-probe     do not probe for filesystems in DEVICE\n\
601
583
  -h, --help              display this message and exit\n\
602
584
  -V, --version           print version information and exit\n\
603
585
  -v, --verbose           print verbose messages\n\
631
613
  char *dev_map = 0;
632
614
  char *root_dev = 0;
633
615
  char *dest_dev;
634
 
  int must_embed = 0, force = 0, fs_probe = 1;
 
616
  int must_embed = 0, force = 0;
635
617
 
636
618
  progname = "grub-setup";
637
619
 
684
666
            force = 1;
685
667
            break;
686
668
 
687
 
          case 's':
688
 
            fs_probe = 0;
689
 
            break;
690
 
 
691
669
          case 'h':
692
670
            usage (0);
693
671
            break;
789
767
          setup (dir ? : DEFAULT_DIRECTORY,
790
768
                 boot_file ? : DEFAULT_BOOT_FILE,
791
769
                 core_file ? : DEFAULT_CORE_FILE,
792
 
                 root_dev, grub_util_get_grub_dev (devicelist[i]), 1, force, fs_probe);
 
770
                 root_dev, grub_util_get_grub_dev (devicelist[i]), 1, force);
793
771
        }
794
772
    }
795
773
  else
798
776
    setup (dir ? : DEFAULT_DIRECTORY,
799
777
           boot_file ? : DEFAULT_BOOT_FILE,
800
778
           core_file ? : DEFAULT_CORE_FILE,
801
 
           root_dev, dest_dev, must_embed, force, fs_probe);
 
779
           root_dev, dest_dev, must_embed, force);
802
780
 
803
781
  /* Free resources.  */
804
782
  grub_fini_all ();