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