~colinb/grub/cdbmain

« back to all changes in this revision

Viewing changes to partmap/apple.c

  • Committer: Colin D Bennett
  • Date: 2008-08-03 03:57:46 UTC
  • mfrom: (820.8.1 trunk-clean)
  • Revision ID: colin@gibibit.com-20080803035746-0zn13x8oznory84l
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* apple.c - Read macintosh partition tables.  */
2
2
/*
3
3
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2002,2004,2005,2006,2007  Free Software Foundation, Inc.
 
4
 *  Copyright (C) 2002,2004,2005,2006,2007,2008  Free Software Foundation, Inc.
5
5
 *
6
6
 *  GRUB is free software: you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
22
22
#include <grub/mm.h>
23
23
#include <grub/partition.h>
24
24
 
 
25
#define GRUB_APPLE_HEADER_MAGIC 0x4552
25
26
#define GRUB_APPLE_PART_MAGIC   0x504D
26
27
 
 
28
struct grub_apple_header
 
29
{
 
30
  /* The magic number to identify the partition map, it should have
 
31
     the value `0x4552'.  */
 
32
  grub_uint16_t magic;
 
33
};
 
34
 
27
35
struct grub_apple_part
28
36
{
29
 
  /* The magic number to idenify this as a partition, it should have
 
37
  /* The magic number to identify this as a partition, it should have
30
38
     the value `0x504D'.  */
31
39
  grub_uint16_t magic;
32
40
 
98
106
                                          const grub_partition_t partition))
99
107
{
100
108
  struct grub_partition part;
 
109
  struct grub_apple_header aheader;
101
110
  struct grub_apple_part apart;
102
111
  struct grub_disk raw;
103
112
  int partno = 0;
109
118
 
110
119
  part.partmap = &grub_apple_partition_map;
111
120
 
 
121
  if (grub_disk_read (&raw, 0, 0, sizeof (aheader), (char *) &aheader))
 
122
    return grub_errno;
 
123
 
 
124
  if (grub_be_to_cpu16 (aheader.magic) != GRUB_APPLE_HEADER_MAGIC)
 
125
    {
 
126
      grub_dprintf ("partition",
 
127
                    "bad magic (found 0x%x; wanted 0x%x\n",
 
128
                    grub_be_to_cpu16 (aheader.magic),
 
129
                    GRUB_APPLE_HEADER_MAGIC);
 
130
      goto fail;
 
131
    }
 
132
 
112
133
  for (;;)
113
134
    {
114
135
      if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
147
168
      partno++;
148
169
    }
149
170
 
150
 
  if (pos == GRUB_DISK_SECTOR_SIZE)
151
 
    return grub_error (GRUB_ERR_BAD_PART_TABLE,
152
 
                       "Apple partition map not found.");
 
171
  if (pos != GRUB_DISK_SECTOR_SIZE)
 
172
    return 0;
153
173
 
154
 
  return 0;
 
174
 fail:
 
175
  return grub_error (GRUB_ERR_BAD_PART_TABLE,
 
176
                     "Apple partition map not found.");
155
177
}
156
178
 
157
179