]>
Commit | Line | Data |
---|---|---|
adbcbf8f | 1 | /** @file\r |
2 | Partition driver that produces logical BlockIo devices from a physical\r | |
3 | BlockIo device. The logical BlockIo devices are based on the format\r | |
4 | of the raw block devices media. Currently "El Torito CD-ROM", Legacy\r | |
5 | MBR, and GPT partition schemes are supported.\r | |
6 | \r | |
f42be642 | 7 | Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
adbcbf8f | 12 | \r |
f42be642 | 13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
adbcbf8f | 15 | \r |
16 | **/\r | |
17 | \r | |
18 | \r | |
19 | #include "Partition.h"\r | |
20 | \r | |
21 | //\r | |
ff61847d | 22 | // Partition Driver Global Variables.\r |
adbcbf8f | 23 | //\r |
24 | EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {\r | |
25 | PartitionDriverBindingSupported,\r | |
26 | PartitionDriverBindingStart,\r | |
27 | PartitionDriverBindingStop,\r | |
28 | 0xa,\r | |
29 | NULL,\r | |
30 | NULL\r | |
31 | };\r | |
32 | \r | |
ff61847d | 33 | //\r |
48557c65 | 34 | // Prioritized function list to detect partition table. \r |
ff61847d | 35 | //\r |
adbcbf8f | 36 | PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {\r |
37 | PartitionInstallGptChildHandles,\r | |
38 | PartitionInstallElToritoChildHandles,\r | |
39 | PartitionInstallMbrChildHandles,\r | |
40 | NULL\r | |
41 | };\r | |
42 | \r | |
43 | \r | |
44 | \r | |
45 | /**\r | |
46 | Test to see if this driver supports ControllerHandle. Any ControllerHandle\r | |
47 | than contains a BlockIo and DiskIo protocol can be supported.\r | |
48 | \r | |
49 | @param This Protocol instance pointer.\r | |
50 | @param ControllerHandle Handle of device to test\r | |
51 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
52 | device to start.\r | |
53 | \r | |
54 | @retval EFI_SUCCESS This driver supports this device\r | |
55 | @retval EFI_ALREADY_STARTED This driver is already running on this device\r | |
56 | @retval other This driver does not support this device\r | |
57 | \r | |
58 | **/\r | |
59 | EFI_STATUS\r | |
60 | EFIAPI\r | |
61 | PartitionDriverBindingSupported (\r | |
62 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
63 | IN EFI_HANDLE ControllerHandle,\r | |
64 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
65 | )\r | |
66 | {\r | |
67 | EFI_STATUS Status;\r | |
68 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
69 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
70 | EFI_DEV_PATH *Node;\r | |
71 | \r | |
72 | if (RemainingDevicePath != NULL) {\r | |
73 | Node = (EFI_DEV_PATH *) RemainingDevicePath;\r | |
74 | if (Node->DevPath.Type != MEDIA_DEVICE_PATH ||\r | |
75 | Node->DevPath.SubType != MEDIA_HARDDRIVE_DP ||\r | |
76 | DevicePathNodeLength (&Node->DevPath) != sizeof (HARDDRIVE_DEVICE_PATH)\r | |
77 | ) {\r | |
78 | return EFI_UNSUPPORTED;\r | |
79 | }\r | |
80 | }\r | |
81 | //\r | |
82 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
83 | //\r | |
84 | Status = gBS->OpenProtocol (\r | |
85 | ControllerHandle,\r | |
86 | &gEfiDevicePathProtocolGuid,\r | |
87 | (VOID **) &ParentDevicePath,\r | |
88 | This->DriverBindingHandle,\r | |
89 | ControllerHandle,\r | |
90 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
91 | );\r | |
92 | if (Status == EFI_ALREADY_STARTED) {\r | |
93 | return EFI_SUCCESS;\r | |
94 | }\r | |
95 | \r | |
96 | if (EFI_ERROR (Status)) {\r | |
97 | return Status;\r | |
98 | }\r | |
99 | //\r | |
100 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
101 | //\r | |
102 | gBS->CloseProtocol (\r | |
ff61847d | 103 | ControllerHandle,\r |
104 | &gEfiDevicePathProtocolGuid,\r | |
105 | This->DriverBindingHandle,\r | |
106 | ControllerHandle\r | |
107 | );\r | |
adbcbf8f | 108 | \r |
109 | //\r | |
110 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
111 | //\r | |
112 | Status = gBS->OpenProtocol (\r | |
113 | ControllerHandle,\r | |
114 | &gEfiDiskIoProtocolGuid,\r | |
115 | (VOID **) &DiskIo,\r | |
116 | This->DriverBindingHandle,\r | |
117 | ControllerHandle,\r | |
118 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
119 | );\r | |
120 | if (Status == EFI_ALREADY_STARTED) {\r | |
121 | return EFI_SUCCESS;\r | |
122 | }\r | |
123 | \r | |
124 | if (EFI_ERROR (Status)) {\r | |
125 | return Status;\r | |
126 | }\r | |
127 | //\r | |
128 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
129 | //\r | |
130 | gBS->CloseProtocol (\r | |
131 | ControllerHandle,\r | |
132 | &gEfiDiskIoProtocolGuid,\r | |
133 | This->DriverBindingHandle,\r | |
134 | ControllerHandle\r | |
135 | );\r | |
136 | \r | |
137 | //\r | |
138 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
139 | //\r | |
140 | Status = gBS->OpenProtocol (\r | |
141 | ControllerHandle,\r | |
142 | &gEfiBlockIoProtocolGuid,\r | |
143 | NULL,\r | |
144 | This->DriverBindingHandle,\r | |
145 | ControllerHandle,\r | |
146 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
147 | );\r | |
148 | \r | |
149 | return Status;\r | |
150 | }\r | |
151 | \r | |
152 | \r | |
153 | /**\r | |
154 | Start this driver on ControllerHandle by opening a Block IO and Disk IO\r | |
155 | protocol, reading Device Path, and creating a child handle with a\r | |
156 | Disk IO and device path protocol.\r | |
157 | \r | |
158 | @param This Protocol instance pointer.\r | |
159 | @param ControllerHandle Handle of device to bind driver to\r | |
160 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
161 | device to start.\r | |
162 | \r | |
163 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r | |
164 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r | |
165 | @retval other This driver does not support this device\r | |
166 | \r | |
167 | **/\r | |
168 | EFI_STATUS\r | |
169 | EFIAPI\r | |
170 | PartitionDriverBindingStart (\r | |
171 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
172 | IN EFI_HANDLE ControllerHandle,\r | |
173 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
174 | )\r | |
175 | {\r | |
176 | EFI_STATUS Status;\r | |
177 | EFI_STATUS OpenStatus;\r | |
178 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
179 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
180 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
181 | PARTITION_DETECT_ROUTINE *Routine;\r | |
182 | \r | |
183 | Status = gBS->OpenProtocol (\r | |
184 | ControllerHandle,\r | |
185 | &gEfiBlockIoProtocolGuid,\r | |
186 | (VOID **) &BlockIo,\r | |
187 | This->DriverBindingHandle,\r | |
188 | ControllerHandle,\r | |
189 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
190 | );\r | |
191 | if (EFI_ERROR (Status)) {\r | |
192 | return Status;\r | |
193 | }\r | |
194 | //\r | |
195 | // Get the Device Path Protocol on ControllerHandle's handle\r | |
196 | //\r | |
197 | Status = gBS->OpenProtocol (\r | |
198 | ControllerHandle,\r | |
199 | &gEfiDevicePathProtocolGuid,\r | |
200 | (VOID **) &ParentDevicePath,\r | |
201 | This->DriverBindingHandle,\r | |
202 | ControllerHandle,\r | |
203 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
204 | );\r | |
205 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
206 | return Status;\r | |
207 | }\r | |
208 | \r | |
209 | Status = gBS->OpenProtocol (\r | |
210 | ControllerHandle,\r | |
211 | &gEfiDiskIoProtocolGuid,\r | |
212 | (VOID **) &DiskIo,\r | |
213 | This->DriverBindingHandle,\r | |
214 | ControllerHandle,\r | |
215 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
216 | );\r | |
217 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
218 | gBS->CloseProtocol (\r | |
219 | ControllerHandle,\r | |
220 | &gEfiDevicePathProtocolGuid,\r | |
221 | This->DriverBindingHandle,\r | |
222 | ControllerHandle\r | |
223 | );\r | |
224 | return Status;\r | |
225 | }\r | |
226 | \r | |
227 | OpenStatus = Status;\r | |
228 | \r | |
229 | //\r | |
230 | // If no media is present, do nothing here.\r | |
231 | //\r | |
232 | Status = EFI_UNSUPPORTED;\r | |
233 | if (BlockIo->Media->MediaPresent) {\r | |
234 | //\r | |
235 | // Try for GPT, then El Torito, and then legacy MBR partition types. If the\r | |
236 | // media supports a given partition type install child handles to represent\r | |
237 | // the partitions described by the media.\r | |
238 | //\r | |
239 | Routine = &mPartitionDetectRoutineTable[0];\r | |
240 | while (*Routine != NULL) {\r | |
241 | Status = (*Routine) (\r | |
242 | This,\r | |
243 | ControllerHandle,\r | |
244 | DiskIo,\r | |
245 | BlockIo,\r | |
246 | ParentDevicePath\r | |
247 | );\r | |
248 | if (!EFI_ERROR (Status) || Status == EFI_MEDIA_CHANGED) {\r | |
249 | break;\r | |
250 | }\r | |
251 | Routine++;\r | |
252 | }\r | |
253 | }\r | |
254 | //\r | |
255 | // In the case that the driver is already started (OpenStatus == EFI_ALREADY_STARTED),\r | |
256 | // the DevicePathProtocol and the DiskIoProtocol are not actually opened by the\r | |
257 | // driver. So don't try to close them. Otherwise, we will break the dependency\r | |
258 | // between the controller and the driver set up before.\r | |
259 | //\r | |
260 | if (EFI_ERROR (Status) && !EFI_ERROR (OpenStatus) && Status != EFI_MEDIA_CHANGED) {\r | |
261 | gBS->CloseProtocol (\r | |
262 | ControllerHandle,\r | |
263 | &gEfiDiskIoProtocolGuid,\r | |
264 | This->DriverBindingHandle,\r | |
265 | ControllerHandle\r | |
266 | );\r | |
267 | \r | |
268 | gBS->CloseProtocol (\r | |
269 | ControllerHandle,\r | |
270 | &gEfiDevicePathProtocolGuid,\r | |
271 | This->DriverBindingHandle,\r | |
272 | ControllerHandle\r | |
273 | );\r | |
274 | }\r | |
275 | \r | |
276 | return Status;\r | |
277 | }\r | |
278 | \r | |
279 | \r | |
280 | /**\r | |
48557c65 | 281 | Stop this driver on ControllerHandle. Support stopping any child handles\r |
adbcbf8f | 282 | created by this driver.\r |
283 | \r | |
284 | @param This Protocol instance pointer.\r | |
285 | @param ControllerHandle Handle of device to stop driver on\r | |
286 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
287 | children is zero stop the entire bus driver.\r | |
288 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
289 | \r | |
290 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
291 | @retval other This driver was not removed from this device\r | |
292 | \r | |
293 | **/\r | |
294 | EFI_STATUS\r | |
295 | EFIAPI\r | |
296 | PartitionDriverBindingStop (\r | |
297 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
298 | IN EFI_HANDLE ControllerHandle,\r | |
299 | IN UINTN NumberOfChildren,\r | |
300 | IN EFI_HANDLE *ChildHandleBuffer\r | |
301 | )\r | |
302 | {\r | |
303 | EFI_STATUS Status;\r | |
304 | UINTN Index;\r | |
305 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
306 | BOOLEAN AllChildrenStopped;\r | |
307 | PARTITION_PRIVATE_DATA *Private;\r | |
308 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
309 | \r | |
310 | if (NumberOfChildren == 0) {\r | |
311 | //\r | |
312 | // Close the bus driver\r | |
313 | //\r | |
314 | gBS->CloseProtocol (\r | |
315 | ControllerHandle,\r | |
316 | &gEfiDiskIoProtocolGuid,\r | |
317 | This->DriverBindingHandle,\r | |
318 | ControllerHandle\r | |
319 | );\r | |
320 | \r | |
321 | gBS->CloseProtocol (\r | |
322 | ControllerHandle,\r | |
323 | &gEfiDevicePathProtocolGuid,\r | |
324 | This->DriverBindingHandle,\r | |
325 | ControllerHandle\r | |
326 | );\r | |
327 | \r | |
328 | return EFI_SUCCESS;\r | |
329 | }\r | |
330 | \r | |
331 | AllChildrenStopped = TRUE;\r | |
332 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
333 | Status = gBS->OpenProtocol (\r | |
334 | ChildHandleBuffer[Index],\r | |
335 | &gEfiBlockIoProtocolGuid,\r | |
336 | (VOID **) &BlockIo,\r | |
337 | This->DriverBindingHandle,\r | |
338 | ControllerHandle,\r | |
339 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
340 | );\r | |
341 | if (!EFI_ERROR (Status)) {\r | |
342 | \r | |
343 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (BlockIo);\r | |
344 | \r | |
345 | //\r | |
346 | // All Software protocols have be freed from the handle so remove it.\r | |
347 | //\r | |
348 | BlockIo->FlushBlocks (BlockIo);\r | |
349 | \r | |
350 | Status = gBS->CloseProtocol (\r | |
351 | ControllerHandle,\r | |
352 | &gEfiDiskIoProtocolGuid,\r | |
353 | This->DriverBindingHandle,\r | |
354 | ChildHandleBuffer[Index]\r | |
355 | );\r | |
356 | \r | |
357 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
358 | ChildHandleBuffer[Index],\r | |
359 | &gEfiDevicePathProtocolGuid,\r | |
360 | Private->DevicePath,\r | |
361 | &gEfiBlockIoProtocolGuid,\r | |
362 | &Private->BlockIo,\r | |
363 | Private->EspGuid,\r | |
364 | NULL,\r | |
365 | NULL\r | |
366 | );\r | |
367 | if (EFI_ERROR (Status)) {\r | |
368 | gBS->OpenProtocol (\r | |
369 | ControllerHandle,\r | |
370 | &gEfiDiskIoProtocolGuid,\r | |
371 | (VOID **) &DiskIo,\r | |
372 | This->DriverBindingHandle,\r | |
373 | ChildHandleBuffer[Index],\r | |
374 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
375 | );\r | |
376 | } else {\r | |
377 | FreePool (Private->DevicePath);\r | |
378 | FreePool (Private);\r | |
379 | }\r | |
380 | \r | |
381 | }\r | |
382 | \r | |
383 | if (EFI_ERROR (Status)) {\r | |
384 | AllChildrenStopped = FALSE;\r | |
385 | }\r | |
386 | }\r | |
387 | \r | |
388 | if (!AllChildrenStopped) {\r | |
389 | return EFI_DEVICE_ERROR;\r | |
390 | }\r | |
391 | \r | |
392 | return EFI_SUCCESS;\r | |
393 | }\r | |
394 | \r | |
395 | \r | |
396 | /**\r | |
397 | Reset the Block Device.\r | |
398 | \r | |
399 | @param This Protocol instance pointer.\r | |
400 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
401 | \r | |
402 | @retval EFI_SUCCESS The device was reset.\r | |
403 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
404 | not be reset.\r | |
405 | \r | |
406 | **/\r | |
adbcbf8f | 407 | EFI_STATUS\r |
408 | EFIAPI\r | |
409 | PartitionReset (\r | |
410 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
411 | IN BOOLEAN ExtendedVerification\r | |
412 | )\r | |
413 | {\r | |
414 | PARTITION_PRIVATE_DATA *Private;\r | |
415 | \r | |
416 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
417 | \r | |
418 | return Private->ParentBlockIo->Reset (\r | |
419 | Private->ParentBlockIo,\r | |
420 | ExtendedVerification\r | |
421 | );\r | |
422 | }\r | |
423 | \r | |
424 | \r | |
425 | /**\r | |
426 | Read by using the Disk IO protocol on the parent device. Lba addresses\r | |
427 | must be converted to byte offsets.\r | |
428 | \r | |
429 | @param This Protocol instance pointer.\r | |
430 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
431 | @param Lba The starting Logical Block Address to read from\r | |
432 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
433 | @param Buffer Buffer containing read data\r | |
434 | \r | |
435 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
436 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
437 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
438 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
439 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
440 | @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not\r | |
441 | valid for the device.\r | |
442 | \r | |
443 | **/\r | |
adbcbf8f | 444 | EFI_STATUS\r |
445 | EFIAPI\r | |
446 | PartitionReadBlocks (\r | |
447 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
448 | IN UINT32 MediaId,\r | |
449 | IN EFI_LBA Lba,\r | |
450 | IN UINTN BufferSize,\r | |
451 | OUT VOID *Buffer\r | |
452 | )\r | |
453 | {\r | |
454 | PARTITION_PRIVATE_DATA *Private;\r | |
455 | UINT64 Offset;\r | |
456 | \r | |
457 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
458 | \r | |
459 | if (BufferSize % Private->BlockSize != 0) {\r | |
460 | return EFI_BAD_BUFFER_SIZE;\r | |
461 | }\r | |
462 | \r | |
463 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
464 | if (Offset + BufferSize > Private->End) {\r | |
465 | return EFI_INVALID_PARAMETER;\r | |
466 | }\r | |
467 | //\r | |
468 | // Because some kinds of partition have different block size from their parent\r | |
469 | // device, we call the Disk IO protocol on the parent device, not the Block IO\r | |
470 | // protocol\r | |
471 | //\r | |
472 | return Private->DiskIo->ReadDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r | |
473 | }\r | |
474 | \r | |
475 | /**\r | |
476 | Write by using the Disk IO protocol on the parent device. Lba addresses\r | |
477 | must be converted to byte offsets.\r | |
478 | \r | |
479 | @param This Protocol instance pointer.\r | |
480 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
481 | @param Lba The starting Logical Block Address to read from\r | |
482 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
483 | @param Buffer Buffer containing read data\r | |
484 | \r | |
485 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
486 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
487 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
488 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
489 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
490 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
491 | @retval EFI_INVALID_PARAMETER The write request contains a LBA that is not\r | |
492 | valid for the device.\r | |
493 | \r | |
494 | **/\r | |
adbcbf8f | 495 | EFI_STATUS\r |
496 | EFIAPI\r | |
497 | PartitionWriteBlocks (\r | |
498 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
499 | IN UINT32 MediaId,\r | |
500 | IN EFI_LBA Lba,\r | |
501 | IN UINTN BufferSize,\r | |
502 | OUT VOID *Buffer\r | |
503 | )\r | |
504 | {\r | |
505 | PARTITION_PRIVATE_DATA *Private;\r | |
506 | UINT64 Offset;\r | |
507 | \r | |
508 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
509 | \r | |
510 | if (BufferSize % Private->BlockSize != 0) {\r | |
511 | return EFI_BAD_BUFFER_SIZE;\r | |
512 | }\r | |
513 | \r | |
514 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
515 | if (Offset + BufferSize > Private->End) {\r | |
516 | return EFI_INVALID_PARAMETER;\r | |
517 | }\r | |
518 | //\r | |
519 | // Because some kinds of partition have different block size from their parent\r | |
520 | // device, we call the Disk IO protocol on the parent device, not the Block IO\r | |
521 | // protocol\r | |
522 | //\r | |
523 | return Private->DiskIo->WriteDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r | |
524 | }\r | |
525 | \r | |
526 | \r | |
527 | /**\r | |
528 | Flush the parent Block Device.\r | |
529 | \r | |
530 | @param This Protocol instance pointer.\r | |
531 | \r | |
532 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
533 | @retval EFI_DEVICE_ERROR The device reported an error while writting back the data\r | |
534 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
535 | \r | |
536 | **/\r | |
adbcbf8f | 537 | EFI_STATUS\r |
538 | EFIAPI\r | |
539 | PartitionFlushBlocks (\r | |
540 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
541 | )\r | |
542 | {\r | |
543 | PARTITION_PRIVATE_DATA *Private;\r | |
544 | \r | |
545 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
546 | \r | |
547 | return Private->ParentBlockIo->FlushBlocks (Private->ParentBlockIo);\r | |
548 | }\r | |
549 | \r | |
550 | \r | |
551 | \r | |
552 | /**\r | |
553 | Create a child handle for a logical block device that represents the\r | |
554 | bytes Start to End of the Parent Block IO device.\r | |
555 | \r | |
a8d0c20e | 556 | @param[in] This Protocol instance pointer\r |
adbcbf8f | 557 | @param[in] ParentHandle Parent Handle for new child\r |
558 | @param[in] ParentDiskIo Parent DiskIo interface\r | |
559 | @param[in] ParentBlockIo Parent BlockIo interface\r | |
560 | @param[in] ParentDevicePath Parent Device Path\r | |
561 | @param[in] DevicePathNode Child Device Path node\r | |
562 | @param[in] Start Start Block\r | |
563 | @param[in] End End Block\r | |
564 | @param[in] BlockSize Child block size\r | |
565 | @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle\r | |
566 | \r | |
567 | @retval EFI_SUCCESS A child handle was added\r | |
568 | @retval other A child handle was not added\r | |
569 | \r | |
570 | **/\r | |
571 | EFI_STATUS\r | |
572 | PartitionInstallChildHandle (\r | |
573 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
574 | IN EFI_HANDLE ParentHandle,\r | |
575 | IN EFI_DISK_IO_PROTOCOL *ParentDiskIo,\r | |
576 | IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo,\r | |
577 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r | |
578 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
579 | IN EFI_LBA Start,\r | |
580 | IN EFI_LBA End,\r | |
581 | IN UINT32 BlockSize,\r | |
582 | IN BOOLEAN InstallEspGuid\r | |
583 | )\r | |
584 | {\r | |
585 | EFI_STATUS Status;\r | |
586 | PARTITION_PRIVATE_DATA *Private;\r | |
587 | \r | |
588 | Private = AllocateZeroPool (sizeof (PARTITION_PRIVATE_DATA));\r | |
589 | if (Private == NULL) {\r | |
590 | return EFI_OUT_OF_RESOURCES;\r | |
591 | }\r | |
592 | \r | |
593 | Private->Signature = PARTITION_PRIVATE_DATA_SIGNATURE;\r | |
594 | \r | |
595 | Private->Start = MultU64x32 (Start, ParentBlockIo->Media->BlockSize);\r | |
596 | Private->End = MultU64x32 (End + 1, ParentBlockIo->Media->BlockSize);\r | |
597 | \r | |
598 | Private->BlockSize = BlockSize;\r | |
599 | Private->ParentBlockIo = ParentBlockIo;\r | |
600 | Private->DiskIo = ParentDiskIo;\r | |
601 | \r | |
602 | Private->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;\r | |
603 | \r | |
604 | Private->BlockIo.Media = &Private->Media;\r | |
605 | CopyMem (Private->BlockIo.Media, ParentBlockIo->Media, sizeof (EFI_BLOCK_IO_MEDIA));\r | |
606 | Private->Media.LogicalPartition = TRUE;\r | |
607 | Private->Media.LastBlock = DivU64x32 (\r | |
608 | MultU64x32 (\r | |
609 | End - Start + 1,\r | |
610 | ParentBlockIo->Media->BlockSize\r | |
611 | ),\r | |
612 | BlockSize\r | |
613 | ) - 1;\r | |
614 | \r | |
615 | Private->Media.BlockSize = (UINT32) BlockSize;\r | |
616 | \r | |
617 | Private->BlockIo.Reset = PartitionReset;\r | |
618 | Private->BlockIo.ReadBlocks = PartitionReadBlocks;\r | |
619 | Private->BlockIo.WriteBlocks = PartitionWriteBlocks;\r | |
620 | Private->BlockIo.FlushBlocks = PartitionFlushBlocks;\r | |
621 | \r | |
622 | Private->DevicePath = AppendDevicePathNode (ParentDevicePath, DevicePathNode);\r | |
623 | \r | |
624 | if (Private->DevicePath == NULL) {\r | |
625 | FreePool (Private);\r | |
626 | return EFI_OUT_OF_RESOURCES;\r | |
627 | }\r | |
628 | \r | |
629 | if (InstallEspGuid) {\r | |
630 | Private->EspGuid = &gEfiPartTypeSystemPartGuid;\r | |
631 | } else {\r | |
632 | //\r | |
633 | // If NULL InstallMultipleProtocolInterfaces will ignore it.\r | |
634 | //\r | |
635 | Private->EspGuid = NULL;\r | |
636 | }\r | |
637 | //\r | |
638 | // Create the new handle\r | |
639 | //\r | |
640 | Private->Handle = NULL;\r | |
641 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
642 | &Private->Handle,\r | |
643 | &gEfiDevicePathProtocolGuid,\r | |
644 | Private->DevicePath,\r | |
645 | &gEfiBlockIoProtocolGuid,\r | |
646 | &Private->BlockIo,\r | |
647 | Private->EspGuid,\r | |
648 | NULL,\r | |
649 | NULL\r | |
650 | );\r | |
651 | \r | |
652 | if (!EFI_ERROR (Status)) {\r | |
653 | //\r | |
654 | // Open the Parent Handle for the child\r | |
655 | //\r | |
656 | Status = gBS->OpenProtocol (\r | |
657 | ParentHandle,\r | |
658 | &gEfiDiskIoProtocolGuid,\r | |
659 | (VOID **) &ParentDiskIo,\r | |
660 | This->DriverBindingHandle,\r | |
661 | Private->Handle,\r | |
662 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
663 | );\r | |
664 | } else {\r | |
665 | FreePool (Private->DevicePath);\r | |
666 | FreePool (Private);\r | |
667 | }\r | |
668 | \r | |
669 | return Status;\r | |
670 | }\r | |
671 | \r | |
672 | \r | |
673 | /**\r | |
674 | The user Entry Point for module Partition. The user code starts with this function.\r | |
675 | \r | |
676 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
677 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
678 | \r | |
679 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
680 | @retval other Some error occurs when executing this entry point.\r | |
681 | \r | |
682 | **/\r | |
683 | EFI_STATUS\r | |
684 | EFIAPI\r | |
685 | InitializePartition (\r | |
686 | IN EFI_HANDLE ImageHandle,\r | |
687 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
688 | )\r | |
689 | {\r | |
690 | EFI_STATUS Status;\r | |
691 | \r | |
692 | //\r | |
693 | // Install driver model protocol(s).\r | |
694 | //\r | |
d38a0f44 | 695 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
adbcbf8f | 696 | ImageHandle,\r |
697 | SystemTable,\r | |
698 | &gPartitionDriverBinding,\r | |
699 | ImageHandle,\r | |
700 | &gPartitionComponentName,\r | |
d38a0f44 | 701 | &gPartitionComponentName2\r |
adbcbf8f | 702 | );\r |
703 | ASSERT_EFI_ERROR (Status);\r | |
704 | \r | |
705 | \r | |
706 | return Status;\r | |
707 | }\r | |
708 | \r |