2 EFI_FILE_PROTOCOL wrappers for other items (Like Environment Variables,
3 StdIn, StdOut, StdErr, etc...).
5 Copyright 2016 Dell Inc.
6 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
7 (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "FileHandleInternal.h"
22 File style interface for console (Open).
24 @param[in] This Ignored.
25 @param[out] NewHandle Ignored.
26 @param[in] FileName Ignored.
27 @param[in] OpenMode Ignored.
28 @param[in] Attributes Ignored.
34 FileInterfaceOpenNotFound(
35 IN EFI_FILE_PROTOCOL
*This
,
36 OUT EFI_FILE_PROTOCOL
**NewHandle
,
42 return (EFI_NOT_FOUND
);
46 File style interface for console (Close, Delete, & Flush)
48 @param[in] This Ignored.
54 FileInterfaceNopGeneric(
55 IN EFI_FILE_PROTOCOL
*This
62 File style interface for console (GetPosition).
64 @param[in] This Ignored.
65 @param[out] Position Ignored.
67 @retval EFI_UNSUPPORTED
71 FileInterfaceNopGetPosition(
72 IN EFI_FILE_PROTOCOL
*This
,
76 return (EFI_UNSUPPORTED
);
80 File style interface for console (SetPosition).
82 @param[in] This Ignored.
83 @param[in] Position Ignored.
85 @retval EFI_UNSUPPORTED
89 FileInterfaceNopSetPosition(
90 IN EFI_FILE_PROTOCOL
*This
,
94 return (EFI_UNSUPPORTED
);
98 File style interface for console (GetInfo).
100 @param[in] This Ignored.
101 @param[in] InformationType Ignored.
102 @param[in, out] BufferSize Ignored.
103 @param[out] Buffer Ignored.
105 @retval EFI_UNSUPPORTED
109 FileInterfaceNopGetInfo(
110 IN EFI_FILE_PROTOCOL
*This
,
111 IN EFI_GUID
*InformationType
,
112 IN OUT UINTN
*BufferSize
,
116 return (EFI_UNSUPPORTED
);
120 File style interface for console (SetInfo).
122 @param[in] This Ignored.
123 @param[in] InformationType Ignored.
124 @param[in] BufferSize Ignored.
125 @param[in] Buffer Ignored.
127 @retval EFI_UNSUPPORTED
131 FileInterfaceNopSetInfo(
132 IN EFI_FILE_PROTOCOL
*This
,
133 IN EFI_GUID
*InformationType
,
138 return (EFI_UNSUPPORTED
);
142 File style interface for StdOut (Write).
144 Writes data to the screen.
146 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
147 @param[in, out] BufferSize Size in bytes of Buffer.
148 @param[in] Buffer The pointer to the buffer to write.
150 @retval EFI_UNSUPPORTED No output console is supported.
151 @return A return value from gST->ConOut->OutputString.
155 FileInterfaceStdOutWrite(
156 IN EFI_FILE_PROTOCOL
*This
,
157 IN OUT UINTN
*BufferSize
,
161 if (ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleOut
) {
162 return (EFI_UNSUPPORTED
);
164 return (gST
->ConOut
->OutputString(gST
->ConOut
, Buffer
));
169 File style interface for StdIn (Write).
171 @param[in] This Ignored.
172 @param[in, out] BufferSize Ignored.
173 @param[in] Buffer Ignored.
175 @retval EFI_UNSUPPORTED
179 FileInterfaceStdInWrite(
180 IN EFI_FILE_PROTOCOL
*This
,
181 IN OUT UINTN
*BufferSize
,
185 return (EFI_UNSUPPORTED
);
189 File style interface for console StdErr (Write).
191 Writes error to the error output.
193 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
194 @param[in, out] BufferSize Size in bytes of Buffer.
195 @param[in] Buffer The pointer to the buffer to write.
197 @return A return value from gST->StdErr->OutputString.
201 FileInterfaceStdErrWrite(
202 IN EFI_FILE_PROTOCOL
*This
,
203 IN OUT UINTN
*BufferSize
,
207 return (gST
->StdErr
->OutputString(gST
->StdErr
, Buffer
));
211 File style interface for console StdOut (Read).
213 @param[in] This Ignored.
214 @param[in, out] BufferSize Ignored.
215 @param[out] Buffer Ignored.
217 @retval EFI_UNSUPPORTED
221 FileInterfaceStdOutRead(
222 IN EFI_FILE_PROTOCOL
*This
,
223 IN OUT UINTN
*BufferSize
,
227 return (EFI_UNSUPPORTED
);
231 File style interface for console StdErr (Read).
233 @param[in] This Ignored.
234 @param[in, out] BufferSize Ignored.
235 @param[out] Buffer Ignored.
237 @retval EFI_UNSUPPORTED Always.
241 FileInterfaceStdErrRead(
242 IN EFI_FILE_PROTOCOL
*This
,
243 IN OUT UINTN
*BufferSize
,
247 return (EFI_UNSUPPORTED
);
251 File style interface for NUL file (Read).
253 @param[in] This Ignored.
254 @param[in, out] BufferSize Poiner to 0 upon return.
255 @param[out] Buffer Ignored.
257 @retval EFI_SUCCESS Always.
261 FileInterfaceNulRead(
262 IN EFI_FILE_PROTOCOL
*This
,
263 IN OUT UINTN
*BufferSize
,
268 return (EFI_SUCCESS
);
272 File style interface for NUL file (Write).
274 @param[in] This Ignored.
275 @param[in, out] BufferSize Ignored.
276 @param[in] Buffer Ignored.
282 FileInterfaceNulWrite(
283 IN EFI_FILE_PROTOCOL
*This
,
284 IN OUT UINTN
*BufferSize
,
288 return (EFI_SUCCESS
);
292 File style interface for console (Read).
294 This will return a single line of input from the console.
296 @param This A pointer to the EFI_FILE_PROTOCOL instance that is the
297 file handle to read data from. Not used.
298 @param BufferSize On input, the size of the Buffer. On output, the amount
299 of data returned in Buffer. In both cases, the size is
301 @param Buffer The buffer into which the data is read.
304 @retval EFI_SUCCESS The data was read.
305 @retval EFI_NO_MEDIA The device has no medium.
306 @retval EFI_DEVICE_ERROR The device reported an error.
307 @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.
308 @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file.
309 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
310 @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory
311 entry. BufferSize has been updated with the size
312 needed to complete the request.
313 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
317 FileInterfaceStdInRead(
318 IN EFI_FILE_PROTOCOL
*This
,
319 IN OUT UINTN
*BufferSize
,
323 CHAR16
*CurrentString
;
325 UINTN Column
; // Column of current cursor
326 UINTN Row
; // Row of current cursor
327 UINTN StartColumn
; // Column at the beginning of the line
328 UINTN Update
; // Line index for update
329 UINTN Delete
; // Num of chars to delete from console after update
330 UINTN StringLen
; // Total length of the line
331 UINTN StringCurPos
; // Line index corresponding to the cursor
332 UINTN MaxStr
; // Maximum possible line length
334 UINTN TotalColumn
; // Num of columns in the console
335 UINTN TotalRow
; // Num of rows in the console
337 UINTN OutputLength
; // Length of the update string
338 UINTN TailRow
; // Row of end of line
339 UINTN TailColumn
; // Column of end of line
342 BUFFER_LIST
*LinePos
;
346 BOOLEAN InTabScrolling
; // Whether in TAB-completion state
347 EFI_SHELL_FILE_INFO
*FoundFileList
;
348 EFI_SHELL_FILE_INFO
*TabLinePos
;
349 EFI_SHELL_FILE_INFO
*TempPos
;
351 CHAR16
*TabOutputStr
;
352 BOOLEAN InQuotationMode
;
354 UINTN TabPos
; // Start index of the string to search for TAB completion.
355 UINTN TabUpdatePos
; // Start index of the string updated by TAB stroke
361 // If buffer is not large enough to hold a CHAR16, return minimum buffer size
363 if (*BufferSize
< sizeof (CHAR16
) * 2) {
364 *BufferSize
= sizeof (CHAR16
) * 2;
365 return (EFI_BUFFER_TOO_SMALL
);
369 CurrentString
= Buffer
;
375 LinePos
= NewPos
= (BUFFER_LIST
*)(&ShellInfoObject
.ViewingSettings
.CommandHistory
);
377 InTabScrolling
= FALSE
;
378 Status
= EFI_SUCCESS
;
380 FoundFileList
= NULL
;
388 TabStr
= AllocateZeroPool (*BufferSize
);
389 if (TabStr
== NULL
) {
390 return EFI_OUT_OF_RESOURCES
;
392 TabOutputStr
= AllocateZeroPool (*BufferSize
);
393 if (TabOutputStr
== NULL
) {
395 return EFI_OUT_OF_RESOURCES
;
399 // Get the screen setting and the current cursor location
401 Column
= StartColumn
= gST
->ConOut
->Mode
->CursorColumn
;
402 Row
= gST
->ConOut
->Mode
->CursorRow
;
403 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &TotalColumn
, &TotalRow
);
406 // Limit the line length to the buffer size or the minimun size of the
407 // screen. (The smaller takes effect)
409 MaxStr
= TotalColumn
* (TotalRow
- 1) - StartColumn
;
410 if (MaxStr
> *BufferSize
/ sizeof (CHAR16
)) {
411 MaxStr
= *BufferSize
/ sizeof (CHAR16
);
413 ZeroMem (CurrentString
, MaxStr
* sizeof (CHAR16
));
418 gBS
->WaitForEvent (1, &gST
->ConIn
->WaitForKey
, &EventIndex
);
419 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
420 if (EFI_ERROR (Status
)) {
425 // Press PageUp or PageDown to scroll the history screen up or down.
426 // Press any other key to quit scrolling.
428 if (Key
.UnicodeChar
== 0 && (Key
.ScanCode
== SCAN_PAGE_UP
|| Key
.ScanCode
== SCAN_PAGE_DOWN
)) {
429 if (Key
.ScanCode
== SCAN_PAGE_UP
) {
430 ConsoleLoggerDisplayHistory(FALSE
, 0, ShellInfoObject
.ConsoleInfo
);
431 } else if (Key
.ScanCode
== SCAN_PAGE_DOWN
) {
432 ConsoleLoggerDisplayHistory(TRUE
, 0, ShellInfoObject
.ConsoleInfo
);
438 ConsoleLoggerStopHistory(ShellInfoObject
.ConsoleInfo
);
444 // If we are quitting TAB scrolling...
446 if (InTabScrolling
&& Key
.UnicodeChar
!= CHAR_TAB
) {
447 if (FoundFileList
!= NULL
) {
448 ShellInfoObject
.NewEfiShellProtocol
->FreeFileList (&FoundFileList
);
449 DEBUG_CODE(FoundFileList
= NULL
;);
451 InTabScrolling
= FALSE
;
454 switch (Key
.UnicodeChar
) {
455 case CHAR_CARRIAGE_RETURN
:
457 // All done, print a newline at the end of the string
459 TailRow
= Row
+ (StringLen
- StringCurPos
+ Column
) / TotalColumn
;
460 TailColumn
= (StringLen
- StringCurPos
+ Column
) % TotalColumn
;
461 ShellPrintEx ((INT32
)TailColumn
, (INT32
)TailRow
, L
"%N\n");
466 if (StringCurPos
!= 0) {
468 // If not move back beyond string beginning, move all characters behind
469 // the current position one character forward
472 Update
= StringCurPos
;
474 CopyMem (CurrentString
+ StringCurPos
, CurrentString
+ StringCurPos
+ 1, sizeof (CHAR16
) * (StringLen
- StringCurPos
));
477 // Adjust the current column and row
479 MoveCursorBackward (TotalColumn
, &Column
, &Row
);
485 // handle auto complete of file and directory names...
487 if (InTabScrolling
) {
488 ASSERT(FoundFileList
!= NULL
);
489 ASSERT(TabLinePos
!= NULL
);
490 TabLinePos
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&(FoundFileList
->Link
), &TabLinePos
->Link
);
491 if (IsNull(&(FoundFileList
->Link
), &TabLinePos
->Link
)) {
492 TabLinePos
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&(FoundFileList
->Link
), &TabLinePos
->Link
);
497 InQuotationMode
= FALSE
;
498 for (Index
= 0; Index
< StringLen
; Index
++) {
499 if (CurrentString
[Index
] == L
'\"') {
500 InQuotationMode
= (BOOLEAN
)(!InQuotationMode
);
502 if (CurrentString
[Index
] == L
' ' && !InQuotationMode
) {
504 TabUpdatePos
= Index
+ 1;
506 if (CurrentString
[Index
] == L
'\\') {
507 TabUpdatePos
= Index
+ 1;
510 if (StrStr(CurrentString
+ TabPos
, L
":") == NULL
) {
511 Cwd
= ShellInfoObject
.NewEfiShellProtocol
->GetCurDir(NULL
);
513 StrnCpyS(TabStr
, (*BufferSize
)/sizeof(CHAR16
), Cwd
, (*BufferSize
)/sizeof(CHAR16
) - 1);
514 StrCatS(TabStr
, (*BufferSize
)/sizeof(CHAR16
), L
"\\");
515 if (TabStr
[StrLen(TabStr
)-1] == L
'\\' && *(CurrentString
+ TabPos
) == L
'\\' ) {
516 TabStr
[StrLen(TabStr
)-1] = CHAR_NULL
;
519 (*BufferSize
)/sizeof(CHAR16
),
520 CurrentString
+ TabPos
,
525 StrnCatS(TabStr
, (*BufferSize
)/sizeof(CHAR16
), CurrentString
+ TabPos
, StringLen
- TabPos
);
528 StrnCpyS(TabStr
, (*BufferSize
)/sizeof(CHAR16
), CurrentString
+ TabPos
, (*BufferSize
)/sizeof(CHAR16
) - 1);
530 StrnCatS(TabStr
, (*BufferSize
)/sizeof(CHAR16
), L
"*", (*BufferSize
)/sizeof(CHAR16
) - 1 - StrLen(TabStr
));
531 FoundFileList
= NULL
;
532 Status
= ShellInfoObject
.NewEfiShellProtocol
->FindFiles(TabStr
, &FoundFileList
);
533 for ( TempStr
= CurrentString
535 ; TempStr
++); // note the ';'... empty for loop
537 // make sure we have a list before we do anything more...
539 if (EFI_ERROR (Status
) || FoundFileList
== NULL
) {
540 InTabScrolling
= FALSE
;
545 // enumerate through the list of files
547 for ( TempPos
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&(FoundFileList
->Link
))
548 ; !IsNull(&FoundFileList
->Link
, &TempPos
->Link
)
549 ; TempPos
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&(FoundFileList
->Link
), &(TempPos
->Link
))
552 // If "cd" is typed, only directory name will be auto-complete filled
553 // in either case . and .. will be removed.
555 if ((((TempStr
[0] == L
'c' || TempStr
[0] == L
'C') &&
556 (TempStr
[1] == L
'd' || TempStr
[1] == L
'D')
557 ) && ((ShellIsDirectory(TempPos
->FullName
) != EFI_SUCCESS
)
558 ||(StrCmp(TempPos
->FileName
, L
".") == 0)
559 ||(StrCmp(TempPos
->FileName
, L
"..") == 0)
560 )) || ((StrCmp(TempPos
->FileName
, L
".") == 0)
561 ||(StrCmp(TempPos
->FileName
, L
"..") == 0))){
562 TabLinePos
= TempPos
;
563 TempPos
= (EFI_SHELL_FILE_INFO
*)(RemoveEntryList(&(TempPos
->Link
))->BackLink
);
564 InternalFreeShellFileInfoNode(TabLinePos
);
567 if (FoundFileList
!= NULL
&& !IsListEmpty(&FoundFileList
->Link
)) {
568 TabLinePos
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&FoundFileList
->Link
);
569 InTabScrolling
= TRUE
;
571 FreePool(FoundFileList
);
572 FoundFileList
= NULL
;
579 if (Key
.UnicodeChar
>= ' ') {
581 // If we are at the buffer's end, drop the key
583 if (StringLen
== MaxStr
- 1 && (ShellInfoObject
.ViewingSettings
.InsertMode
|| StringCurPos
== StringLen
)) {
587 // If in insert mode, make space by moving each other character 1
588 // space higher in the array
590 if (ShellInfoObject
.ViewingSettings
.InsertMode
) {
591 CopyMem(CurrentString
+ StringCurPos
+ 1, CurrentString
+ StringCurPos
, (StringLen
- StringCurPos
)*sizeof(CurrentString
[0]));
594 CurrentString
[StringCurPos
] = Key
.UnicodeChar
;
595 Update
= StringCurPos
;
603 switch (Key
.ScanCode
) {
606 // Move characters behind current position one character forward
608 if (StringLen
!= 0) {
609 Update
= StringCurPos
;
611 CopyMem (CurrentString
+ StringCurPos
, CurrentString
+ StringCurPos
+ 1, sizeof (CHAR16
) * (StringLen
- StringCurPos
));
617 // Prepare to print the previous command
619 NewPos
= (BUFFER_LIST
*)GetPreviousNode(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &LinePos
->Link
);
620 if (IsNull(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &LinePos
->Link
)) {
621 NewPos
= (BUFFER_LIST
*)GetPreviousNode(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &LinePos
->Link
);
627 // Prepare to print the next command
629 NewPos
= (BUFFER_LIST
*)GetNextNode(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &LinePos
->Link
);
630 if (NewPos
== (BUFFER_LIST
*)(&ShellInfoObject
.ViewingSettings
.CommandHistory
)) {
631 NewPos
= (BUFFER_LIST
*)GetNextNode(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &LinePos
->Link
);
637 // Adjust current cursor position
639 if (StringCurPos
!= 0) {
641 MoveCursorBackward (TotalColumn
, &Column
, &Row
);
647 // Adjust current cursor position
649 if (StringCurPos
< StringLen
) {
651 MoveCursorForward (TotalColumn
, TotalRow
, &Column
, &Row
);
657 // Move current cursor position to the beginning of the command line
659 Row
-= (StringCurPos
+ StartColumn
) / TotalColumn
;
660 Column
= StartColumn
;
666 // Move current cursor position to the end of the command line
668 TailRow
= Row
+ (StringLen
- StringCurPos
+ Column
) / TotalColumn
;
669 TailColumn
= (StringLen
- StringCurPos
+ Column
) % TotalColumn
;
672 StringCurPos
= StringLen
;
677 // Prepare to clear the current command line
679 CurrentString
[0] = 0;
682 Row
-= (StringCurPos
+ StartColumn
) / TotalColumn
;
683 Column
= StartColumn
;
689 // Toggle the SEnvInsertMode flag
691 ShellInfoObject
.ViewingSettings
.InsertMode
= (BOOLEAN
)!ShellInfoObject
.ViewingSettings
.InsertMode
;
696 // Print command history
698 PrintCommandHistory (TotalColumn
, TotalRow
, 4);
699 *CurrentString
= CHAR_NULL
;
710 // If we are in auto-complete mode, we are preparing to print
711 // the next file or directory name
713 if (InTabScrolling
) {
715 // Adjust the column and row to the start of TAB-completion string.
717 Column
= (StartColumn
+ TabUpdatePos
) % TotalColumn
;
718 Row
-= (StartColumn
+ StringCurPos
) / TotalColumn
- (StartColumn
+ TabUpdatePos
) / TotalColumn
;
719 OutputLength
= StrLen (TabLinePos
->FileName
);
721 // if the output string contains blank space, quotation marks L'\"'
722 // should be added to the output.
724 if (StrStr(TabLinePos
->FileName
, L
" ") != NULL
){
725 TabOutputStr
[0] = L
'\"';
726 CopyMem (TabOutputStr
+ 1, TabLinePos
->FileName
, OutputLength
* sizeof (CHAR16
));
727 TabOutputStr
[OutputLength
+ 1] = L
'\"';
728 TabOutputStr
[OutputLength
+ 2] = CHAR_NULL
;
730 CopyMem (TabOutputStr
, TabLinePos
->FileName
, OutputLength
* sizeof (CHAR16
));
731 TabOutputStr
[OutputLength
] = CHAR_NULL
;
733 OutputLength
= StrLen (TabOutputStr
) < MaxStr
- 1 ? StrLen (TabOutputStr
) : MaxStr
- 1;
734 CopyMem (CurrentString
+ TabUpdatePos
, TabOutputStr
, OutputLength
* sizeof (CHAR16
));
735 CurrentString
[TabUpdatePos
+ OutputLength
] = CHAR_NULL
;
736 StringCurPos
= TabUpdatePos
+ OutputLength
;
737 Update
= TabUpdatePos
;
738 if (StringLen
> TabUpdatePos
+ OutputLength
) {
739 Delete
= StringLen
- TabUpdatePos
- OutputLength
;
744 // If we have a new position, we are preparing to print a previous or
747 if (NewPos
!= (BUFFER_LIST
*)(&ShellInfoObject
.ViewingSettings
.CommandHistory
)) {
748 Column
= StartColumn
;
749 Row
-= (StringCurPos
+ StartColumn
) / TotalColumn
;
752 NewPos
= (BUFFER_LIST
*)(&ShellInfoObject
.ViewingSettings
.CommandHistory
);
754 OutputLength
= StrLen (LinePos
->Buffer
) < MaxStr
- 1 ? StrLen (LinePos
->Buffer
) : MaxStr
- 1;
755 CopyMem (CurrentString
, LinePos
->Buffer
, OutputLength
* sizeof (CHAR16
));
756 CurrentString
[OutputLength
] = CHAR_NULL
;
758 StringCurPos
= OutputLength
;
761 // Draw new input string
764 if (StringLen
> OutputLength
) {
766 // If old string was longer, blank its tail
768 Delete
= StringLen
- OutputLength
;
772 // If we need to update the output do so now
774 if (Update
!= (UINTN
) -1) {
775 ShellPrintEx ((INT32
)Column
, (INT32
)Row
, L
"%s%.*s", CurrentString
+ Update
, Delete
, L
"");
776 StringLen
= StrLen (CurrentString
);
779 SetMem (CurrentString
+ StringLen
, Delete
* sizeof (CHAR16
), CHAR_NULL
);
782 if (StringCurPos
> StringLen
) {
783 StringCurPos
= StringLen
;
789 // After using print to reflect newly updates, if we're not using
790 // BACKSPACE and DELETE, we need to move the cursor position forward,
791 // so adjust row and column here.
793 if (Key
.UnicodeChar
!= CHAR_BACKSPACE
&& !(Key
.UnicodeChar
== 0 && Key
.ScanCode
== SCAN_DELETE
)) {
795 // Calulate row and column of the tail of current string
797 TailRow
= Row
+ (StringLen
- StringCurPos
+ Column
+ OutputLength
) / TotalColumn
;
798 TailColumn
= (StringLen
- StringCurPos
+ Column
+ OutputLength
) % TotalColumn
;
801 // If the tail of string reaches screen end, screen rolls up, so if
802 // Row does not equal TailRow, Row should be decremented
804 // (if we are recalling commands using UPPER and DOWN key, and if the
805 // old command is too long to fit the screen, TailColumn must be 79.
807 if (TailColumn
== 0 && TailRow
>= TotalRow
&& Row
!= TailRow
) {
811 // Calculate the cursor position after current operation. If cursor
812 // reaches line end, update both row and column, otherwise, only
813 // column will be changed.
815 if (Column
+ OutputLength
>= TotalColumn
) {
816 SkipLength
= OutputLength
- (TotalColumn
- Column
);
818 Row
+= SkipLength
/ TotalColumn
+ 1;
819 if (Row
> TotalRow
- 1) {
823 Column
= SkipLength
% TotalColumn
;
825 Column
+= OutputLength
;
832 // Set the cursor position for this key
834 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Column
, Row
);
837 if (CurrentString
!= NULL
&& StrLen(CurrentString
) > 0) {
839 // add the line to the history buffer
841 AddLineToCommandHistory(CurrentString
);
845 FreePool (TabOutputStr
);
847 // Return the data to the caller
849 *BufferSize
= StringLen
* sizeof (CHAR16
);
852 // if this was used it should be deallocated by now...
853 // prevent memory leaks...
855 ASSERT(FoundFileList
== NULL
);
861 // FILE sytle interfaces for StdIn/StdOut/StdErr
863 EFI_FILE_PROTOCOL FileInterfaceStdIn
= {
865 FileInterfaceOpenNotFound
,
866 FileInterfaceNopGeneric
,
867 FileInterfaceNopGeneric
,
868 FileInterfaceStdInRead
,
869 FileInterfaceStdInWrite
,
870 FileInterfaceNopGetPosition
,
871 FileInterfaceNopSetPosition
,
872 FileInterfaceNopGetInfo
,
873 FileInterfaceNopSetInfo
,
874 FileInterfaceNopGeneric
877 EFI_FILE_PROTOCOL FileInterfaceStdOut
= {
879 FileInterfaceOpenNotFound
,
880 FileInterfaceNopGeneric
,
881 FileInterfaceNopGeneric
,
882 FileInterfaceStdOutRead
,
883 FileInterfaceStdOutWrite
,
884 FileInterfaceNopGetPosition
,
885 FileInterfaceNopSetPosition
,
886 FileInterfaceNopGetInfo
,
887 FileInterfaceNopSetInfo
,
888 FileInterfaceNopGeneric
891 EFI_FILE_PROTOCOL FileInterfaceStdErr
= {
893 FileInterfaceOpenNotFound
,
894 FileInterfaceNopGeneric
,
895 FileInterfaceNopGeneric
,
896 FileInterfaceStdErrRead
,
897 FileInterfaceStdErrWrite
,
898 FileInterfaceNopGetPosition
,
899 FileInterfaceNopSetPosition
,
900 FileInterfaceNopGetInfo
,
901 FileInterfaceNopSetInfo
,
902 FileInterfaceNopGeneric
905 EFI_FILE_PROTOCOL FileInterfaceNulFile
= {
907 FileInterfaceOpenNotFound
,
908 FileInterfaceNopGeneric
,
909 FileInterfaceNopGeneric
,
910 FileInterfaceNulRead
,
911 FileInterfaceNulWrite
,
912 FileInterfaceNopGetPosition
,
913 FileInterfaceNopSetPosition
,
914 FileInterfaceNopGetInfo
,
915 FileInterfaceNopSetInfo
,
916 FileInterfaceNopGeneric
923 // This is identical to EFI_FILE_PROTOCOL except for the additional member
930 EFI_FILE_CLOSE Close
;
931 EFI_FILE_DELETE Delete
;
933 EFI_FILE_WRITE Write
;
934 EFI_FILE_GET_POSITION GetPosition
;
935 EFI_FILE_SET_POSITION SetPosition
;
936 EFI_FILE_GET_INFO GetInfo
;
937 EFI_FILE_SET_INFO SetInfo
;
938 EFI_FILE_FLUSH Flush
;
940 } EFI_FILE_PROTOCOL_ENVIRONMENT
;
941 //ANSI compliance helper to get size of the struct.
942 #define SIZE_OF_EFI_FILE_PROTOCOL_ENVIRONMENT EFI_FIELD_OFFSET (EFI_FILE_PROTOCOL_ENVIRONMENT, Name)
945 File style interface for Environment Variable (Close).
947 Frees the memory for this object.
949 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
955 FileInterfaceEnvClose(
956 IN EFI_FILE_PROTOCOL
*This
964 // Most if not all UEFI commands will have an '\r\n' at the end of any output.
965 // Since the output was redirected to a variable, it does not make sense to
966 // keep this. So, before closing, strip the trailing '\r\n' from the variable
972 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, &NewSize
, NewBuffer
);
973 if (Status
== EFI_BUFFER_TOO_SMALL
) {
974 NewBuffer
= AllocateZeroPool(NewSize
+ sizeof(CHAR16
));
975 if (NewBuffer
== NULL
) {
976 return EFI_OUT_OF_RESOURCES
;
978 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, &NewSize
, NewBuffer
);
981 if (!EFI_ERROR(Status
) && NewBuffer
!= NULL
) {
983 if (StrSize(NewBuffer
) > 6)
985 if ((((CHAR16
*)NewBuffer
)[(StrSize(NewBuffer
)/2) - 2] == CHAR_LINEFEED
)
986 && (((CHAR16
*)NewBuffer
)[(StrSize(NewBuffer
)/2) - 3] == CHAR_CARRIAGE_RETURN
)) {
987 ((CHAR16
*)NewBuffer
)[(StrSize(NewBuffer
)/2) - 3] = CHAR_NULL
;
990 if (IsVolatileEnv(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
)) {
991 Status
= SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, StrSize(NewBuffer
), NewBuffer
);
993 Status
= SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, StrSize(NewBuffer
), NewBuffer
);
998 SHELL_FREE_NON_NULL(NewBuffer
);
999 FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
);
1004 File style interface for Environment Variable (Delete).
1006 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1008 @retval The return value from FileInterfaceEnvClose().
1012 FileInterfaceEnvDelete(
1013 IN EFI_FILE_PROTOCOL
*This
1016 SHELL_DELETE_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
);
1017 return (FileInterfaceEnvClose(This
));
1021 File style interface for Environment Variable (Read).
1023 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1024 @param[in, out] BufferSize Size in bytes of Buffer.
1025 @param[out] Buffer The pointer to the buffer to fill.
1027 @retval EFI_SUCCESS The data was read.
1031 FileInterfaceEnvRead(
1032 IN EFI_FILE_PROTOCOL
*This
,
1033 IN OUT UINTN
*BufferSize
,
1037 return (SHELL_GET_ENVIRONMENT_VARIABLE(
1038 ((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
,
1044 File style interface for Volatile Environment Variable (Write).
1046 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1047 @param[in, out] BufferSize Size in bytes of Buffer.
1048 @param[in] Buffer The pointer to the buffer to write.
1050 @retval EFI_SUCCESS The data was read.
1054 FileInterfaceEnvVolWrite(
1055 IN EFI_FILE_PROTOCOL
*This
,
1056 IN OUT UINTN
*BufferSize
,
1067 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, &NewSize
, NewBuffer
);
1068 if (Status
== EFI_BUFFER_TOO_SMALL
){
1069 NewBuffer
= AllocateZeroPool(NewSize
+ *BufferSize
+ sizeof(CHAR16
));
1070 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, &NewSize
, NewBuffer
);
1072 if (!EFI_ERROR(Status
) && NewBuffer
!= NULL
) {
1073 while (((CHAR16
*)NewBuffer
)[NewSize
/2] == CHAR_NULL
) {
1075 // We want to overwrite the CHAR_NULL
1079 CopyMem((UINT8
*)NewBuffer
+ NewSize
+ 2, Buffer
, *BufferSize
);
1080 Status
= SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, StrSize(NewBuffer
), NewBuffer
);
1081 FreePool(NewBuffer
);
1084 SHELL_FREE_NON_NULL(NewBuffer
);
1085 return (SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, *BufferSize
, Buffer
));
1091 File style interface for Non Volatile Environment Variable (Write).
1093 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1094 @param[in, out] BufferSize Size in bytes of Buffer.
1095 @param[in] Buffer The pointer to the buffer to write.
1097 @retval EFI_SUCCESS The data was read.
1101 FileInterfaceEnvNonVolWrite(
1102 IN EFI_FILE_PROTOCOL
*This
,
1103 IN OUT UINTN
*BufferSize
,
1114 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, &NewSize
, NewBuffer
);
1115 if (Status
== EFI_BUFFER_TOO_SMALL
){
1116 NewBuffer
= AllocateZeroPool(NewSize
+ *BufferSize
);
1117 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
, &NewSize
, NewBuffer
);
1119 if (!EFI_ERROR(Status
)) {
1120 CopyMem((UINT8
*)NewBuffer
+ NewSize
, Buffer
, *BufferSize
);
1121 return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(
1122 ((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
,
1123 NewSize
+ *BufferSize
,
1126 return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(
1127 ((EFI_FILE_PROTOCOL_ENVIRONMENT
*)This
)->Name
,
1134 Creates a EFI_FILE_PROTOCOL (almost) object for using to access
1135 environment variables through file operations.
1137 @param EnvName The name of the Environment Variable to be operated on.
1139 @retval NULL Memory could not be allocated.
1140 @return other a pointer to an EFI_FILE_PROTOCOL structure
1144 CreateFileInterfaceEnv(
1145 IN CONST CHAR16
*EnvName
1148 EFI_FILE_PROTOCOL_ENVIRONMENT
*EnvFileInterface
;
1151 if (EnvName
== NULL
) {
1158 EnvNameSize
= StrSize(EnvName
);
1159 EnvFileInterface
= AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT
)+EnvNameSize
);
1160 if (EnvFileInterface
== NULL
){
1165 // Assign the generic members
1167 EnvFileInterface
->Revision
= EFI_FILE_REVISION
;
1168 EnvFileInterface
->Open
= FileInterfaceOpenNotFound
;
1169 EnvFileInterface
->Close
= FileInterfaceEnvClose
;
1170 EnvFileInterface
->GetPosition
= FileInterfaceNopGetPosition
;
1171 EnvFileInterface
->SetPosition
= FileInterfaceNopSetPosition
;
1172 EnvFileInterface
->GetInfo
= FileInterfaceNopGetInfo
;
1173 EnvFileInterface
->SetInfo
= FileInterfaceNopSetInfo
;
1174 EnvFileInterface
->Flush
= FileInterfaceNopGeneric
;
1175 EnvFileInterface
->Delete
= FileInterfaceEnvDelete
;
1176 EnvFileInterface
->Read
= FileInterfaceEnvRead
;
1178 CopyMem(EnvFileInterface
->Name
, EnvName
, EnvNameSize
);
1181 // Assign the different members for Volatile and Non-Volatile variables
1183 if (IsVolatileEnv(EnvName
)) {
1184 EnvFileInterface
->Write
= FileInterfaceEnvVolWrite
;
1186 EnvFileInterface
->Write
= FileInterfaceEnvNonVolWrite
;
1188 return ((EFI_FILE_PROTOCOL
*)EnvFileInterface
);
1192 Move the cursor position one character backward.
1194 @param[in] LineLength Length of a line. Get it by calling QueryMode
1195 @param[in, out] Column Current column of the cursor position
1196 @param[in, out] Row Current row of the cursor position
1200 MoveCursorBackward (
1201 IN UINTN LineLength
,
1202 IN OUT UINTN
*Column
,
1207 // If current column is 0, move to the last column of the previous line,
1208 // otherwise, just decrement column.
1211 *Column
= LineLength
- 1;
1221 Move the cursor position one character forward.
1223 @param[in] LineLength Length of a line.
1224 @param[in] TotalRow Total row of a screen
1225 @param[in, out] Column Current column of the cursor position
1226 @param[in, out] Row Current row of the cursor position
1231 IN UINTN LineLength
,
1233 IN OUT UINTN
*Column
,
1238 // Increment Column.
1239 // If this puts column past the end of the line, move to first column
1243 if (*Column
>= LineLength
) {
1245 if ((*Row
) < TotalRow
- 1) {
1252 Prints out each previously typed command in the command list history log.
1254 When each screen is full it will pause for a key before continuing.
1256 @param[in] TotalCols How many columns are on the screen
1257 @param[in] TotalRows How many rows are on the screen
1258 @param[in] StartColumn which column to start at
1262 PrintCommandHistory (
1263 IN CONST UINTN TotalCols
,
1264 IN CONST UINTN TotalRows
,
1265 IN CONST UINTN StartColumn
1273 ShellPrintEx (-1, -1, L
"\n");
1277 // go through history list...
1279 for ( Node
= (BUFFER_LIST
*)GetFirstNode(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
)
1280 ; !IsNull(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &Node
->Link
)
1281 ; Node
= (BUFFER_LIST
*)GetNextNode(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &Node
->Link
)
1284 LineCount
= ((StrLen (Node
->Buffer
) + StartColumn
+ 1) / TotalCols
) + 1;
1286 if (LineNumber
+ LineCount
>= TotalRows
) {
1287 ShellPromptForResponseHii(
1288 ShellPromptResponseTypeEnterContinue
,
1289 STRING_TOKEN (STR_SHELL_ENTER_TO_CONT
),
1290 ShellInfoObject
.HiiHandle
,
1295 ShellPrintEx (-1, -1, L
"%2d. %s\n", Index
, Node
->Buffer
);
1296 LineNumber
+= LineCount
;
1306 // This is identical to EFI_FILE_PROTOCOL except for the additional members
1307 // for the buffer, size, and position.
1313 EFI_FILE_CLOSE Close
;
1314 EFI_FILE_DELETE Delete
;
1316 EFI_FILE_WRITE Write
;
1317 EFI_FILE_GET_POSITION GetPosition
;
1318 EFI_FILE_SET_POSITION SetPosition
;
1319 EFI_FILE_GET_INFO GetInfo
;
1320 EFI_FILE_SET_INFO SetInfo
;
1321 EFI_FILE_FLUSH Flush
;
1326 } EFI_FILE_PROTOCOL_MEM
;
1329 File style interface for Mem (SetPosition).
1331 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1332 @param[out] Position The position to set.
1334 @retval EFI_SUCCESS The position was successfully changed.
1335 @retval EFI_INVALID_PARAMETER The Position was invalid.
1339 FileInterfaceMemSetPosition(
1340 IN EFI_FILE_PROTOCOL
*This
,
1344 if (Position
<= ((EFI_FILE_PROTOCOL_MEM
*)This
)->BufferSize
) {
1345 ((EFI_FILE_PROTOCOL_MEM
*)This
)->Position
= Position
;
1346 return (EFI_SUCCESS
);
1348 return (EFI_INVALID_PARAMETER
);
1353 File style interface for Mem (GetPosition).
1355 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1356 @param[out] Position The pointer to the position.
1358 @retval EFI_SUCCESS The position was retrieved.
1362 FileInterfaceMemGetPosition(
1363 IN EFI_FILE_PROTOCOL
*This
,
1364 OUT UINT64
*Position
1367 *Position
= ((EFI_FILE_PROTOCOL_MEM
*)This
)->Position
;
1368 return (EFI_SUCCESS
);
1372 File style interface for Mem (Write).
1374 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1375 @param[in, out] BufferSize Size in bytes of Buffer.
1376 @param[in] Buffer The pointer to the buffer to write.
1378 @retval EFI_OUT_OF_RESOURCES The operation failed due to lack of resources.
1379 @retval EFI_SUCCESS The data was written.
1383 FileInterfaceMemWrite(
1384 IN EFI_FILE_PROTOCOL
*This
,
1385 IN OUT UINTN
*BufferSize
,
1390 EFI_FILE_PROTOCOL_MEM
*MemFile
;
1392 MemFile
= (EFI_FILE_PROTOCOL_MEM
*) This
;
1393 if (MemFile
->Unicode
) {
1397 if ((UINTN
)(MemFile
->Position
+ (*BufferSize
)) > (UINTN
)(MemFile
->BufferSize
)) {
1398 MemFile
->Buffer
= ReallocatePool((UINTN
)(MemFile
->BufferSize
), (UINTN
)(MemFile
->BufferSize
) + (*BufferSize
) + 10, MemFile
->Buffer
);
1399 MemFile
->BufferSize
+= (*BufferSize
) + 10;
1401 CopyMem(((UINT8
*)MemFile
->Buffer
) + MemFile
->Position
, Buffer
, *BufferSize
);
1402 MemFile
->Position
+= (*BufferSize
);
1403 return (EFI_SUCCESS
);
1408 AsciiBuffer
= AllocateZeroPool(*BufferSize
);
1409 if (AsciiBuffer
== NULL
) {
1410 return (EFI_OUT_OF_RESOURCES
);
1412 AsciiSPrint(AsciiBuffer
, *BufferSize
, "%S", Buffer
);
1413 if ((UINTN
)(MemFile
->Position
+ AsciiStrSize(AsciiBuffer
)) > (UINTN
)(MemFile
->BufferSize
)) {
1414 MemFile
->Buffer
= ReallocatePool((UINTN
)(MemFile
->BufferSize
), (UINTN
)(MemFile
->BufferSize
) + AsciiStrSize(AsciiBuffer
) + 10, MemFile
->Buffer
);
1415 MemFile
->BufferSize
+= AsciiStrSize(AsciiBuffer
) + 10;
1417 CopyMem(((UINT8
*)MemFile
->Buffer
) + MemFile
->Position
, AsciiBuffer
, AsciiStrSize(AsciiBuffer
));
1418 MemFile
->Position
+= (*BufferSize
/ sizeof(CHAR16
));
1419 FreePool(AsciiBuffer
);
1420 return (EFI_SUCCESS
);
1425 File style interface for Mem (Read).
1427 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1428 @param[in, out] BufferSize Size in bytes of Buffer.
1429 @param[in] Buffer The pointer to the buffer to fill.
1431 @retval EFI_SUCCESS The data was read.
1435 FileInterfaceMemRead(
1436 IN EFI_FILE_PROTOCOL
*This
,
1437 IN OUT UINTN
*BufferSize
,
1441 EFI_FILE_PROTOCOL_MEM
*MemFile
;
1443 MemFile
= (EFI_FILE_PROTOCOL_MEM
*) This
;
1444 if (*BufferSize
> (UINTN
)((MemFile
->BufferSize
) - (UINTN
)(MemFile
->Position
))) {
1445 (*BufferSize
) = (UINTN
)((MemFile
->BufferSize
) - (UINTN
)(MemFile
->Position
));
1447 CopyMem(Buffer
, ((UINT8
*)MemFile
->Buffer
) + MemFile
->Position
, (*BufferSize
));
1448 MemFile
->Position
= MemFile
->Position
+ (*BufferSize
);
1449 return (EFI_SUCCESS
);
1453 File style interface for Mem (Close).
1455 Frees all memory associated with this object.
1457 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1459 @retval EFI_SUCCESS The 'file' was closed.
1463 FileInterfaceMemClose(
1464 IN EFI_FILE_PROTOCOL
*This
1467 SHELL_FREE_NON_NULL(((EFI_FILE_PROTOCOL_MEM
*)This
)->Buffer
);
1468 SHELL_FREE_NON_NULL(This
);
1469 return (EFI_SUCCESS
);
1473 Creates a EFI_FILE_PROTOCOL (almost) object for using to access
1474 a file entirely in memory through file operations.
1476 @param[in] Unicode Boolean value with TRUE for Unicode and FALSE for Ascii.
1478 @retval NULL Memory could not be allocated.
1479 @return other A pointer to an EFI_FILE_PROTOCOL structure.
1483 CreateFileInterfaceMem(
1484 IN CONST BOOLEAN Unicode
1487 EFI_FILE_PROTOCOL_MEM
*FileInterface
;
1492 FileInterface
= AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_MEM
));
1493 if (FileInterface
== NULL
){
1498 // Assign the generic members
1500 FileInterface
->Revision
= EFI_FILE_REVISION
;
1501 FileInterface
->Open
= FileInterfaceOpenNotFound
;
1502 FileInterface
->Close
= FileInterfaceMemClose
;
1503 FileInterface
->GetPosition
= FileInterfaceMemGetPosition
;
1504 FileInterface
->SetPosition
= FileInterfaceMemSetPosition
;
1505 FileInterface
->GetInfo
= FileInterfaceNopGetInfo
;
1506 FileInterface
->SetInfo
= FileInterfaceNopSetInfo
;
1507 FileInterface
->Flush
= FileInterfaceNopGeneric
;
1508 FileInterface
->Delete
= FileInterfaceNopGeneric
;
1509 FileInterface
->Read
= FileInterfaceMemRead
;
1510 FileInterface
->Write
= FileInterfaceMemWrite
;
1511 FileInterface
->Unicode
= Unicode
;
1513 ASSERT(FileInterface
->Buffer
== NULL
);
1514 ASSERT(FileInterface
->BufferSize
== 0);
1515 ASSERT(FileInterface
->Position
== 0);
1518 FileInterface
->Buffer
= AllocateZeroPool(sizeof(gUnicodeFileTag
));
1519 *((CHAR16
*) (FileInterface
->Buffer
)) = EFI_UNICODE_BYTE_ORDER_MARK
;
1520 FileInterface
->BufferSize
= 2;
1521 FileInterface
->Position
= 2;
1524 return ((EFI_FILE_PROTOCOL
*)FileInterface
);
1530 EFI_FILE_CLOSE Close
;
1531 EFI_FILE_DELETE Delete
;
1533 EFI_FILE_WRITE Write
;
1534 EFI_FILE_GET_POSITION GetPosition
;
1535 EFI_FILE_SET_POSITION SetPosition
;
1536 EFI_FILE_GET_INFO GetInfo
;
1537 EFI_FILE_SET_INFO SetInfo
;
1538 EFI_FILE_FLUSH Flush
;
1540 EFI_FILE_PROTOCOL
*Orig
;
1541 } EFI_FILE_PROTOCOL_FILE
;
1544 Set a files current position
1546 @param This Protocol instance pointer.
1547 @param Position Byte position from the start of the file.
1549 @retval EFI_SUCCESS Data was written.
1550 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
1555 FileInterfaceFileSetPosition(
1556 IN EFI_FILE_PROTOCOL
*This
,
1560 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->SetPosition(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, Position
);
1564 Get a file's current position
1566 @param This Protocol instance pointer.
1567 @param Position Byte position from the start of the file.
1569 @retval EFI_SUCCESS Data was written.
1570 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
1575 FileInterfaceFileGetPosition(
1576 IN EFI_FILE_PROTOCOL
*This
,
1577 OUT UINT64
*Position
1580 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->GetPosition(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, Position
);
1584 Get information about a file.
1586 @param This Protocol instance pointer.
1587 @param InformationType Type of information to return in Buffer.
1588 @param BufferSize On input size of buffer, on output amount of data in buffer.
1589 @param Buffer The buffer to return data.
1591 @retval EFI_SUCCESS Data was returned.
1592 @retval EFI_UNSUPPORT InformationType is not supported.
1593 @retval EFI_NO_MEDIA The device has no media.
1594 @retval EFI_DEVICE_ERROR The device reported an error.
1595 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1596 @retval EFI_WRITE_PROTECTED The device is write protected.
1597 @retval EFI_ACCESS_DENIED The file was open for read only.
1598 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
1603 FileInterfaceFileGetInfo(
1604 IN EFI_FILE_PROTOCOL
*This
,
1605 IN EFI_GUID
*InformationType
,
1606 IN OUT UINTN
*BufferSize
,
1610 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->GetInfo(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, InformationType
, BufferSize
, Buffer
);
1614 Set information about a file
1616 @param This Protocol instance pointer.
1617 @param InformationType Type of information in Buffer.
1618 @param BufferSize Size of buffer.
1619 @param Buffer The data to write.
1621 @retval EFI_SUCCESS Data was returned.
1622 @retval EFI_UNSUPPORT InformationType is not supported.
1623 @retval EFI_NO_MEDIA The device has no media.
1624 @retval EFI_DEVICE_ERROR The device reported an error.
1625 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1626 @retval EFI_WRITE_PROTECTED The device is write protected.
1627 @retval EFI_ACCESS_DENIED The file was open for read only.
1632 FileInterfaceFileSetInfo(
1633 IN EFI_FILE_PROTOCOL
*This
,
1634 IN EFI_GUID
*InformationType
,
1635 IN UINTN BufferSize
,
1639 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->SetInfo(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, InformationType
, BufferSize
, Buffer
);
1643 Flush data back for the file handle.
1645 @param This Protocol instance pointer.
1647 @retval EFI_SUCCESS Data was written.
1648 @retval EFI_UNSUPPORT Writes to Open directory are not supported.
1649 @retval EFI_NO_MEDIA The device has no media.
1650 @retval EFI_DEVICE_ERROR The device reported an error.
1651 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1652 @retval EFI_WRITE_PROTECTED The device is write protected.
1653 @retval EFI_ACCESS_DENIED The file was open for read only.
1654 @retval EFI_VOLUME_FULL The volume is full.
1659 FileInterfaceFileFlush(
1660 IN EFI_FILE_PROTOCOL
*This
1663 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Flush(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
);
1667 Read data from the file.
1669 @param This Protocol instance pointer.
1670 @param BufferSize On input size of buffer, on output amount of data in buffer.
1671 @param Buffer The buffer in which data is read.
1673 @retval EFI_SUCCESS Data was read.
1674 @retval EFI_NO_MEDIA The device has no media.
1675 @retval EFI_DEVICE_ERROR The device reported an error.
1676 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1677 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
1682 FileInterfaceFileRead(
1683 IN EFI_FILE_PROTOCOL
*This
,
1684 IN OUT UINTN
*BufferSize
,
1688 CHAR8
*AsciiStrBuffer
;
1689 CHAR16
*UscStrBuffer
;
1693 if (((EFI_FILE_PROTOCOL_FILE
*)This
)->Unicode
) {
1697 return (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Read(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, BufferSize
, Buffer
));
1702 Size
= (*BufferSize
) / sizeof(CHAR16
);
1703 AsciiStrBuffer
= AllocateZeroPool(Size
+ sizeof(CHAR8
));
1704 if (AsciiStrBuffer
== NULL
) {
1705 return EFI_OUT_OF_RESOURCES
;
1707 UscStrBuffer
= AllocateZeroPool(*BufferSize
+ sizeof(CHAR16
));
1708 if (UscStrBuffer
== NULL
) {
1709 SHELL_FREE_NON_NULL(AsciiStrBuffer
);
1710 return EFI_OUT_OF_RESOURCES
;
1712 Status
= (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Read(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, &Size
, AsciiStrBuffer
));
1713 if (!EFI_ERROR(Status
)) {
1714 CharNum
= UnicodeSPrint(UscStrBuffer
, *BufferSize
+ sizeof(CHAR16
), L
"%a", AsciiStrBuffer
);
1715 if (CharNum
== Size
) {
1716 CopyMem (Buffer
, UscStrBuffer
, *BufferSize
);
1718 Status
= EFI_UNSUPPORTED
;
1721 SHELL_FREE_NON_NULL(AsciiStrBuffer
);
1722 SHELL_FREE_NON_NULL(UscStrBuffer
);
1728 Opens a new file relative to the source file's location.
1730 @param[in] This The protocol instance pointer.
1731 @param[out] NewHandle Returns File Handle for FileName.
1732 @param[in] FileName Null terminated string. "\", ".", and ".." are supported.
1733 @param[in] OpenMode Open mode for file.
1734 @param[in] Attributes Only used for EFI_FILE_MODE_CREATE.
1736 @retval EFI_SUCCESS The device was opened.
1737 @retval EFI_NOT_FOUND The specified file could not be found on the device.
1738 @retval EFI_NO_MEDIA The device has no media.
1739 @retval EFI_MEDIA_CHANGED The media has changed.
1740 @retval EFI_DEVICE_ERROR The device reported an error.
1741 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1742 @retval EFI_ACCESS_DENIED The service denied access to the file.
1743 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
1744 @retval EFI_VOLUME_FULL The volume is full.
1748 FileInterfaceFileOpen (
1749 IN EFI_FILE_PROTOCOL
*This
,
1750 OUT EFI_FILE_PROTOCOL
**NewHandle
,
1751 IN CHAR16
*FileName
,
1753 IN UINT64 Attributes
1756 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Open(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, NewHandle
, FileName
, OpenMode
, Attributes
);
1760 Close and delete the file handle.
1762 @param This Protocol instance pointer.
1764 @retval EFI_SUCCESS The device was opened.
1765 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
1770 FileInterfaceFileDelete(
1771 IN EFI_FILE_PROTOCOL
*This
1775 Status
= ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Delete(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
);
1781 File style interface for File (Close).
1783 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1785 @retval EFI_SUCCESS The file was closed.
1789 FileInterfaceFileClose(
1790 IN EFI_FILE_PROTOCOL
*This
1794 Status
= ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Close(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
);
1800 File style interface for File (Write).
1802 If the file was opened with ASCII mode the data will be processed through
1803 AsciiSPrint before writing.
1805 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1806 @param[in, out] BufferSize Size in bytes of Buffer.
1807 @param[in] Buffer The pointer to the buffer to write.
1809 @retval EFI_SUCCESS The data was written.
1813 FileInterfaceFileWrite(
1814 IN EFI_FILE_PROTOCOL
*This
,
1815 IN OUT UINTN
*BufferSize
,
1822 if (((EFI_FILE_PROTOCOL_FILE
*)This
)->Unicode
) {
1826 return (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Write(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, BufferSize
, Buffer
));
1831 AsciiBuffer
= AllocateZeroPool(*BufferSize
);
1832 AsciiSPrint(AsciiBuffer
, *BufferSize
, "%S", Buffer
);
1833 Size
= AsciiStrSize(AsciiBuffer
) - 1; // (we dont need the null terminator)
1834 Status
= (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Write(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, &Size
, AsciiBuffer
));
1835 FreePool(AsciiBuffer
);
1841 Create a file interface with unicode information.
1843 This will create a new EFI_FILE_PROTOCOL identical to the Templace
1844 except that the new one has Unicode and Ascii knowledge.
1846 @param[in] Template A pointer to the EFI_FILE_PROTOCOL object.
1847 @param[in] Unicode TRUE for UCS-2, FALSE for ASCII.
1849 @return a new EFI_FILE_PROTOCOL object to be used instead of the template.
1852 CreateFileInterfaceFile(
1853 IN CONST EFI_FILE_PROTOCOL
*Template
,
1854 IN CONST BOOLEAN Unicode
1857 EFI_FILE_PROTOCOL_FILE
*NewOne
;
1859 NewOne
= AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_FILE
));
1860 if (NewOne
== NULL
) {
1863 CopyMem(NewOne
, Template
, sizeof(EFI_FILE_PROTOCOL_FILE
));
1864 NewOne
->Orig
= (EFI_FILE_PROTOCOL
*)Template
;
1865 NewOne
->Unicode
= Unicode
;
1866 NewOne
->Open
= FileInterfaceFileOpen
;
1867 NewOne
->Close
= FileInterfaceFileClose
;
1868 NewOne
->Delete
= FileInterfaceFileDelete
;
1869 NewOne
->Read
= FileInterfaceFileRead
;
1870 NewOne
->Write
= FileInterfaceFileWrite
;
1871 NewOne
->GetPosition
= FileInterfaceFileGetPosition
;
1872 NewOne
->SetPosition
= FileInterfaceFileSetPosition
;
1873 NewOne
->GetInfo
= FileInterfaceFileGetInfo
;
1874 NewOne
->SetInfo
= FileInterfaceFileSetInfo
;
1875 NewOne
->Flush
= FileInterfaceFileFlush
;
1877 return ((EFI_FILE_PROTOCOL
*)NewOne
);