3 Copyright (c) 2004 - 2005, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Produce block IO abstractions for real devices on your PC using Posix APIs.
19 The configuration of what devices to mount or emulate comes from UNIX
20 environment variables. The variables must be visible to the Microsoft*
21 Developer Studio for them to work.
23 <F>ixed - Fixed disk like a hard drive.
24 <R>emovable - Removable media like a floppy or CD-ROM.
25 Read <O>nly - Write protected device.
26 Read <W>rite - Read write device.
27 <block count> - Decimal number of blocks a device supports.
28 <block size> - Decimal number of bytes per block.
30 UNIX envirnonment variable contents. '<' and '>' are not part of the variable,
31 they are just used to make this help more readable. There should be no
32 spaces between the ';'. Extra spaces will break the variable. A '!' is
33 used to seperate multiple devices in a variable.
35 EFI_UNIX_VIRTUAL_DISKS =
36 <F | R><O | W>;<block count>;<block size>[!...]
38 EFI_UNIX_PHYSICAL_DISKS =
39 <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]
41 Virtual Disks: These devices use a file to emulate a hard disk or removable
44 Thus a 20 MB emulated hard drive would look like:
45 EFI_UNIX_VIRTUAL_DISKS=FW;40960;512
47 A 1.44MB emulated floppy with a block size of 1024 would look like:
48 EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024
50 Physical Disks: These devices use UNIX to open a real device in your system
52 Thus a 120 MB floppy would look like:
53 EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512
55 Thus a standard CD-ROM floppy would look like:
56 EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048
59 * Other names and brands may be claimed as the property of others.
65 #include "UnixBlockIo.h"
68 // Block IO protocol member functions
73 UnixBlockIoReadBlocks (
74 IN EFI_BLOCK_IO_PROTOCOL
*This
,
84 TODO: Add function description
88 This - TODO: add argument description
89 MediaId - TODO: add argument description
90 Lba - TODO: add argument description
91 BufferSize - TODO: add argument description
92 Buffer - TODO: add argument description
96 TODO: add return values
104 UnixBlockIoWriteBlocks (
105 IN EFI_BLOCK_IO_PROTOCOL
*This
,
115 TODO: Add function description
119 This - TODO: add argument description
120 MediaId - TODO: add argument description
121 Lba - TODO: add argument description
122 BufferSize - TODO: add argument description
123 Buffer - TODO: add argument description
127 TODO: add return values
135 UnixBlockIoFlushBlocks (
136 IN EFI_BLOCK_IO_PROTOCOL
*This
142 TODO: Add function description
146 This - TODO: add argument description
150 TODO: add return values
158 UnixBlockIoResetBlock (
159 IN EFI_BLOCK_IO_PROTOCOL
*This
,
160 IN BOOLEAN ExtendedVerification
166 TODO: Add function description
170 This - TODO: add argument description
171 ExtendedVerification - TODO: add argument description
175 TODO: add return values
181 // Private Worker functions
185 UnixBlockIoCreateMapping (
186 IN EFI_UNIX_IO_PROTOCOL
*UnixIo
,
187 IN EFI_HANDLE EfiDeviceHandle
,
190 IN BOOLEAN RemovableMedia
,
191 IN UINTN NumberOfBlocks
,
198 TODO: Add function description
202 UnixIo - TODO: add argument description
203 EfiDeviceHandle - TODO: add argument description
204 Filename - TODO: add argument description
205 ReadOnly - TODO: add argument description
206 RemovableMedia - TODO: add argument description
207 NumberOfBlocks - TODO: add argument description
208 BlockSize - TODO: add argument description
209 DeviceType - TODO: add argument description
213 TODO: add return values
220 UnixBlockIoReadWriteCommon (
221 IN UNIX_BLOCK_IO_PRIVATE
*Private
,
232 TODO: Add function description
236 Private - TODO: add argument description
237 MediaId - TODO: add argument description
238 Lba - TODO: add argument description
239 BufferSize - TODO: add argument description
240 Buffer - TODO: add argument description
241 CallerName - TODO: add argument description
245 TODO: add return values
253 IN UNIX_BLOCK_IO_PRIVATE
*Private
259 TODO: Add function description
263 Private - TODO: add argument description
267 TODO: add return values
274 UnixBlockIoOpenDevice (
275 UNIX_BLOCK_IO_PRIVATE
*Private
281 TODO: Add function description
285 Private - TODO: add argument description
289 TODO: add return values
296 GetNextElementPastTerminator (
297 IN CHAR16
*EnvironmentVariable
,
304 TODO: Add function description
308 EnvironmentVariable - TODO: add argument description
309 Terminator - TODO: add argument description
313 TODO: add return values
317 EFI_DRIVER_BINDING_PROTOCOL gUnixBlockIoDriverBinding
= {
318 UnixBlockIoDriverBindingSupported
,
319 UnixBlockIoDriverBindingStart
,
320 UnixBlockIoDriverBindingStop
,
328 UnixBlockIoDriverBindingSupported (
329 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
330 IN EFI_HANDLE Handle
,
331 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
344 // TODO: This - add argument and description to function comment
345 // TODO: Handle - add argument and description to function comment
346 // TODO: RemainingDevicePath - add argument and description to function comment
349 EFI_UNIX_IO_PROTOCOL
*UnixIo
;
352 // Open the IO Abstraction(s) needed to perform the supported test
354 Status
= gBS
->OpenProtocol (
356 &gEfiUnixIoProtocolGuid
,
358 This
->DriverBindingHandle
,
360 EFI_OPEN_PROTOCOL_BY_DRIVER
362 if (EFI_ERROR (Status
)) {
367 // Make sure the UnixThunkProtocol is valid
369 Status
= EFI_UNSUPPORTED
;
370 if (UnixIo
->UnixThunk
->Signature
== EFI_UNIX_THUNK_PROTOCOL_SIGNATURE
) {
373 // Check the GUID to see if this is a handle type the driver supports
375 if (CompareGuid (UnixIo
->TypeGuid
, &gEfiUnixVirtualDisksGuid
) ) {
376 Status
= EFI_SUCCESS
;
381 // Close the I/O Abstraction(s) used to perform the supported test
385 &gEfiUnixIoProtocolGuid
,
386 This
->DriverBindingHandle
,
395 UnixBlockIoDriverBindingStart (
396 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
397 IN EFI_HANDLE Handle
,
398 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
411 // TODO: This - add argument and description to function comment
412 // TODO: Handle - add argument and description to function comment
413 // TODO: RemainingDevicePath - add argument and description to function comment
416 EFI_UNIX_IO_PROTOCOL
*UnixIo
;
417 CHAR16 Buffer
[FILENAME_BUFFER_SIZE
];
419 BOOLEAN RemovableMedia
;
420 BOOLEAN WriteProtected
;
421 UINTN NumberOfBlocks
;
426 // Grab the protocols we need
428 Status
= gBS
->OpenProtocol (
430 &gEfiUnixIoProtocolGuid
,
432 This
->DriverBindingHandle
,
434 EFI_OPEN_PROTOCOL_BY_DRIVER
436 if (EFI_ERROR (Status
)) {
443 if (!CompareGuid (UnixIo
->TypeGuid
, &gEfiUnixVirtualDisksGuid
)) {
444 Status
= EFI_UNSUPPORTED
;
448 Status
= EFI_NOT_FOUND
;
450 Str
= UnixIo
->EnvString
;
452 while (*Str
&& *Str
!= ':')
453 Buffer
[i
++] = *Str
++;
461 RemovableMedia
= FALSE
;
462 WriteProtected
= TRUE
;
466 if (*Str
== 'R' || *Str
== 'F') {
467 RemovableMedia
= (BOOLEAN
) (*Str
== 'R');
470 if (*Str
== 'O' || *Str
== 'W') {
471 WriteProtected
= (BOOLEAN
) (*Str
== 'O');
480 NumberOfBlocks
= Atoi (Str
);
481 Str
= GetNextElementPastTerminator (Str
, ';');
482 if (NumberOfBlocks
== 0)
485 BlockSize
= Atoi (Str
);
487 Str
= GetNextElementPastTerminator (Str
, ';');
491 // If we get here the variable is valid so do the work.
493 Status
= UnixBlockIoCreateMapping (
504 if (EFI_ERROR (Status
)) {
507 &gEfiUnixIoProtocolGuid
,
508 This
->DriverBindingHandle
,
518 UnixBlockIoDriverBindingStop (
519 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
520 IN EFI_HANDLE Handle
,
521 IN UINTN NumberOfChildren
,
522 IN EFI_HANDLE
*ChildHandleBuffer
528 TODO: Add function description
532 This - TODO: add argument description
533 Handle - TODO: add argument description
534 NumberOfChildren - TODO: add argument description
535 ChildHandleBuffer - TODO: add argument description
539 EFI_UNSUPPORTED - TODO: Add description for return value
543 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
545 UNIX_BLOCK_IO_PRIVATE
*Private
;
548 // Get our context back
550 Status
= gBS
->OpenProtocol (
552 &gEfiBlockIoProtocolGuid
,
554 This
->DriverBindingHandle
,
556 EFI_OPEN_PROTOCOL_GET_PROTOCOL
558 if (EFI_ERROR (Status
)) {
559 return EFI_UNSUPPORTED
;
562 Private
= UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo
);
565 // BugBug: If we need to kick people off, we need to make Uninstall Close the handles.
566 // We could pass in our image handle or FLAG our open to be closed via
567 // Unistall (== to saying any CloseProtocol will close our open)
569 Status
= gBS
->UninstallMultipleProtocolInterfaces (
571 &gEfiBlockIoProtocolGuid
,
575 if (!EFI_ERROR (Status
)) {
577 Status
= gBS
->CloseProtocol (
579 &gEfiUnixIoProtocolGuid
,
580 This
->DriverBindingHandle
,
585 // Shut down our device
587 Private
->UnixThunk
->Close (Private
->fd
);
590 // Free our instance data
592 FreeUnicodeStringTable (Private
->ControllerNameTable
);
594 gBS
->FreePool (Private
);
602 GetNextElementPastTerminator (
603 IN CHAR16
*EnvironmentVariable
,
610 Worker function to parse environment variables.
613 EnvironmentVariable - Envirnment variable to parse.
615 Terminator - Terminator to parse for.
619 Pointer to next eliment past the first occurence of Terminator or the '\0'
620 at the end of the string.
626 for (Ptr
= EnvironmentVariable
; *Ptr
!= '\0'; Ptr
++) {
627 if (*Ptr
== Terminator
) {
638 UnixBlockIoCreateMapping (
639 IN EFI_UNIX_IO_PROTOCOL
*UnixIo
,
640 IN EFI_HANDLE EfiDeviceHandle
,
643 IN BOOLEAN RemovableMedia
,
644 IN UINTN NumberOfBlocks
,
651 TODO: Add function description
655 UnixIo - TODO: add argument description
656 EfiDeviceHandle - TODO: add argument description
657 Filename - TODO: add argument description
658 ReadOnly - TODO: add argument description
659 RemovableMedia - TODO: add argument description
660 NumberOfBlocks - TODO: add argument description
661 BlockSize - TODO: add argument description
662 DeviceType - TODO: add argument description
666 TODO: add return values
671 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
672 UNIX_BLOCK_IO_PRIVATE
*Private
;
675 Status
= gBS
->AllocatePool (
677 sizeof (UNIX_BLOCK_IO_PRIVATE
),
680 ASSERT_EFI_ERROR (Status
);
682 EfiInitializeLock (&Private
->Lock
, EFI_TPL_NOTIFY
);
684 Private
->UnixThunk
= UnixIo
->UnixThunk
;
686 Private
->Signature
= UNIX_BLOCK_IO_PRIVATE_SIGNATURE
;
687 Private
->LastBlock
= NumberOfBlocks
- 1;
688 Private
->BlockSize
= BlockSize
;
690 for (Index
= 0; Filename
[Index
] != 0; Index
++) {
691 Private
->Filename
[Index
] = Filename
[Index
];
694 Private
->Filename
[Index
] = 0;
696 Private
->Mode
= (ReadOnly
? O_RDONLY
: O_RDWR
);
698 Private
->NumberOfBlocks
= NumberOfBlocks
;
701 Private
->ControllerNameTable
= NULL
;
705 gUnixBlockIoComponentName
.SupportedLanguages
,
706 &Private
->ControllerNameTable
,
710 BlockIo
= &Private
->BlockIo
;
711 BlockIo
->Revision
= EFI_BLOCK_IO_PROTOCOL_REVISION
;
712 BlockIo
->Media
= &Private
->Media
;
713 BlockIo
->Media
->BlockSize
= Private
->BlockSize
;
714 BlockIo
->Media
->LastBlock
= Private
->NumberOfBlocks
- 1;
715 BlockIo
->Media
->MediaId
= 0;;
717 BlockIo
->Reset
= UnixBlockIoResetBlock
;
718 BlockIo
->ReadBlocks
= UnixBlockIoReadBlocks
;
719 BlockIo
->WriteBlocks
= UnixBlockIoWriteBlocks
;
720 BlockIo
->FlushBlocks
= UnixBlockIoFlushBlocks
;
722 BlockIo
->Media
->ReadOnly
= ReadOnly
;
723 BlockIo
->Media
->RemovableMedia
= RemovableMedia
;
724 BlockIo
->Media
->LogicalPartition
= FALSE
;
725 BlockIo
->Media
->MediaPresent
= TRUE
;
726 BlockIo
->Media
->WriteCaching
= FALSE
;
728 BlockIo
->Media
->IoAlign
= 1;
730 Private
->EfiHandle
= EfiDeviceHandle
;
731 Status
= UnixBlockIoOpenDevice (Private
);
732 if (!EFI_ERROR (Status
)) {
734 Status
= gBS
->InstallMultipleProtocolInterfaces (
736 &gEfiBlockIoProtocolGuid
,
740 if (EFI_ERROR (Status
)) {
741 FreeUnicodeStringTable (Private
->ControllerNameTable
);
742 gBS
->FreePool (Private
);
745 DEBUG ((EFI_D_INIT
, "BlockDevice added: %s\n", Filename
));
753 UnixBlockIoOpenDevice (
754 UNIX_BLOCK_IO_PRIVATE
*Private
760 TODO: Add function description
764 Private - TODO: add argument description
768 TODO: add return values
775 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
777 BlockIo
= &Private
->BlockIo
;
778 EfiAcquireLock (&Private
->Lock
);
781 // If the device is already opened, close it
783 if (Private
->fd
>= 0) {
784 BlockIo
->Reset (BlockIo
, FALSE
);
790 Private
->fd
= Private
->UnixThunk
->Open
791 (Private
->Filename
, Private
->Mode
, 0644);
793 if (Private
->fd
< 0) {
794 DEBUG ((EFI_D_INFO
, "PlOpenBlock: Could not open %s\n",
796 BlockIo
->Media
->MediaPresent
= FALSE
;
797 Status
= EFI_NO_MEDIA
;
801 if (!BlockIo
->Media
->MediaPresent
) {
803 // BugBug: try to emulate if a CD appears - notify drivers to check it out
805 BlockIo
->Media
->MediaPresent
= TRUE
;
806 EfiReleaseLock (&Private
->Lock
);
807 EfiAcquireLock (&Private
->Lock
);
811 // get the size of the file
813 Status
= SetFilePointer64 (Private
, 0, &FileSize
, SEEK_END
);
815 if (EFI_ERROR (Status
)) {
816 FileSize
= MultU64x32 (Private
->NumberOfBlocks
, Private
->BlockSize
);
817 DEBUG ((EFI_D_ERROR
, "PlOpenBlock: Could not get filesize of %s\n", Private
->Filename
));
818 Status
= EFI_UNSUPPORTED
;
822 if (Private
->NumberOfBlocks
== 0) {
823 Private
->NumberOfBlocks
= DivU64x32 (FileSize
, Private
->BlockSize
);
826 EndOfFile
= MultU64x32 (Private
->NumberOfBlocks
, Private
->BlockSize
);
828 if (FileSize
!= EndOfFile
) {
830 // file is not the proper size, change it
832 DEBUG ((EFI_D_INIT
, "PlOpenBlock: Initializing block device: %a\n", Private
->Filename
));
837 Private
->UnixThunk
->FTruncate (Private
->fd
, 0);
840 // then set it to the needed file size (OS will zero fill it)
842 Private
->UnixThunk
->FTruncate (Private
->fd
, EndOfFile
);
845 DEBUG ((EFI_D_INIT
, "%HPlOpenBlock: opened %s%N\n", Private
->Filename
));
846 Status
= EFI_SUCCESS
;
849 if (EFI_ERROR (Status
)) {
850 if (Private
->fd
>= 0) {
851 BlockIo
->Reset (BlockIo
, FALSE
);
855 EfiReleaseLock (&Private
->Lock
);
862 IN UNIX_BLOCK_IO_PRIVATE
*Private
868 TODO: Add function description
872 Private - TODO: add argument description
876 TODO: add return values
880 return EFI_DEVICE_ERROR
;
883 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
885 BOOLEAN ReinstallBlockIoFlag
;
888 BlockIo
= &Private
->BlockIo
;
890 switch (Private
->UnixThunk
->GetLastError ()) {
892 case ERROR_NOT_READY
:
893 Status
= EFI_NO_MEDIA
;
894 BlockIo
->Media
->ReadOnly
= FALSE
;
895 BlockIo
->Media
->MediaPresent
= FALSE
;
896 ReinstallBlockIoFlag
= FALSE
;
899 case ERROR_WRONG_DISK
:
900 BlockIo
->Media
->ReadOnly
= FALSE
;
901 BlockIo
->Media
->MediaPresent
= TRUE
;
902 BlockIo
->Media
->MediaId
+= 1;
903 ReinstallBlockIoFlag
= TRUE
;
904 Status
= EFI_MEDIA_CHANGED
;
907 case ERROR_WRITE_PROTECT
:
908 BlockIo
->Media
->ReadOnly
= TRUE
;
909 ReinstallBlockIoFlag
= FALSE
;
910 Status
= EFI_WRITE_PROTECTED
;
914 ReinstallBlockIoFlag
= FALSE
;
915 Status
= EFI_DEVICE_ERROR
;
919 if (ReinstallBlockIoFlag
) {
920 BlockIo
->Reset (BlockIo
, FALSE
);
922 gBS
->ReinstallProtocolInterface (
924 &gEfiBlockIoProtocolGuid
,
936 UnixBlockIoReadWriteCommon (
937 IN UNIX_BLOCK_IO_PRIVATE
*Private
,
948 TODO: Add function description
952 Private - TODO: add argument description
953 MediaId - TODO: add argument description
954 Lba - TODO: add argument description
955 BufferSize - TODO: add argument description
956 Buffer - TODO: add argument description
957 CallerName - TODO: add argument description
961 EFI_NO_MEDIA - TODO: Add description for return value
962 EFI_MEDIA_CHANGED - TODO: Add description for return value
963 EFI_INVALID_PARAMETER - TODO: Add description for return value
964 EFI_SUCCESS - TODO: Add description for return value
965 EFI_BAD_BUFFER_SIZE - TODO: Add description for return value
966 EFI_INVALID_PARAMETER - TODO: Add description for return value
967 EFI_SUCCESS - TODO: Add description for return value
974 INT64 DistanceToMove
;
975 UINT64 DistanceMoved
;
977 if (Private
->fd
< 0) {
978 Status
= UnixBlockIoOpenDevice (Private
);
979 if (EFI_ERROR (Status
)) {
984 if (!Private
->Media
.MediaPresent
) {
985 DEBUG ((EFI_D_INIT
, "%s: No Media\n", CallerName
));
989 if (Private
->Media
.MediaId
!= MediaId
) {
990 return EFI_MEDIA_CHANGED
;
993 if ((UINT32
) Buffer
% Private
->Media
.IoAlign
!= 0) {
994 return EFI_INVALID_PARAMETER
;
998 // Verify buffer size
1000 BlockSize
= Private
->BlockSize
;
1001 if (BufferSize
== 0) {
1002 DEBUG ((EFI_D_INIT
, "%s: Zero length read\n", CallerName
));
1006 if ((BufferSize
% BlockSize
) != 0) {
1007 DEBUG ((EFI_D_INIT
, "%s: Invalid read size\n", CallerName
));
1008 return EFI_BAD_BUFFER_SIZE
;
1011 LastBlock
= Lba
+ (BufferSize
/ BlockSize
) - 1;
1012 if (LastBlock
> Private
->LastBlock
) {
1013 DEBUG ((EFI_D_INIT
, "ReadBlocks: Attempted to read off end of device\n"));
1014 return EFI_INVALID_PARAMETER
;
1017 // Seek to End of File
1019 DistanceToMove
= MultU64x32 (Lba
, BlockSize
);
1020 Status
= SetFilePointer64 (Private
, DistanceToMove
, &DistanceMoved
, SEEK_SET
);
1022 if (EFI_ERROR (Status
)) {
1023 DEBUG ((EFI_D_INIT
, "WriteBlocks: SetFilePointer failed\n"));
1024 return UnixBlockIoError (Private
);
1033 UnixBlockIoReadBlocks (
1034 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1037 IN UINTN BufferSize
,
1042 Routine Description:
1043 Read BufferSize bytes from Lba into Buffer.
1046 This - Protocol instance pointer.
1047 MediaId - Id of the media, changes every time the media is replaced.
1048 Lba - The starting Logical Block Address to read from
1049 BufferSize - Size of Buffer, must be a multiple of device block size.
1050 Buffer - Buffer containing read data
1053 EFI_SUCCESS - The data was read correctly from the device.
1054 EFI_DEVICE_ERROR - The device reported an error while performing the read.
1055 EFI_NO_MEDIA - There is no media in the device.
1056 EFI_MEDIA_CHANGED - The MediaId does not matched the current device.
1057 EFI_BAD_BUFFER_SIZE - The Buffer was not a multiple of the block size of the
1059 EFI_INVALID_PARAMETER - The read request contains device addresses that are not
1060 valid for the device.
1064 UNIX_BLOCK_IO_PRIVATE
*Private
;
1068 Private
= UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This
);
1070 Status
= UnixBlockIoReadWriteCommon (Private
, MediaId
, Lba
, BufferSize
, Buffer
, "UnixReadBlocks");
1071 if (EFI_ERROR (Status
)) {
1075 len
= Private
->UnixThunk
->Read (Private
->fd
, Buffer
, BufferSize
);
1076 if (len
!= BufferSize
) {
1077 DEBUG ((EFI_D_INIT
, "ReadBlocks: ReadFile failed.\n"));
1078 return UnixBlockIoError (Private
);
1082 // If we wrote then media is present.
1084 This
->Media
->MediaPresent
= TRUE
;
1091 UnixBlockIoWriteBlocks (
1092 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1095 IN UINTN BufferSize
,
1100 Routine Description:
1101 Write BufferSize bytes from Lba into Buffer.
1104 This - Protocol instance pointer.
1105 MediaId - Id of the media, changes every time the media is replaced.
1106 Lba - The starting Logical Block Address to read from
1107 BufferSize - Size of Buffer, must be a multiple of device block size.
1108 Buffer - Buffer containing read data
1111 EFI_SUCCESS - The data was written correctly to the device.
1112 EFI_WRITE_PROTECTED - The device can not be written to.
1113 EFI_DEVICE_ERROR - The device reported an error while performing the write.
1114 EFI_NO_MEDIA - There is no media in the device.
1115 EFI_MEDIA_CHNAGED - The MediaId does not matched the current device.
1116 EFI_BAD_BUFFER_SIZE - The Buffer was not a multiple of the block size of the
1118 EFI_INVALID_PARAMETER - The write request contains a LBA that is not
1119 valid for the device.
1123 UNIX_BLOCK_IO_PRIVATE
*Private
;
1127 Private
= UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This
);
1129 Status
= UnixBlockIoReadWriteCommon (Private
, MediaId
, Lba
, BufferSize
, Buffer
, "UnixWriteBlocks");
1130 if (EFI_ERROR (Status
)) {
1134 len
= Private
->UnixThunk
->Write (Private
->fd
, Buffer
, BufferSize
);
1135 if (len
!= BufferSize
) {
1136 DEBUG ((EFI_D_INIT
, "ReadBlocks: WriteFile failed.\n"));
1137 return UnixBlockIoError (Private
);
1141 // If the write succeeded, we are not write protected and media is present.
1143 This
->Media
->MediaPresent
= TRUE
;
1144 This
->Media
->ReadOnly
= FALSE
;
1151 UnixBlockIoFlushBlocks (
1152 IN EFI_BLOCK_IO_PROTOCOL
*This
1156 Routine Description:
1157 Flush the Block Device.
1160 This - Protocol instance pointer.
1163 EFI_SUCCESS - All outstanding data was written to the device
1164 EFI_DEVICE_ERROR - The device reported an error while writting back the data
1165 EFI_NO_MEDIA - There is no media in the device.
1175 UnixBlockIoResetBlock (
1176 IN EFI_BLOCK_IO_PROTOCOL
*This
,
1177 IN BOOLEAN ExtendedVerification
1181 Routine Description:
1182 Reset the Block Device.
1185 This - Protocol instance pointer.
1186 ExtendedVerification - Driver may perform diagnostics on reset.
1189 EFI_SUCCESS - The device was reset.
1190 EFI_DEVICE_ERROR - The device is not functioning properly and could
1195 UNIX_BLOCK_IO_PRIVATE
*Private
;
1197 Private
= UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This
);
1199 if (Private
->fd
>= 0) {
1200 Private
->UnixThunk
->Close (Private
->fd
);
1213 Routine Description:
1215 Convert a unicode string to a UINTN
1219 String - Unicode string.
1223 UINTN of the number represented by String.
1231 // skip preceeding white space
1234 while ((*Str
) && (*Str
== ' ')) {
1238 // Convert ot a Number
1241 while (*Str
!= '\0') {
1242 if ((*Str
>= '0') && (*Str
<= '9')) {
1243 Number
= (Number
* 10) +*Str
- '0';
1256 IN UNIX_BLOCK_IO_PRIVATE
*Private
,
1257 IN INT64 DistanceToMove
,
1258 OUT UINT64
*NewFilePointer
,
1263 This function extends the capability of SetFilePointer to accept 64 bit parameters
1266 // TODO: function comment is missing 'Routine Description:'
1267 // TODO: function comment is missing 'Arguments:'
1268 // TODO: function comment is missing 'Returns:'
1269 // TODO: Private - add argument and description to function comment
1270 // TODO: DistanceToMove - add argument and description to function comment
1271 // TODO: NewFilePointer - add argument and description to function comment
1272 // TODO: MoveMethod - add argument and description to function comment
1277 res
= Private
->UnixThunk
->Lseek(Private
->fd
, DistanceToMove
, MoveMethod
);
1279 Status
= EFI_INVALID_PARAMETER
;
1282 if (NewFilePointer
!= NULL
) {
1283 *NewFilePointer
= res
;