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 - 2016, 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
;
1327 } EFI_FILE_PROTOCOL_MEM
;
1330 File style interface for Mem (SetPosition).
1332 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1333 @param[out] Position The position to set.
1335 @retval EFI_SUCCESS The position was successfully changed.
1336 @retval EFI_INVALID_PARAMETER The Position was invalid.
1340 FileInterfaceMemSetPosition(
1341 IN EFI_FILE_PROTOCOL
*This
,
1345 if (Position
<= ((EFI_FILE_PROTOCOL_MEM
*)This
)->FileSize
) {
1346 ((EFI_FILE_PROTOCOL_MEM
*)This
)->Position
= Position
;
1347 return (EFI_SUCCESS
);
1349 return (EFI_INVALID_PARAMETER
);
1354 File style interface for Mem (GetPosition).
1356 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1357 @param[out] Position The pointer to the position.
1359 @retval EFI_SUCCESS The position was retrieved.
1363 FileInterfaceMemGetPosition(
1364 IN EFI_FILE_PROTOCOL
*This
,
1365 OUT UINT64
*Position
1368 *Position
= ((EFI_FILE_PROTOCOL_MEM
*)This
)->Position
;
1369 return (EFI_SUCCESS
);
1373 File style interface for Mem (Write).
1375 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1376 @param[in, out] BufferSize Size in bytes of Buffer.
1377 @param[in] Buffer The pointer to the buffer to write.
1379 @retval EFI_OUT_OF_RESOURCES The operation failed due to lack of resources.
1380 @retval EFI_SUCCESS The data was written.
1384 FileInterfaceMemWrite(
1385 IN EFI_FILE_PROTOCOL
*This
,
1386 IN OUT UINTN
*BufferSize
,
1391 EFI_FILE_PROTOCOL_MEM
*MemFile
;
1393 MemFile
= (EFI_FILE_PROTOCOL_MEM
*) This
;
1394 if (MemFile
->Unicode
) {
1398 if ((UINTN
)(MemFile
->Position
+ (*BufferSize
)) > (UINTN
)(MemFile
->BufferSize
)) {
1399 MemFile
->Buffer
= ReallocatePool((UINTN
)(MemFile
->BufferSize
), (UINTN
)(MemFile
->BufferSize
) + (*BufferSize
) + 10, MemFile
->Buffer
);
1400 MemFile
->BufferSize
+= (*BufferSize
) + 10;
1402 CopyMem(((UINT8
*)MemFile
->Buffer
) + MemFile
->Position
, Buffer
, *BufferSize
);
1403 MemFile
->Position
+= (*BufferSize
);
1404 MemFile
->FileSize
= MemFile
->Position
;
1405 return (EFI_SUCCESS
);
1410 AsciiBuffer
= AllocateZeroPool(*BufferSize
);
1411 if (AsciiBuffer
== NULL
) {
1412 return (EFI_OUT_OF_RESOURCES
);
1414 AsciiSPrint(AsciiBuffer
, *BufferSize
, "%S", Buffer
);
1415 if ((UINTN
)(MemFile
->Position
+ AsciiStrSize(AsciiBuffer
)) > (UINTN
)(MemFile
->BufferSize
)) {
1416 MemFile
->Buffer
= ReallocatePool((UINTN
)(MemFile
->BufferSize
), (UINTN
)(MemFile
->BufferSize
) + AsciiStrSize(AsciiBuffer
) + 10, MemFile
->Buffer
);
1417 MemFile
->BufferSize
+= AsciiStrSize(AsciiBuffer
) + 10;
1419 CopyMem(((UINT8
*)MemFile
->Buffer
) + MemFile
->Position
, AsciiBuffer
, AsciiStrSize(AsciiBuffer
));
1420 MemFile
->Position
+= (*BufferSize
/ sizeof(CHAR16
));
1421 MemFile
->FileSize
= MemFile
->Position
;
1422 FreePool(AsciiBuffer
);
1423 return (EFI_SUCCESS
);
1428 File style interface for Mem (Read).
1430 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1431 @param[in, out] BufferSize Size in bytes of Buffer.
1432 @param[in] Buffer The pointer to the buffer to fill.
1434 @retval EFI_SUCCESS The data was read.
1438 FileInterfaceMemRead(
1439 IN EFI_FILE_PROTOCOL
*This
,
1440 IN OUT UINTN
*BufferSize
,
1444 EFI_FILE_PROTOCOL_MEM
*MemFile
;
1446 MemFile
= (EFI_FILE_PROTOCOL_MEM
*) This
;
1447 if (*BufferSize
> (UINTN
)((MemFile
->FileSize
) - (UINTN
)(MemFile
->Position
))) {
1448 (*BufferSize
) = (UINTN
)((MemFile
->FileSize
) - (UINTN
)(MemFile
->Position
));
1450 CopyMem(Buffer
, ((UINT8
*)MemFile
->Buffer
) + MemFile
->Position
, (*BufferSize
));
1451 MemFile
->Position
= MemFile
->Position
+ (*BufferSize
);
1452 return (EFI_SUCCESS
);
1456 File style interface for Mem (Close).
1458 Frees all memory associated with this object.
1460 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1462 @retval EFI_SUCCESS The 'file' was closed.
1466 FileInterfaceMemClose(
1467 IN EFI_FILE_PROTOCOL
*This
1470 SHELL_FREE_NON_NULL(((EFI_FILE_PROTOCOL_MEM
*)This
)->Buffer
);
1471 SHELL_FREE_NON_NULL(This
);
1472 return (EFI_SUCCESS
);
1476 Creates a EFI_FILE_PROTOCOL (almost) object for using to access
1477 a file entirely in memory through file operations.
1479 @param[in] Unicode Boolean value with TRUE for Unicode and FALSE for Ascii.
1481 @retval NULL Memory could not be allocated.
1482 @return other A pointer to an EFI_FILE_PROTOCOL structure.
1486 CreateFileInterfaceMem(
1487 IN CONST BOOLEAN Unicode
1490 EFI_FILE_PROTOCOL_MEM
*FileInterface
;
1495 FileInterface
= AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_MEM
));
1496 if (FileInterface
== NULL
){
1501 // Assign the generic members
1503 FileInterface
->Revision
= EFI_FILE_REVISION
;
1504 FileInterface
->Open
= FileInterfaceOpenNotFound
;
1505 FileInterface
->Close
= FileInterfaceMemClose
;
1506 FileInterface
->GetPosition
= FileInterfaceMemGetPosition
;
1507 FileInterface
->SetPosition
= FileInterfaceMemSetPosition
;
1508 FileInterface
->GetInfo
= FileInterfaceNopGetInfo
;
1509 FileInterface
->SetInfo
= FileInterfaceNopSetInfo
;
1510 FileInterface
->Flush
= FileInterfaceNopGeneric
;
1511 FileInterface
->Delete
= FileInterfaceNopGeneric
;
1512 FileInterface
->Read
= FileInterfaceMemRead
;
1513 FileInterface
->Write
= FileInterfaceMemWrite
;
1514 FileInterface
->Unicode
= Unicode
;
1516 ASSERT(FileInterface
->Buffer
== NULL
);
1517 ASSERT(FileInterface
->BufferSize
== 0);
1518 ASSERT(FileInterface
->Position
== 0);
1521 FileInterface
->Buffer
= AllocateZeroPool(sizeof(gUnicodeFileTag
));
1522 if (FileInterface
->Buffer
== NULL
) {
1523 FreePool (FileInterface
);
1526 *((CHAR16
*) (FileInterface
->Buffer
)) = EFI_UNICODE_BYTE_ORDER_MARK
;
1527 FileInterface
->BufferSize
= 2;
1528 FileInterface
->Position
= 2;
1531 return ((EFI_FILE_PROTOCOL
*)FileInterface
);
1537 EFI_FILE_CLOSE Close
;
1538 EFI_FILE_DELETE Delete
;
1540 EFI_FILE_WRITE Write
;
1541 EFI_FILE_GET_POSITION GetPosition
;
1542 EFI_FILE_SET_POSITION SetPosition
;
1543 EFI_FILE_GET_INFO GetInfo
;
1544 EFI_FILE_SET_INFO SetInfo
;
1545 EFI_FILE_FLUSH Flush
;
1547 EFI_FILE_PROTOCOL
*Orig
;
1548 } EFI_FILE_PROTOCOL_FILE
;
1551 Set a files current position
1553 @param This Protocol instance pointer.
1554 @param Position Byte position from the start of the file.
1556 @retval EFI_SUCCESS Data was written.
1557 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
1562 FileInterfaceFileSetPosition(
1563 IN EFI_FILE_PROTOCOL
*This
,
1567 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->SetPosition(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, Position
);
1571 Get a file's current position
1573 @param This Protocol instance pointer.
1574 @param Position Byte position from the start of the file.
1576 @retval EFI_SUCCESS Data was written.
1577 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
1582 FileInterfaceFileGetPosition(
1583 IN EFI_FILE_PROTOCOL
*This
,
1584 OUT UINT64
*Position
1587 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->GetPosition(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, Position
);
1591 Get information about a file.
1593 @param This Protocol instance pointer.
1594 @param InformationType Type of information to return in Buffer.
1595 @param BufferSize On input size of buffer, on output amount of data in buffer.
1596 @param Buffer The buffer to return data.
1598 @retval EFI_SUCCESS Data was returned.
1599 @retval EFI_UNSUPPORT InformationType is not supported.
1600 @retval EFI_NO_MEDIA The device has no media.
1601 @retval EFI_DEVICE_ERROR The device reported an error.
1602 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1603 @retval EFI_WRITE_PROTECTED The device is write protected.
1604 @retval EFI_ACCESS_DENIED The file was open for read only.
1605 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
1610 FileInterfaceFileGetInfo(
1611 IN EFI_FILE_PROTOCOL
*This
,
1612 IN EFI_GUID
*InformationType
,
1613 IN OUT UINTN
*BufferSize
,
1617 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->GetInfo(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, InformationType
, BufferSize
, Buffer
);
1621 Set information about a file
1623 @param This Protocol instance pointer.
1624 @param InformationType Type of information in Buffer.
1625 @param BufferSize Size of buffer.
1626 @param Buffer The data to write.
1628 @retval EFI_SUCCESS Data was returned.
1629 @retval EFI_UNSUPPORT InformationType is not supported.
1630 @retval EFI_NO_MEDIA The device has no media.
1631 @retval EFI_DEVICE_ERROR The device reported an error.
1632 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1633 @retval EFI_WRITE_PROTECTED The device is write protected.
1634 @retval EFI_ACCESS_DENIED The file was open for read only.
1639 FileInterfaceFileSetInfo(
1640 IN EFI_FILE_PROTOCOL
*This
,
1641 IN EFI_GUID
*InformationType
,
1642 IN UINTN BufferSize
,
1646 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->SetInfo(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, InformationType
, BufferSize
, Buffer
);
1650 Flush data back for the file handle.
1652 @param This Protocol instance pointer.
1654 @retval EFI_SUCCESS Data was written.
1655 @retval EFI_UNSUPPORT Writes to Open directory are not supported.
1656 @retval EFI_NO_MEDIA The device has no media.
1657 @retval EFI_DEVICE_ERROR The device reported an error.
1658 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1659 @retval EFI_WRITE_PROTECTED The device is write protected.
1660 @retval EFI_ACCESS_DENIED The file was open for read only.
1661 @retval EFI_VOLUME_FULL The volume is full.
1666 FileInterfaceFileFlush(
1667 IN EFI_FILE_PROTOCOL
*This
1670 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Flush(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
);
1674 Read data from the file.
1676 @param This Protocol instance pointer.
1677 @param BufferSize On input size of buffer, on output amount of data in buffer.
1678 @param Buffer The buffer in which data is read.
1680 @retval EFI_SUCCESS Data was read.
1681 @retval EFI_NO_MEDIA The device has no media.
1682 @retval EFI_DEVICE_ERROR The device reported an error.
1683 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1684 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
1689 FileInterfaceFileRead(
1690 IN EFI_FILE_PROTOCOL
*This
,
1691 IN OUT UINTN
*BufferSize
,
1695 CHAR8
*AsciiStrBuffer
;
1696 CHAR16
*UscStrBuffer
;
1700 if (((EFI_FILE_PROTOCOL_FILE
*)This
)->Unicode
) {
1704 return (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Read(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, BufferSize
, Buffer
));
1709 Size
= (*BufferSize
) / sizeof(CHAR16
);
1710 AsciiStrBuffer
= AllocateZeroPool(Size
+ sizeof(CHAR8
));
1711 if (AsciiStrBuffer
== NULL
) {
1712 return EFI_OUT_OF_RESOURCES
;
1714 UscStrBuffer
= AllocateZeroPool(*BufferSize
+ sizeof(CHAR16
));
1715 if (UscStrBuffer
== NULL
) {
1716 SHELL_FREE_NON_NULL(AsciiStrBuffer
);
1717 return EFI_OUT_OF_RESOURCES
;
1719 Status
= (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Read(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, &Size
, AsciiStrBuffer
));
1720 if (!EFI_ERROR(Status
)) {
1721 CharNum
= UnicodeSPrint(UscStrBuffer
, *BufferSize
+ sizeof(CHAR16
), L
"%a", AsciiStrBuffer
);
1722 if (CharNum
== Size
) {
1723 CopyMem (Buffer
, UscStrBuffer
, *BufferSize
);
1725 Status
= EFI_UNSUPPORTED
;
1728 SHELL_FREE_NON_NULL(AsciiStrBuffer
);
1729 SHELL_FREE_NON_NULL(UscStrBuffer
);
1735 Opens a new file relative to the source file's location.
1737 @param[in] This The protocol instance pointer.
1738 @param[out] NewHandle Returns File Handle for FileName.
1739 @param[in] FileName Null terminated string. "\", ".", and ".." are supported.
1740 @param[in] OpenMode Open mode for file.
1741 @param[in] Attributes Only used for EFI_FILE_MODE_CREATE.
1743 @retval EFI_SUCCESS The device was opened.
1744 @retval EFI_NOT_FOUND The specified file could not be found on the device.
1745 @retval EFI_NO_MEDIA The device has no media.
1746 @retval EFI_MEDIA_CHANGED The media has changed.
1747 @retval EFI_DEVICE_ERROR The device reported an error.
1748 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
1749 @retval EFI_ACCESS_DENIED The service denied access to the file.
1750 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
1751 @retval EFI_VOLUME_FULL The volume is full.
1755 FileInterfaceFileOpen (
1756 IN EFI_FILE_PROTOCOL
*This
,
1757 OUT EFI_FILE_PROTOCOL
**NewHandle
,
1758 IN CHAR16
*FileName
,
1760 IN UINT64 Attributes
1763 return ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Open(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, NewHandle
, FileName
, OpenMode
, Attributes
);
1767 Close and delete the file handle.
1769 @param This Protocol instance pointer.
1771 @retval EFI_SUCCESS The device was opened.
1772 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
1777 FileInterfaceFileDelete(
1778 IN EFI_FILE_PROTOCOL
*This
1782 Status
= ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Delete(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
);
1788 File style interface for File (Close).
1790 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1792 @retval EFI_SUCCESS The file was closed.
1796 FileInterfaceFileClose(
1797 IN EFI_FILE_PROTOCOL
*This
1801 Status
= ((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Close(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
);
1807 File style interface for File (Write).
1809 If the file was opened with ASCII mode the data will be processed through
1810 AsciiSPrint before writing.
1812 @param[in] This The pointer to the EFI_FILE_PROTOCOL object.
1813 @param[in, out] BufferSize Size in bytes of Buffer.
1814 @param[in] Buffer The pointer to the buffer to write.
1816 @retval EFI_SUCCESS The data was written.
1820 FileInterfaceFileWrite(
1821 IN EFI_FILE_PROTOCOL
*This
,
1822 IN OUT UINTN
*BufferSize
,
1829 if (((EFI_FILE_PROTOCOL_FILE
*)This
)->Unicode
) {
1833 return (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Write(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, BufferSize
, Buffer
));
1838 AsciiBuffer
= AllocateZeroPool(*BufferSize
);
1839 AsciiSPrint(AsciiBuffer
, *BufferSize
, "%S", Buffer
);
1840 Size
= AsciiStrSize(AsciiBuffer
) - 1; // (we dont need the null terminator)
1841 Status
= (((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
->Write(((EFI_FILE_PROTOCOL_FILE
*)This
)->Orig
, &Size
, AsciiBuffer
));
1842 FreePool(AsciiBuffer
);
1848 Create a file interface with unicode information.
1850 This will create a new EFI_FILE_PROTOCOL identical to the Templace
1851 except that the new one has Unicode and Ascii knowledge.
1853 @param[in] Template A pointer to the EFI_FILE_PROTOCOL object.
1854 @param[in] Unicode TRUE for UCS-2, FALSE for ASCII.
1856 @return a new EFI_FILE_PROTOCOL object to be used instead of the template.
1859 CreateFileInterfaceFile(
1860 IN CONST EFI_FILE_PROTOCOL
*Template
,
1861 IN CONST BOOLEAN Unicode
1864 EFI_FILE_PROTOCOL_FILE
*NewOne
;
1866 NewOne
= AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_FILE
));
1867 if (NewOne
== NULL
) {
1870 CopyMem(NewOne
, Template
, sizeof(EFI_FILE_PROTOCOL_FILE
));
1871 NewOne
->Orig
= (EFI_FILE_PROTOCOL
*)Template
;
1872 NewOne
->Unicode
= Unicode
;
1873 NewOne
->Open
= FileInterfaceFileOpen
;
1874 NewOne
->Close
= FileInterfaceFileClose
;
1875 NewOne
->Delete
= FileInterfaceFileDelete
;
1876 NewOne
->Read
= FileInterfaceFileRead
;
1877 NewOne
->Write
= FileInterfaceFileWrite
;
1878 NewOne
->GetPosition
= FileInterfaceFileGetPosition
;
1879 NewOne
->SetPosition
= FileInterfaceFileSetPosition
;
1880 NewOne
->GetInfo
= FileInterfaceFileGetInfo
;
1881 NewOne
->SetInfo
= FileInterfaceFileSetInfo
;
1882 NewOne
->Flush
= FileInterfaceFileFlush
;
1884 return ((EFI_FILE_PROTOCOL
*)NewOne
);