~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to partmap/gpt.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
static const grub_gpt_part_type_t grub_gpt_partition_type_empty = GRUB_GPT_PARTITION_TYPE_EMPTY;
34
34
 
 
35
/* 512 << 7 = 65536 byte sectors.  */
 
36
#define MAX_SECTOR_LOG 7
 
37
 
35
38
static struct grub_partition_map grub_gpt_partition_map;
36
39
 
37
40
 
48
51
  grub_uint64_t entries;
49
52
  unsigned int i;
50
53
  int last_offset = 0;
 
54
  int sector_log = 0;
51
55
 
52
56
  /* Read the protective MBR.  */
53
57
  if (grub_disk_read (disk, 0, 0, sizeof (mbr), &mbr))
62
66
    return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found");
63
67
 
64
68
  /* Read the GPT header.  */
65
 
  if (grub_disk_read (disk, 1, 0, sizeof (gpt), &gpt))
66
 
    return grub_errno;
 
69
  for (sector_log = 0; sector_log < MAX_SECTOR_LOG; sector_log++)
 
70
    {
 
71
      if (grub_disk_read (disk, 1 << sector_log, 0, sizeof (gpt), &gpt))
 
72
        return grub_errno;
67
73
 
68
 
  if (grub_memcmp (gpt.magic, grub_gpt_magic, sizeof (grub_gpt_magic)))
 
74
      if (grub_memcmp (gpt.magic, grub_gpt_magic, sizeof (grub_gpt_magic)) == 0)
 
75
        break;
 
76
    }
 
77
  if (sector_log == MAX_SECTOR_LOG)
69
78
    return grub_error (GRUB_ERR_BAD_PART_TABLE, "no valid GPT header");
70
79
 
71
80
  grub_dprintf ("gpt", "Read a valid GPT header\n");
72
81
 
73
 
  entries = grub_le_to_cpu64 (gpt.partitions);
 
82
  entries = grub_le_to_cpu64 (gpt.partitions) << sector_log;
74
83
  for (i = 0; i < grub_le_to_cpu32 (gpt.maxpart); i++)
75
84
    {
76
85
      if (grub_disk_read (disk, entries, last_offset,
81
90
                       sizeof (grub_gpt_partition_type_empty)))
82
91
        {
83
92
          /* Calculate the first block and the size of the partition.  */
84
 
          part.start = grub_le_to_cpu64 (entry.start);
 
93
          part.start = grub_le_to_cpu64 (entry.start) << sector_log;
85
94
          part.len = (grub_le_to_cpu64 (entry.end)
86
 
                      - grub_le_to_cpu64 (entry.start) + 1);
 
95
                      - grub_le_to_cpu64 (entry.start) + 1)  << sector_log;
87
96
          part.offset = entries;
88
97
          part.number = i;
89
98
          part.index = last_offset;