1 | Index: MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
|
---|
2 | ===================================================================
|
---|
3 | --- MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h (revision 9332)
|
---|
4 | +++ MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h (working copy)
|
---|
5 | @@ -399,6 +399,75 @@
|
---|
6 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
---|
7 | );
|
---|
8 |
|
---|
9 | +/**
|
---|
10 | + Install child handles if the Handle supports Apple format.
|
---|
11 | +
|
---|
12 | + @param This Calling context.
|
---|
13 | + @param Handle Parent Handle.
|
---|
14 | + @param DiskIo Parent DiskIo interface.
|
---|
15 | + @param BlockIo Parent BlockIo interface.
|
---|
16 | + @param DevicePath Parent Device Path.
|
---|
17 | +
|
---|
18 | + @retval EFI_SUCCESS A child handle was added.
|
---|
19 | + @retval EFI_MEDIA_CHANGED Media change was detected.
|
---|
20 | + @retval Others MBR partition was not found.
|
---|
21 | +
|
---|
22 | +**/
|
---|
23 | +EFI_STATUS
|
---|
24 | +PartitionInstallAppleChildHandles (
|
---|
25 | + IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
26 | + IN EFI_HANDLE Handle,
|
---|
27 | + IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
---|
28 | + IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
|
---|
29 | + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
---|
30 | + );
|
---|
31 | +
|
---|
32 | +/**
|
---|
33 | + Install child handles if the Handle supports Apple format.
|
---|
34 | +
|
---|
35 | + @param This Calling context.
|
---|
36 | + @param Handle Parent Handle.
|
---|
37 | + @param DiskIo Parent DiskIo interface.
|
---|
38 | + @param BlockIo Parent BlockIo interface.
|
---|
39 | + @param DevicePath Parent Device Path.
|
---|
40 | +
|
---|
41 | + @retval EFI_SUCCESS A child handle was added.
|
---|
42 | + @retval EFI_MEDIA_CHANGED Media change was detected.
|
---|
43 | + @retval Others Apple partition was not found.
|
---|
44 | +
|
---|
45 | +**/
|
---|
46 | +EFI_STATUS
|
---|
47 | +PartitionInstallAppleChildHandles (
|
---|
48 | + IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
49 | + IN EFI_HANDLE Handle,
|
---|
50 | + IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
---|
51 | + IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
|
---|
52 | + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
---|
53 | + );
|
---|
54 | +
|
---|
55 | +/**
|
---|
56 | + Install child handles if the Handle supports Apple format.
|
---|
57 | +
|
---|
58 | + @param This Calling context.
|
---|
59 | + @param Handle Parent Handle.
|
---|
60 | + @param DiskIo Parent DiskIo interface.
|
---|
61 | + @param BlockIo Parent BlockIo interface.
|
---|
62 | + @param DevicePath Parent Device Path.
|
---|
63 | +
|
---|
64 | + @retval EFI_SUCCESS A child handle was added.
|
---|
65 | + @retval EFI_MEDIA_CHANGED Media change was detected.
|
---|
66 | + @retval Others Apple partition was not found.
|
---|
67 | +
|
---|
68 | +**/
|
---|
69 | +EFI_STATUS
|
---|
70 | +PartitionInstallAppleChildHandles (
|
---|
71 | + IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
72 | + IN EFI_HANDLE Handle,
|
---|
73 | + IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
---|
74 | + IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
|
---|
75 | + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
---|
76 | + );
|
---|
77 | +
|
---|
78 | typedef
|
---|
79 | EFI_STATUS
|
---|
80 | (*PARTITION_DETECT_ROUTINE) (
|
---|
81 | Index: MdeModulePkg/Universal/Disk/PartitionDxe/Apple.c
|
---|
82 | ===================================================================
|
---|
83 | --- MdeModulePkg/Universal/Disk/PartitionDxe/Apple.c (revision 0)
|
---|
84 | +++ MdeModulePkg/Universal/Disk/PartitionDxe/Apple.c (revision 0)
|
---|
85 | @@ -0,0 +1,208 @@
|
---|
86 | +/** @file
|
---|
87 | + Decode an Apple formatted partition table
|
---|
88 | +
|
---|
89 | + Copyright (c) 2009-2010, Oracle Corporation
|
---|
90 | +**/
|
---|
91 | +
|
---|
92 | +
|
---|
93 | +#include "Partition.h"
|
---|
94 | +
|
---|
95 | +#define DPISTRLEN 32
|
---|
96 | +
|
---|
97 | +#pragma pack(1)
|
---|
98 | +typedef struct APPLE_PT_HEADER {
|
---|
99 | + UINT16 sbSig; /* must be BE 0x4552 */
|
---|
100 | + UINT16 sbBlkSize; /* block size of device */
|
---|
101 | + UINT32 sbBlkCount; /* number of blocks on device */
|
---|
102 | + UINT16 sbDevType; /* device type */
|
---|
103 | + UINT16 sbDevId; /* device id */
|
---|
104 | + UINT32 sbData; /* not used */
|
---|
105 | + UINT16 sbDrvrCount; /* driver descriptor count */
|
---|
106 | + UINT16 sbMap[247]; /* descriptor map */
|
---|
107 | +} APPLE_PT_HEADER;
|
---|
108 | +
|
---|
109 | +typedef struct APPLE_PT_ENTRY {
|
---|
110 | + UINT16 signature ; /* must be BE 0x504D for new style PT */
|
---|
111 | + UINT16 reserved_1 ;
|
---|
112 | + UINT32 map_entries ; /* how many PT entries are there */
|
---|
113 | + UINT32 pblock_start ; /* first physical block */
|
---|
114 | + UINT32 pblocks ; /* number of physical blocks */
|
---|
115 | + char name[DPISTRLEN] ; /* name of partition */
|
---|
116 | + char type[DPISTRLEN] ; /* type of partition */
|
---|
117 | + /* Some more data we don't really need */
|
---|
118 | +} APPLE_PT_ENTRY;
|
---|
119 | +#pragma pack()
|
---|
120 | +
|
---|
121 | +static UINT16
|
---|
122 | +be16_to_cpu(UINT16 x)
|
---|
123 | +{
|
---|
124 | + return SwapBytes16(x);
|
---|
125 | +}
|
---|
126 | +
|
---|
127 | +static UINT32
|
---|
128 | +be32_to_cpu(UINT32 x)
|
---|
129 | +{
|
---|
130 | + return SwapBytes32(x);
|
---|
131 | +}
|
---|
132 | +
|
---|
133 | +
|
---|
134 | +/**
|
---|
135 | + Install child handles if the Handle supports Apple partition table format.
|
---|
136 | +
|
---|
137 | + @param[in] This Calling context.
|
---|
138 | + @param[in] Handle Parent Handle
|
---|
139 | + @param[in] DiskIo Parent DiskIo interface
|
---|
140 | + @param[in] BlockIo Parent BlockIo interface
|
---|
141 | + @param[in] DevicePath Parent Device Path
|
---|
142 | +
|
---|
143 | +
|
---|
144 | + @retval EFI_SUCCESS Child handle(s) was added
|
---|
145 | + @retval EFI_MEDIA_CHANGED Media changed Detected
|
---|
146 | + @retval other no child handle was added
|
---|
147 | +
|
---|
148 | +**/
|
---|
149 | +EFI_STATUS
|
---|
150 | +PartitionInstallAppleChildHandles (
|
---|
151 | + IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
152 | + IN EFI_HANDLE Handle,
|
---|
153 | + IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
---|
154 | + IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
|
---|
155 | + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
---|
156 | + )
|
---|
157 | +{
|
---|
158 | + EFI_STATUS Status;
|
---|
159 | + UINT32 Lba;
|
---|
160 | + EFI_BLOCK_IO_MEDIA *Media;
|
---|
161 | + VOID *Block;
|
---|
162 | + //UINTN MaxIndex;
|
---|
163 | + /** @todo: wrong, as this PT can be on both HDD or CD */
|
---|
164 | + CDROM_DEVICE_PATH CdDev;
|
---|
165 | + //EFI_DEVICE_PATH_PROTOCOL Dev;
|
---|
166 | + EFI_STATUS Found;
|
---|
167 | + UINT32 Partition;
|
---|
168 | + UINT32 PartitionEntries;
|
---|
169 | + UINT32 VolSpaceSize;
|
---|
170 | + UINT32 SubBlockSize;
|
---|
171 | + UINT32 BlkPerSec;
|
---|
172 | +
|
---|
173 | + Found = EFI_NOT_FOUND;
|
---|
174 | + Media = BlockIo->Media;
|
---|
175 | + VolSpaceSize = 0;
|
---|
176 | +
|
---|
177 | + Block = AllocatePool ((UINTN) Media->BlockSize);
|
---|
178 | +
|
---|
179 | + if (Block == NULL) {
|
---|
180 | + return EFI_NOT_FOUND;
|
---|
181 | + }
|
---|
182 | +
|
---|
183 | + do {
|
---|
184 | + APPLE_PT_HEADER * Header;
|
---|
185 | +
|
---|
186 | + /* read PT header first */
|
---|
187 | + Lba = 0;
|
---|
188 | +
|
---|
189 | + Status = DiskIo->ReadDisk (
|
---|
190 | + DiskIo,
|
---|
191 | + Media->MediaId,
|
---|
192 | + MultU64x32 (Lba, Media->BlockSize),
|
---|
193 | + Media->BlockSize,
|
---|
194 | + Block
|
---|
195 | + );
|
---|
196 | + if (EFI_ERROR (Status))
|
---|
197 | + {
|
---|
198 | + Found = Status;
|
---|
199 | + break;
|
---|
200 | + }
|
---|
201 | +
|
---|
202 | + Header = (APPLE_PT_HEADER *)Block;
|
---|
203 | + if (be16_to_cpu(Header->sbSig) != 0x4552)
|
---|
204 | + {
|
---|
205 | + break;
|
---|
206 | + }
|
---|
207 | + SubBlockSize = be16_to_cpu(Header->sbBlkSize);
|
---|
208 | + BlkPerSec = Media->BlockSize / SubBlockSize;
|
---|
209 | +
|
---|
210 | + /* Fail if media block size isn't an exact multiple */
|
---|
211 | + if (Media->BlockSize != SubBlockSize * BlkPerSec)
|
---|
212 | + {
|
---|
213 | + break;
|
---|
214 | + }
|
---|
215 | +
|
---|
216 | + /* Now iterate over PT entries and install child handles */
|
---|
217 | + PartitionEntries = 1;
|
---|
218 | + for (Partition = 1; Partition <= PartitionEntries; Partition++)
|
---|
219 | + {
|
---|
220 | + APPLE_PT_ENTRY * Entry;
|
---|
221 | + UINT32 StartLba;
|
---|
222 | + UINT32 SizeLbs;
|
---|
223 | +
|
---|
224 | + Status = DiskIo->ReadDisk (
|
---|
225 | + DiskIo,
|
---|
226 | + Media->MediaId,
|
---|
227 | + MultU64x32 (Partition, SubBlockSize),
|
---|
228 | + SubBlockSize,
|
---|
229 | + Block
|
---|
230 | + );
|
---|
231 | +
|
---|
232 | + if (EFI_ERROR (Status)) {
|
---|
233 | + Status = EFI_NOT_FOUND;
|
---|
234 | + goto done; /* would break, but ... */
|
---|
235 | + }
|
---|
236 | +
|
---|
237 | + Entry = (APPLE_PT_ENTRY *)Block;
|
---|
238 | +
|
---|
239 | + if (be16_to_cpu(Entry->signature) != 0x504D)
|
---|
240 | + {
|
---|
241 | + Print(L"Not a new PT entry: %x", Entry->signature);
|
---|
242 | + continue;
|
---|
243 | + }
|
---|
244 | +
|
---|
245 | + /* First partition contains partitions count */
|
---|
246 | + if (Partition == 1)
|
---|
247 | + {
|
---|
248 | + PartitionEntries = be32_to_cpu(Entry->map_entries);
|
---|
249 | + }
|
---|
250 | +
|
---|
251 | + StartLba = be32_to_cpu(Entry->pblock_start);
|
---|
252 | + SizeLbs = be32_to_cpu(Entry->pblocks);
|
---|
253 | +
|
---|
254 | + if (0 && CompareMem("Apple_HFS", Entry->type, 10) == 0)
|
---|
255 | + Print(L"HFS partition (%d of %d) at LBA 0x%x size=%dM\n",
|
---|
256 | + Partition, PartitionEntries, StartLba,
|
---|
257 | + (UINT32)(MultU64x32(SizeLbs, SubBlockSize) / (1024 * 1024)));
|
---|
258 | +
|
---|
259 | + ZeroMem (&CdDev, sizeof (CdDev));
|
---|
260 | + CdDev.Header.Type = MEDIA_DEVICE_PATH;
|
---|
261 | + CdDev.Header.SubType = MEDIA_CDROM_DP;
|
---|
262 | + SetDevicePathNodeLength (&CdDev.Header, sizeof (CdDev));
|
---|
263 | +
|
---|
264 | + CdDev.BootEntry = 0;
|
---|
265 | + /* Convert from partition to media blocks */
|
---|
266 | + CdDev.PartitionStart = StartLba / BlkPerSec; /* start, LBA */
|
---|
267 | + CdDev.PartitionSize = SizeLbs / BlkPerSec; /* size, LBs */
|
---|
268 | +
|
---|
269 | + Status = PartitionInstallChildHandle (
|
---|
270 | + This,
|
---|
271 | + Handle,
|
---|
272 | + DiskIo,
|
---|
273 | + BlockIo,
|
---|
274 | + DevicePath,
|
---|
275 | + (EFI_DEVICE_PATH_PROTOCOL *) &CdDev,
|
---|
276 | + CdDev.PartitionStart,
|
---|
277 | + CdDev.PartitionStart + CdDev.PartitionSize - 1,
|
---|
278 | + SubBlockSize,
|
---|
279 | + FALSE
|
---|
280 | + );
|
---|
281 | +
|
---|
282 | + if (!EFI_ERROR (Status)) {
|
---|
283 | + Found = EFI_SUCCESS;
|
---|
284 | + }
|
---|
285 | + }
|
---|
286 | +
|
---|
287 | + } while (0);
|
---|
288 | +
|
---|
289 | + done:
|
---|
290 | + FreePool (Block);
|
---|
291 | +
|
---|
292 | + return Found;
|
---|
293 | +}
|
---|
294 | Index: MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
|
---|
295 | ===================================================================
|
---|
296 | --- MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf (revision 9332)
|
---|
297 | +++ MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf (working copy)
|
---|
298 | @@ -41,6 +41,7 @@
|
---|
299 | Mbr.c
|
---|
300 | Gpt.c
|
---|
301 | ElTorito.c
|
---|
302 | + Apple.c
|
---|
303 | Partition.c
|
---|
304 | Partition.h
|
---|
305 |
|
---|
306 | Index: MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
|
---|
307 | ===================================================================
|
---|
308 | --- MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c (revision 9332)
|
---|
309 | +++ MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c (working copy)
|
---|
310 | @@ -34,6 +34,7 @@
|
---|
311 | // Prioritized function list to detect partition table.
|
---|
312 | //
|
---|
313 | PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {
|
---|
314 | + PartitionInstallAppleChildHandles,
|
---|
315 | PartitionInstallGptChildHandles,
|
---|
316 | PartitionInstallElToritoChildHandles,
|
---|
317 | PartitionInstallMbrChildHandles,
|
---|