]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.c
Move SecExtractGuidedSectionLib instance from OvmfPkg to MdePkg
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / DiskIoDxe / DiskIo.c
CommitLineData
adbcbf8f 1/** @file\r
ff61847d 2 DiskIo driver that lays on every BlockIo protocol in the system.\r
adbcbf8f 3 DiskIo converts a block oriented device to a byte oriented device.\r
4\r
ff61847d 5 Disk access may have to handle unaligned request about sector boundaries.\r
adbcbf8f 6 There are three cases:\r
7 UnderRun - The first byte is not on a sector boundary or the read request is\r
8 less than a sector in length.\r
9 Aligned - A read of N contiguous sectors.\r
10 OverRun - The last byte is not on a sector boundary.\r
11\r
e5eed7d3
HT
12Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
13This program and the accompanying materials\r
f42be642 14are licensed and made available under the terms and conditions of the BSD License\r
15which accompanies this distribution. The full text of the license may be found at\r
16http://opensource.org/licenses/bsd-license.php\r
17\r
18THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
19WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
adbcbf8f 20\r
21**/\r
22\r
23#include "DiskIo.h"\r
24\r
ff61847d 25//\r
26// Driver binding protocol implementation for DiskIo driver.\r
27//\r
adbcbf8f 28EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding = {\r
29 DiskIoDriverBindingSupported,\r
30 DiskIoDriverBindingStart,\r
31 DiskIoDriverBindingStop,\r
32 0xa,\r
33 NULL,\r
34 NULL\r
35};\r
36\r
ff61847d 37//\r
38// Template for DiskIo private data structure.\r
39// The pointer to BlockIo protocol interface is assigned dynamically.\r
40//\r
adbcbf8f 41DISK_IO_PRIVATE_DATA gDiskIoPrivateDataTemplate = {\r
42 DISK_IO_PRIVATE_DATA_SIGNATURE,\r
43 {\r
44 EFI_DISK_IO_PROTOCOL_REVISION,\r
45 DiskIoReadDisk,\r
46 DiskIoWriteDisk\r
47 },\r
48 NULL\r
49};\r
50\r
51\r
52/**\r
53 Test to see if this driver supports ControllerHandle. \r
54\r
55 @param This Protocol instance pointer.\r
56 @param ControllerHandle Handle of device to test\r
57 @param RemainingDevicePath Optional parameter use to pick a specific child\r
58 device to start.\r
59\r
60 @retval EFI_SUCCESS This driver supports this device\r
61 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
62 @retval other This driver does not support this device\r
63\r
64**/\r
65EFI_STATUS\r
66EFIAPI\r
67DiskIoDriverBindingSupported (\r
68 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
69 IN EFI_HANDLE ControllerHandle,\r
70 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
71 )\r
72{\r
73 EFI_STATUS Status;\r
74 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
75\r
76 //\r
77 // Open the IO Abstraction(s) needed to perform the supported test.\r
78 //\r
79 Status = gBS->OpenProtocol (\r
80 ControllerHandle,\r
81 &gEfiBlockIoProtocolGuid,\r
82 (VOID **) &BlockIo,\r
83 This->DriverBindingHandle,\r
84 ControllerHandle,\r
85 EFI_OPEN_PROTOCOL_BY_DRIVER\r
86 );\r
87 if (EFI_ERROR (Status)) {\r
88 return Status;\r
89 }\r
90\r
91 //\r
92 // Close the I/O Abstraction(s) used to perform the supported test.\r
93 //\r
94 gBS->CloseProtocol (\r
95 ControllerHandle,\r
96 &gEfiBlockIoProtocolGuid,\r
97 This->DriverBindingHandle,\r
98 ControllerHandle\r
99 );\r
100 return EFI_SUCCESS;\r
101}\r
102\r
103\r
104/**\r
105 Start this driver on ControllerHandle by opening a Block IO protocol and\r
106 installing a Disk IO protocol on ControllerHandle.\r
107\r
108 @param This Protocol instance pointer.\r
109 @param ControllerHandle Handle of device to bind driver to\r
110 @param RemainingDevicePath Optional parameter use to pick a specific child\r
111 device to start.\r
112\r
113 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
114 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
115 @retval other This driver does not support this device\r
116\r
117**/\r
118EFI_STATUS\r
119EFIAPI\r
120DiskIoDriverBindingStart (\r
121 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
122 IN EFI_HANDLE ControllerHandle,\r
123 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
124 )\r
125{\r
126 EFI_STATUS Status;\r
127 DISK_IO_PRIVATE_DATA *Private;\r
128\r
129 Private = NULL;\r
130\r
131 //\r
132 // Connect to the Block IO interface on ControllerHandle.\r
133 //\r
134 Status = gBS->OpenProtocol (\r
135 ControllerHandle,\r
136 &gEfiBlockIoProtocolGuid,\r
137 (VOID **) &gDiskIoPrivateDataTemplate.BlockIo,\r
138 This->DriverBindingHandle,\r
139 ControllerHandle,\r
140 EFI_OPEN_PROTOCOL_BY_DRIVER\r
141 );\r
142 if (EFI_ERROR (Status)) {\r
143 return Status;\r
144 }\r
145 \r
146 //\r
147 // Initialize the Disk IO device instance.\r
148 //\r
149 Private = AllocateCopyPool (sizeof (DISK_IO_PRIVATE_DATA), &gDiskIoPrivateDataTemplate);\r
150 if (Private == NULL) {\r
151 Status = EFI_OUT_OF_RESOURCES;\r
152 goto ErrorExit;\r
153 }\r
154 \r
155 //\r
156 // Install protocol interfaces for the Disk IO device.\r
157 //\r
158 Status = gBS->InstallProtocolInterface (\r
159 &ControllerHandle,\r
160 &gEfiDiskIoProtocolGuid,\r
161 EFI_NATIVE_INTERFACE,\r
162 &Private->DiskIo\r
163 );\r
164\r
165ErrorExit:\r
166 if (EFI_ERROR (Status)) {\r
167\r
168 if (Private != NULL) {\r
169 FreePool (Private);\r
170 }\r
171\r
172 gBS->CloseProtocol (\r
173 ControllerHandle,\r
174 &gEfiBlockIoProtocolGuid,\r
175 This->DriverBindingHandle,\r
176 ControllerHandle\r
177 );\r
178 }\r
179\r
180 return Status;\r
181}\r
182\r
183\r
184/**\r
185 Stop this driver on ControllerHandle by removing Disk IO protocol and closing\r
186 the Block IO protocol on ControllerHandle.\r
187\r
188 @param This Protocol instance pointer.\r
189 @param ControllerHandle Handle of device to stop driver on\r
190 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
191 children is zero stop the entire bus driver.\r
192 @param ChildHandleBuffer List of Child Handles to Stop.\r
193\r
194 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
195 @retval other This driver was not removed from this device\r
196\r
197**/\r
198EFI_STATUS\r
199EFIAPI\r
200DiskIoDriverBindingStop (\r
201 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
202 IN EFI_HANDLE ControllerHandle,\r
203 IN UINTN NumberOfChildren,\r
204 IN EFI_HANDLE *ChildHandleBuffer\r
205 )\r
206{\r
207 EFI_STATUS Status;\r
208 EFI_DISK_IO_PROTOCOL *DiskIo;\r
209 DISK_IO_PRIVATE_DATA *Private;\r
210\r
211 //\r
212 // Get our context back.\r
213 //\r
214 Status = gBS->OpenProtocol (\r
215 ControllerHandle,\r
216 &gEfiDiskIoProtocolGuid,\r
217 (VOID **) &DiskIo,\r
218 This->DriverBindingHandle,\r
219 ControllerHandle,\r
220 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
221 );\r
222 if (EFI_ERROR (Status)) {\r
223 return EFI_UNSUPPORTED;\r
224 }\r
225\r
226 Private = DISK_IO_PRIVATE_DATA_FROM_THIS (DiskIo);\r
227\r
228 Status = gBS->UninstallProtocolInterface (\r
229 ControllerHandle,\r
230 &gEfiDiskIoProtocolGuid,\r
231 &Private->DiskIo\r
232 );\r
233 if (!EFI_ERROR (Status)) {\r
adbcbf8f 234 Status = gBS->CloseProtocol (\r
235 ControllerHandle,\r
236 &gEfiBlockIoProtocolGuid,\r
237 This->DriverBindingHandle,\r
238 ControllerHandle\r
239 );\r
240 }\r
241\r
242 if (!EFI_ERROR (Status)) {\r
243 FreePool (Private);\r
244 }\r
245\r
246 return Status;\r
247}\r
248\r
249\r
250\r
251/**\r
252 Read BufferSize bytes from Offset into Buffer.\r
253 Reads may support reads that are not aligned on\r
254 sector boundaries. There are three cases:\r
255 UnderRun - The first byte is not on a sector boundary or the read request is\r
256 less than a sector in length.\r
257 Aligned - A read of N contiguous sectors.\r
258 OverRun - The last byte is not on a sector boundary.\r
259\r
260 @param This Protocol instance pointer.\r
261 @param MediaId Id of the media, changes every time the media is replaced.\r
262 @param Offset The starting byte offset to read from\r
263 @param BufferSize Size of Buffer\r
264 @param Buffer Buffer containing read data\r
265\r
266 @retval EFI_SUCCESS The data was read correctly from the device.\r
267 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r
268 @retval EFI_NO_MEDIA There is no media in the device.\r
269 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
270 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not\r
271 valid for the device.\r
272\r
273**/\r
274EFI_STATUS\r
275EFIAPI\r
276DiskIoReadDisk (\r
277 IN EFI_DISK_IO_PROTOCOL *This,\r
278 IN UINT32 MediaId,\r
279 IN UINT64 Offset,\r
280 IN UINTN BufferSize,\r
281 OUT VOID *Buffer\r
282 )\r
283{\r
284 EFI_STATUS Status;\r
285 DISK_IO_PRIVATE_DATA *Private;\r
286 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
287 EFI_BLOCK_IO_MEDIA *Media;\r
288 UINT32 BlockSize;\r
289 UINT64 Lba;\r
290 UINT64 OverRunLba;\r
291 UINT32 UnderRun;\r
292 UINT32 OverRun;\r
293 BOOLEAN TransactionComplete;\r
294 UINTN WorkingBufferSize;\r
295 UINT8 *WorkingBuffer;\r
296 UINTN Length;\r
297 UINT8 *Data;\r
298 UINT8 *PreData;\r
299 UINTN IsBufferAligned;\r
300 UINTN DataBufferSize;\r
301 BOOLEAN LastRead;\r
302\r
303 Private = DISK_IO_PRIVATE_DATA_FROM_THIS (This);\r
304\r
305 BlockIo = Private->BlockIo;\r
306 Media = BlockIo->Media;\r
307 BlockSize = Media->BlockSize;\r
308\r
309 if (Media->MediaId != MediaId) {\r
310 return EFI_MEDIA_CHANGED;\r
311 }\r
312\r
313 WorkingBuffer = Buffer;\r
314 WorkingBufferSize = BufferSize;\r
315\r
316 //\r
317 // Allocate a temporary buffer for operation\r
318 //\r
319 DataBufferSize = BlockSize * DATA_BUFFER_BLOCK_NUM;\r
320\r
321 if (Media->IoAlign > 1) {\r
322 PreData = AllocatePool (DataBufferSize + Media->IoAlign);\r
323 Data = PreData - ((UINTN) PreData & (Media->IoAlign - 1)) + Media->IoAlign;\r
324 } else {\r
325 PreData = AllocatePool (DataBufferSize);\r
326 Data = PreData;\r
327 }\r
328\r
329 if (PreData == NULL) {\r
330 return EFI_OUT_OF_RESOURCES;\r
331 }\r
332\r
333 Lba = DivU64x32Remainder (Offset, BlockSize, &UnderRun);\r
334\r
335 Length = BlockSize - UnderRun;\r
336 TransactionComplete = FALSE;\r
337\r
338 Status = EFI_SUCCESS;\r
339 if (UnderRun != 0) {\r
340 //\r
341 // Offset starts in the middle of an Lba, so read the entire block.\r
342 //\r
343 Status = BlockIo->ReadBlocks (\r
344 BlockIo,\r
345 MediaId,\r
346 Lba,\r
347 BlockSize,\r
348 Data\r
349 );\r
350\r
351 if (EFI_ERROR (Status)) {\r
352 goto Done;\r
353 }\r
354\r
355 if (Length > BufferSize) {\r
356 Length = BufferSize;\r
357 TransactionComplete = TRUE;\r
358 }\r
359\r
360 CopyMem (WorkingBuffer, Data + UnderRun, Length);\r
361\r
362 WorkingBuffer += Length;\r
363\r
364 WorkingBufferSize -= Length;\r
365 if (WorkingBufferSize == 0) {\r
366 goto Done;\r
367 }\r
368\r
369 Lba += 1;\r
370 }\r
371\r
372 OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);\r
373\r
374 if (!TransactionComplete && WorkingBufferSize >= BlockSize) {\r
375 //\r
376 // If the DiskIo maps directly to a BlockIo device do the read.\r
377 //\r
378 if (OverRun != 0) {\r
379 WorkingBufferSize -= OverRun;\r
380 }\r
381 //\r
382 // Check buffer alignment\r
383 //\r
384 IsBufferAligned = (UINTN) WorkingBuffer & (UINTN) (Media->IoAlign - 1);\r
385\r
386 if (Media->IoAlign <= 1 || IsBufferAligned == 0) {\r
387 //\r
388 // Alignment is satisfied, so read them together\r
389 //\r
390 Status = BlockIo->ReadBlocks (\r
391 BlockIo,\r
392 MediaId,\r
393 Lba,\r
394 WorkingBufferSize,\r
395 WorkingBuffer\r
396 );\r
397\r
398 if (EFI_ERROR (Status)) {\r
399 goto Done;\r
400 }\r
401\r
402 WorkingBuffer += WorkingBufferSize;\r
403\r
404 } else {\r
405 //\r
406 // Use the allocated buffer instead of the original buffer\r
407 // to avoid alignment issue.\r
408 // Here, the allocated buffer (8-byte align) can satisfy the alignment\r
409 //\r
410 LastRead = FALSE;\r
411 do {\r
412 if (WorkingBufferSize <= DataBufferSize) {\r
413 //\r
414 // It is the last calling to readblocks in this loop\r
415 //\r
416 DataBufferSize = WorkingBufferSize;\r
417 LastRead = TRUE;\r
418 }\r
419\r
420 Status = BlockIo->ReadBlocks (\r
421 BlockIo,\r
422 MediaId,\r
423 Lba,\r
424 DataBufferSize,\r
425 Data\r
426 );\r
427 if (EFI_ERROR (Status)) {\r
428 goto Done;\r
429 }\r
430\r
431 CopyMem (WorkingBuffer, Data, DataBufferSize);\r
432 WorkingBufferSize -= DataBufferSize;\r
433 WorkingBuffer += DataBufferSize;\r
434 Lba += DATA_BUFFER_BLOCK_NUM;\r
435 } while (!LastRead);\r
436 }\r
437 }\r
438\r
439 if (!TransactionComplete && OverRun != 0) {\r
440 //\r
441 // Last read is not a complete block.\r
442 //\r
443 Status = BlockIo->ReadBlocks (\r
444 BlockIo,\r
445 MediaId,\r
446 OverRunLba,\r
447 BlockSize,\r
448 Data\r
449 );\r
450\r
451 if (EFI_ERROR (Status)) {\r
452 goto Done;\r
453 }\r
454\r
455 CopyMem (WorkingBuffer, Data, OverRun);\r
456 }\r
457\r
458Done:\r
459 if (PreData != NULL) {\r
460 FreePool (PreData);\r
461 }\r
462\r
463 return Status;\r
464}\r
465\r
466\r
467/**\r
ff61847d 468 Writes BufferSize bytes from Buffer into Offset.\r
adbcbf8f 469 Writes may require a read modify write to support writes that are not\r
470 aligned on sector boundaries. There are three cases:\r
471 UnderRun - The first byte is not on a sector boundary or the write request\r
472 is less than a sector in length. Read modify write is required.\r
473 Aligned - A write of N contiguous sectors.\r
474 OverRun - The last byte is not on a sector boundary. Read modified write\r
475 required.\r
476\r
477 @param This Protocol instance pointer.\r
478 @param MediaId Id of the media, changes every time the media is replaced.\r
479 @param Offset The starting byte offset to read from\r
480 @param BufferSize Size of Buffer\r
481 @param Buffer Buffer containing read data\r
482\r
483 @retval EFI_SUCCESS The data was written correctly to the device.\r
484 @retval EFI_WRITE_PROTECTED The device can not be written to.\r
485 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
486 @retval EFI_NO_MEDIA There is no media in the device.\r
487 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
488 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not\r
489 valid for the device.\r
490\r
491**/\r
492EFI_STATUS\r
493EFIAPI\r
494DiskIoWriteDisk (\r
495 IN EFI_DISK_IO_PROTOCOL *This,\r
496 IN UINT32 MediaId,\r
497 IN UINT64 Offset,\r
498 IN UINTN BufferSize,\r
499 IN VOID *Buffer\r
500 )\r
501{\r
502 EFI_STATUS Status;\r
503 DISK_IO_PRIVATE_DATA *Private;\r
504 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
505 EFI_BLOCK_IO_MEDIA *Media;\r
506 UINT32 BlockSize;\r
507 UINT64 Lba;\r
508 UINT64 OverRunLba;\r
509 UINT32 UnderRun;\r
510 UINT32 OverRun;\r
511 BOOLEAN TransactionComplete;\r
512 UINTN WorkingBufferSize;\r
513 UINT8 *WorkingBuffer;\r
514 UINTN Length;\r
515 UINT8 *Data;\r
516 UINT8 *PreData;\r
517 UINTN IsBufferAligned;\r
518 UINTN DataBufferSize;\r
519 BOOLEAN LastWrite;\r
520\r
521 Private = DISK_IO_PRIVATE_DATA_FROM_THIS (This);\r
522\r
523 BlockIo = Private->BlockIo;\r
524 Media = BlockIo->Media;\r
525 BlockSize = Media->BlockSize;\r
526\r
527 if (Media->ReadOnly) {\r
528 return EFI_WRITE_PROTECTED;\r
529 }\r
530\r
531 if (Media->MediaId != MediaId) {\r
532 return EFI_MEDIA_CHANGED;\r
533 }\r
534\r
535 DataBufferSize = BlockSize * DATA_BUFFER_BLOCK_NUM;\r
536\r
537 if (Media->IoAlign > 1) {\r
538 PreData = AllocatePool (DataBufferSize + Media->IoAlign);\r
539 Data = PreData - ((UINTN) PreData & (Media->IoAlign - 1)) + Media->IoAlign;\r
540 } else {\r
541 PreData = AllocatePool (DataBufferSize);\r
542 Data = PreData;\r
543 }\r
544\r
545 if (PreData == NULL) {\r
546 return EFI_OUT_OF_RESOURCES;\r
547 }\r
548\r
549 WorkingBuffer = Buffer;\r
550 WorkingBufferSize = BufferSize;\r
551\r
552 Lba = DivU64x32Remainder (Offset, BlockSize, &UnderRun);\r
553\r
554 Length = BlockSize - UnderRun;\r
555 TransactionComplete = FALSE;\r
556\r
557 Status = EFI_SUCCESS;\r
558 if (UnderRun != 0) {\r
559 //\r
560 // Offset starts in the middle of an Lba, so do read modify write.\r
561 //\r
562 Status = BlockIo->ReadBlocks (\r
563 BlockIo,\r
564 MediaId,\r
565 Lba,\r
566 BlockSize,\r
567 Data\r
568 );\r
569\r
570 if (EFI_ERROR (Status)) {\r
571 goto Done;\r
572 }\r
573\r
574 if (Length > BufferSize) {\r
575 Length = BufferSize;\r
576 TransactionComplete = TRUE;\r
577 }\r
578\r
579 CopyMem (Data + UnderRun, WorkingBuffer, Length);\r
580\r
581 Status = BlockIo->WriteBlocks (\r
582 BlockIo,\r
583 MediaId,\r
584 Lba,\r
585 BlockSize,\r
586 Data\r
587 );\r
588 if (EFI_ERROR (Status)) {\r
589 goto Done;\r
590 }\r
591\r
592 WorkingBuffer += Length;\r
593 WorkingBufferSize -= Length;\r
594 if (WorkingBufferSize == 0) {\r
595 goto Done;\r
596 }\r
597\r
598 Lba += 1;\r
599 }\r
600\r
601 OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);\r
602\r
603 if (!TransactionComplete && WorkingBufferSize >= BlockSize) {\r
604 //\r
605 // If the DiskIo maps directly to a BlockIo device do the write.\r
606 //\r
607 if (OverRun != 0) {\r
608 WorkingBufferSize -= OverRun;\r
609 }\r
610 //\r
611 // Check buffer alignment\r
612 //\r
613 IsBufferAligned = (UINTN) WorkingBuffer & (UINTN) (Media->IoAlign - 1);\r
614\r
615 if (Media->IoAlign <= 1 || IsBufferAligned == 0) {\r
616 //\r
617 // Alignment is satisfied, so write them together\r
618 //\r
619 Status = BlockIo->WriteBlocks (\r
620 BlockIo,\r
621 MediaId,\r
622 Lba,\r
623 WorkingBufferSize,\r
624 WorkingBuffer\r
625 );\r
626\r
627 if (EFI_ERROR (Status)) {\r
628 goto Done;\r
629 }\r
630\r
631 WorkingBuffer += WorkingBufferSize;\r
632\r
633 } else {\r
634 //\r
635 // The buffer parameter is not aligned with the request\r
636 // So use the allocated instead.\r
637 // It can fit almost all the cases.\r
638 //\r
639 LastWrite = FALSE;\r
640 do {\r
641 if (WorkingBufferSize <= DataBufferSize) {\r
642 //\r
643 // It is the last calling to writeblocks in this loop\r
644 //\r
645 DataBufferSize = WorkingBufferSize;\r
646 LastWrite = TRUE;\r
647 }\r
648\r
649 CopyMem (Data, WorkingBuffer, DataBufferSize);\r
650 Status = BlockIo->WriteBlocks (\r
651 BlockIo,\r
652 MediaId,\r
653 Lba,\r
654 DataBufferSize,\r
655 Data\r
656 );\r
657 if (EFI_ERROR (Status)) {\r
658 goto Done;\r
659 }\r
660\r
661 WorkingBufferSize -= DataBufferSize;\r
662 WorkingBuffer += DataBufferSize;\r
663 Lba += DATA_BUFFER_BLOCK_NUM;\r
664 } while (!LastWrite);\r
665 }\r
666 }\r
667\r
668 if (!TransactionComplete && OverRun != 0) {\r
669 //\r
670 // Last bit is not a complete block, so do a read modify write.\r
671 //\r
672 Status = BlockIo->ReadBlocks (\r
673 BlockIo,\r
674 MediaId,\r
675 OverRunLba,\r
676 BlockSize,\r
677 Data\r
678 );\r
679\r
680 if (EFI_ERROR (Status)) {\r
681 goto Done;\r
682 }\r
683\r
684 CopyMem (Data, WorkingBuffer, OverRun);\r
685\r
686 Status = BlockIo->WriteBlocks (\r
687 BlockIo,\r
688 MediaId,\r
689 OverRunLba,\r
690 BlockSize,\r
691 Data\r
692 );\r
693 if (EFI_ERROR (Status)) {\r
694 goto Done;\r
695 }\r
696 }\r
697\r
698Done:\r
699 if (PreData != NULL) {\r
700 FreePool (PreData);\r
701 }\r
702\r
703 return Status;\r
704}\r
705\r
706\r
707/**\r
708 The user Entry Point for module DiskIo. The user code starts with this function.\r
709\r
710 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
711 @param[in] SystemTable A pointer to the EFI System Table.\r
712 \r
713 @retval EFI_SUCCESS The entry point is executed successfully.\r
714 @retval other Some error occurs when executing this entry point.\r
715\r
716**/\r
717EFI_STATUS\r
718EFIAPI\r
719InitializeDiskIo (\r
720 IN EFI_HANDLE ImageHandle,\r
721 IN EFI_SYSTEM_TABLE *SystemTable\r
722 )\r
723{\r
724 EFI_STATUS Status;\r
725\r
726 //\r
727 // Install driver model protocol(s).\r
728 //\r
d38a0f44 729 Status = EfiLibInstallDriverBindingComponentName2 (\r
adbcbf8f 730 ImageHandle,\r
731 SystemTable,\r
732 &gDiskIoDriverBinding,\r
733 ImageHandle,\r
734 &gDiskIoComponentName,\r
d38a0f44 735 &gDiskIoComponentName2\r
adbcbf8f 736 );\r
737 ASSERT_EFI_ERROR (Status);\r
738\r
739\r
740 return Status;\r
741}\r
742\r