]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | EFI_FILE_PROTOCOL wrappers for other items (Like Environment Variables,\r | |
3 | StdIn, StdOut, StdErr, etc...).\r | |
4 | \r | |
9ed21946 | 5 | Copyright 2016 Dell Inc.\r |
9eec4d38 | 6 | Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r |
c011b6c9 | 7 | (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r |
a405b86d | 8 | This program and the accompanying materials\r |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include "Shell.h"\r | |
19 | #include "FileHandleInternal.h"\r | |
20 | \r | |
c8d9d0e2 JD |
21 | #define MEM_WRITE_REALLOC_OVERHEAD 1024\r |
22 | \r | |
a405b86d | 23 | /**\r |
24 | File style interface for console (Open). \r | |
25 | \r | |
26 | @param[in] This Ignored.\r | |
27 | @param[out] NewHandle Ignored.\r | |
28 | @param[in] FileName Ignored.\r | |
29 | @param[in] OpenMode Ignored.\r | |
30 | @param[in] Attributes Ignored.\r | |
31 | \r | |
32 | @retval EFI_NOT_FOUND\r | |
33 | **/\r | |
34 | EFI_STATUS\r | |
35 | EFIAPI\r | |
36 | FileInterfaceOpenNotFound(\r | |
37 | IN EFI_FILE_PROTOCOL *This,\r | |
38 | OUT EFI_FILE_PROTOCOL **NewHandle,\r | |
39 | IN CHAR16 *FileName,\r | |
40 | IN UINT64 OpenMode,\r | |
41 | IN UINT64 Attributes\r | |
42 | )\r | |
43 | {\r | |
44 | return (EFI_NOT_FOUND);\r | |
45 | }\r | |
46 | \r | |
47 | /**\r | |
48 | File style interface for console (Close, Delete, & Flush)\r | |
49 | \r | |
50 | @param[in] This Ignored.\r | |
51 | \r | |
52 | @retval EFI_SUCCESS\r | |
53 | **/\r | |
54 | EFI_STATUS\r | |
55 | EFIAPI\r | |
56 | FileInterfaceNopGeneric(\r | |
57 | IN EFI_FILE_PROTOCOL *This\r | |
58 | )\r | |
59 | {\r | |
60 | return (EFI_SUCCESS);\r | |
61 | }\r | |
62 | \r | |
63 | /**\r | |
64 | File style interface for console (GetPosition).\r | |
65 | \r | |
66 | @param[in] This Ignored.\r | |
67 | @param[out] Position Ignored.\r | |
68 | \r | |
69 | @retval EFI_UNSUPPORTED\r | |
70 | **/\r | |
71 | EFI_STATUS\r | |
72 | EFIAPI\r | |
73 | FileInterfaceNopGetPosition(\r | |
74 | IN EFI_FILE_PROTOCOL *This,\r | |
75 | OUT UINT64 *Position\r | |
76 | )\r | |
77 | {\r | |
78 | return (EFI_UNSUPPORTED);\r | |
79 | }\r | |
80 | \r | |
81 | /**\r | |
82 | File style interface for console (SetPosition).\r | |
83 | \r | |
84 | @param[in] This Ignored.\r | |
85 | @param[in] Position Ignored.\r | |
86 | \r | |
87 | @retval EFI_UNSUPPORTED\r | |
88 | **/\r | |
89 | EFI_STATUS\r | |
90 | EFIAPI\r | |
91 | FileInterfaceNopSetPosition(\r | |
92 | IN EFI_FILE_PROTOCOL *This,\r | |
93 | IN UINT64 Position\r | |
94 | )\r | |
95 | {\r | |
96 | return (EFI_UNSUPPORTED);\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
100 | File style interface for console (GetInfo).\r | |
101 | \r | |
4ff7e37b ED |
102 | @param[in] This Ignored.\r |
103 | @param[in] InformationType Ignored.\r | |
104 | @param[in, out] BufferSize Ignored.\r | |
105 | @param[out] Buffer Ignored.\r | |
a405b86d | 106 | \r |
107 | @retval EFI_UNSUPPORTED\r | |
108 | **/\r | |
109 | EFI_STATUS\r | |
110 | EFIAPI\r | |
111 | FileInterfaceNopGetInfo(\r | |
112 | IN EFI_FILE_PROTOCOL *This,\r | |
113 | IN EFI_GUID *InformationType,\r | |
114 | IN OUT UINTN *BufferSize,\r | |
115 | OUT VOID *Buffer\r | |
116 | )\r | |
117 | {\r | |
118 | return (EFI_UNSUPPORTED);\r | |
119 | }\r | |
120 | \r | |
121 | /**\r | |
122 | File style interface for console (SetInfo).\r | |
123 | \r | |
124 | @param[in] This Ignored.\r | |
125 | @param[in] InformationType Ignored.\r | |
126 | @param[in] BufferSize Ignored.\r | |
127 | @param[in] Buffer Ignored.\r | |
128 | \r | |
129 | @retval EFI_UNSUPPORTED\r | |
130 | **/\r | |
131 | EFI_STATUS\r | |
132 | EFIAPI\r | |
133 | FileInterfaceNopSetInfo(\r | |
134 | IN EFI_FILE_PROTOCOL *This,\r | |
135 | IN EFI_GUID *InformationType,\r | |
136 | IN UINTN BufferSize,\r | |
137 | IN VOID *Buffer\r | |
138 | )\r | |
139 | {\r | |
140 | return (EFI_UNSUPPORTED);\r | |
141 | }\r | |
142 | \r | |
143 | /**\r | |
144 | File style interface for StdOut (Write).\r | |
145 | \r | |
146 | Writes data to the screen.\r | |
147 | \r | |
4ff7e37b ED |
148 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
149 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
150 | @param[in] Buffer The pointer to the buffer to write.\r | |
a405b86d | 151 | \r |
152 | @retval EFI_UNSUPPORTED No output console is supported.\r | |
153 | @return A return value from gST->ConOut->OutputString.\r | |
154 | **/\r | |
155 | EFI_STATUS\r | |
156 | EFIAPI\r | |
157 | FileInterfaceStdOutWrite(\r | |
158 | IN EFI_FILE_PROTOCOL *This,\r | |
159 | IN OUT UINTN *BufferSize,\r | |
160 | IN VOID *Buffer\r | |
161 | )\r | |
162 | {\r | |
163 | if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {\r | |
164 | return (EFI_UNSUPPORTED);\r | |
a405b86d | 165 | }\r |
d73fc181 JD |
166 | if (*((CHAR16 *)Buffer) == gUnicodeFileTag) {\r |
167 | return (gST->ConOut->OutputString(gST->ConOut, (CHAR16 *)Buffer + 1));\r | |
168 | }\r | |
169 | return (gST->ConOut->OutputString(gST->ConOut, Buffer));\r | |
a405b86d | 170 | }\r |
171 | \r | |
172 | /**\r | |
173 | File style interface for StdIn (Write).\r | |
174 | \r | |
4ff7e37b ED |
175 | @param[in] This Ignored.\r |
176 | @param[in, out] BufferSize Ignored.\r | |
177 | @param[in] Buffer Ignored.\r | |
a405b86d | 178 | \r |
179 | @retval EFI_UNSUPPORTED\r | |
180 | **/\r | |
181 | EFI_STATUS\r | |
182 | EFIAPI\r | |
183 | FileInterfaceStdInWrite(\r | |
733f138d | 184 | IN EFI_FILE_PROTOCOL *This,\r |
185 | IN OUT UINTN *BufferSize,\r | |
186 | IN VOID *Buffer\r | |
a405b86d | 187 | )\r |
188 | {\r | |
189 | return (EFI_UNSUPPORTED);\r | |
190 | }\r | |
191 | \r | |
192 | /**\r | |
193 | File style interface for console StdErr (Write).\r | |
194 | \r | |
195 | Writes error to the error output.\r | |
196 | \r | |
4ff7e37b ED |
197 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
198 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
199 | @param[in] Buffer The pointer to the buffer to write.\r | |
a405b86d | 200 | \r |
201 | @return A return value from gST->StdErr->OutputString.\r | |
202 | **/\r | |
203 | EFI_STATUS\r | |
204 | EFIAPI\r | |
205 | FileInterfaceStdErrWrite(\r | |
206 | IN EFI_FILE_PROTOCOL *This,\r | |
207 | IN OUT UINTN *BufferSize,\r | |
208 | IN VOID *Buffer\r | |
209 | )\r | |
210 | {\r | |
211 | return (gST->StdErr->OutputString(gST->StdErr, Buffer));\r | |
212 | }\r | |
213 | \r | |
214 | /**\r | |
215 | File style interface for console StdOut (Read).\r | |
216 | \r | |
4ff7e37b ED |
217 | @param[in] This Ignored.\r |
218 | @param[in, out] BufferSize Ignored.\r | |
219 | @param[out] Buffer Ignored.\r | |
a405b86d | 220 | \r |
221 | @retval EFI_UNSUPPORTED\r | |
222 | **/\r | |
223 | EFI_STATUS\r | |
224 | EFIAPI\r | |
225 | FileInterfaceStdOutRead(\r | |
226 | IN EFI_FILE_PROTOCOL *This,\r | |
227 | IN OUT UINTN *BufferSize,\r | |
228 | OUT VOID *Buffer\r | |
229 | )\r | |
230 | {\r | |
231 | return (EFI_UNSUPPORTED);\r | |
232 | }\r | |
233 | \r | |
234 | /**\r | |
235 | File style interface for console StdErr (Read).\r | |
236 | \r | |
4ff7e37b ED |
237 | @param[in] This Ignored.\r |
238 | @param[in, out] BufferSize Ignored.\r | |
239 | @param[out] Buffer Ignored.\r | |
a405b86d | 240 | \r |
733f138d | 241 | @retval EFI_UNSUPPORTED Always.\r |
a405b86d | 242 | **/\r |
243 | EFI_STATUS\r | |
244 | EFIAPI\r | |
245 | FileInterfaceStdErrRead(\r | |
246 | IN EFI_FILE_PROTOCOL *This,\r | |
247 | IN OUT UINTN *BufferSize,\r | |
248 | OUT VOID *Buffer\r | |
249 | )\r | |
250 | {\r | |
251 | return (EFI_UNSUPPORTED);\r | |
252 | }\r | |
253 | \r | |
254 | /**\r | |
255 | File style interface for NUL file (Read).\r | |
256 | \r | |
4ff7e37b ED |
257 | @param[in] This Ignored.\r |
258 | @param[in, out] BufferSize Poiner to 0 upon return.\r | |
259 | @param[out] Buffer Ignored.\r | |
a405b86d | 260 | \r |
733f138d | 261 | @retval EFI_SUCCESS Always.\r |
a405b86d | 262 | **/\r |
263 | EFI_STATUS\r | |
264 | EFIAPI\r | |
265 | FileInterfaceNulRead(\r | |
733f138d | 266 | IN EFI_FILE_PROTOCOL *This,\r |
267 | IN OUT UINTN *BufferSize,\r | |
268 | OUT VOID *Buffer\r | |
a405b86d | 269 | )\r |
270 | {\r | |
a49f6a2f | 271 | *BufferSize = 0;\r |
a405b86d | 272 | return (EFI_SUCCESS);\r |
273 | }\r | |
274 | \r | |
275 | /**\r | |
276 | File style interface for NUL file (Write).\r | |
277 | \r | |
4ff7e37b ED |
278 | @param[in] This Ignored.\r |
279 | @param[in, out] BufferSize Ignored.\r | |
280 | @param[in] Buffer Ignored.\r | |
a405b86d | 281 | \r |
282 | @retval EFI_SUCCESS\r | |
283 | **/\r | |
284 | EFI_STATUS\r | |
285 | EFIAPI\r | |
286 | FileInterfaceNulWrite(\r | |
287 | IN EFI_FILE_PROTOCOL *This,\r | |
288 | IN OUT UINTN *BufferSize,\r | |
289 | IN VOID *Buffer\r | |
290 | )\r | |
291 | {\r | |
292 | return (EFI_SUCCESS);\r | |
293 | }\r | |
294 | \r | |
9fcfa150 RN |
295 | /**\r |
296 | Create the TAB completion list.\r | |
297 | \r | |
298 | @param[in] InputString The command line to expand.\r | |
299 | @param[in] StringLen Length of the command line.\r | |
300 | @param[in] BufferSize Buffer size.\r | |
8009b2e4 BD |
301 | @param[in, out] TabCompletionList Return the TAB completion list.\r |
302 | @param[in, out] TabUpdatePos Return the TAB update position.\r | |
9fcfa150 RN |
303 | **/\r |
304 | EFI_STATUS\r | |
9fcfa150 RN |
305 | CreateTabCompletionList (\r |
306 | IN CONST CHAR16 *InputString,\r | |
307 | IN CONST UINTN StringLen, \r | |
308 | IN CONST UINTN BufferSize,\r | |
309 | IN OUT EFI_SHELL_FILE_INFO **TabCompletionList,\r | |
310 | IN OUT UINTN *TabUpdatePos\r | |
311 | )\r | |
312 | {\r | |
313 | BOOLEAN InQuotation;\r | |
314 | UINTN TabPos;\r | |
315 | UINTN Index;\r | |
316 | CONST CHAR16 *Cwd;\r | |
317 | EFI_STATUS Status;\r | |
318 | CHAR16 *TabStr;\r | |
319 | EFI_SHELL_FILE_INFO *FileList;\r | |
320 | EFI_SHELL_FILE_INFO *FileInfo;\r | |
321 | EFI_SHELL_FILE_INFO *TempFileInfo;\r | |
322 | \r | |
323 | //\r | |
324 | // Allocate buffers\r | |
325 | //\r | |
326 | TabStr = AllocateZeroPool (BufferSize);\r | |
327 | if (TabStr == NULL) {\r | |
328 | return EFI_OUT_OF_RESOURCES;\r | |
329 | }\r | |
330 | \r | |
331 | //\r | |
332 | // handle auto complete of file and directory names...\r | |
333 | // E.g.: cd fs0:\EFI\Bo<TAB>\r | |
334 | // ^ ^\r | |
335 | // TabPos TabUpdatePos\r | |
336 | //\r | |
337 | TabPos = 0;\r | |
338 | *TabUpdatePos = 0;\r | |
339 | FileList = NULL;\r | |
340 | InQuotation = FALSE;\r | |
341 | for (Index = 0; Index < StringLen; Index++) {\r | |
342 | switch (InputString[Index]) {\r | |
343 | case L'\"':\r | |
344 | InQuotation = (BOOLEAN) (!InQuotation);\r | |
345 | break;\r | |
346 | \r | |
347 | case L' ':\r | |
348 | if (!InQuotation) {\r | |
349 | TabPos = Index + 1;\r | |
350 | *TabUpdatePos = TabPos;\r | |
351 | }\r | |
352 | break;\r | |
353 | \r | |
354 | case L':':\r | |
355 | //\r | |
356 | // handle the case "fs0:<TAB>"\r | |
357 | // Update the TabUpdatePos as well.\r | |
358 | //\r | |
359 | case L'\\':\r | |
360 | *TabUpdatePos = Index + 1;\r | |
361 | break;\r | |
362 | \r | |
363 | default:\r | |
364 | break;\r | |
365 | }\r | |
366 | }\r | |
367 | \r | |
368 | if (StrStr (InputString + TabPos, L":") == NULL) {\r | |
369 | //\r | |
db2e266a | 370 | // If file path doesn't contain ":", ...\r |
9fcfa150 RN |
371 | //\r |
372 | Cwd = ShellInfoObject.NewEfiShellProtocol->GetCurDir (NULL);\r | |
373 | if (Cwd != NULL) {\r | |
9fcfa150 | 374 | if (InputString[TabPos] != L'\\') {\r |
db2e266a RN |
375 | //\r |
376 | // and it doesn't begin with "\\", it's a path relative to current directory.\r | |
377 | // TabStr = "<cwd>\\"\r | |
378 | //\r | |
379 | StrnCpyS (TabStr, BufferSize / sizeof (CHAR16), Cwd, (BufferSize) / sizeof (CHAR16) - 1);\r | |
9fcfa150 | 380 | StrCatS (TabStr, (BufferSize) / sizeof (CHAR16), L"\\");\r |
db2e266a RN |
381 | } else {\r |
382 | //\r | |
383 | // and it begins with "\\", it's a path pointing to root directory of current map.\r | |
384 | // TabStr = "fsx:"\r | |
385 | //\r | |
386 | Index = StrStr (Cwd, L":") - Cwd + 1;\r | |
387 | StrnCpyS (TabStr, BufferSize / sizeof (CHAR16), Cwd, Index);\r | |
9fcfa150 RN |
388 | }\r |
389 | }\r | |
390 | }\r | |
391 | StrnCatS (TabStr, (BufferSize) / sizeof (CHAR16), InputString + TabPos, StringLen - TabPos);\r | |
392 | StrnCatS (TabStr, (BufferSize) / sizeof (CHAR16), L"*", (BufferSize) / sizeof (CHAR16) - 1 - StrLen (TabStr));\r | |
393 | Status = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FileList);\r | |
394 | \r | |
395 | //\r | |
396 | // Filter out the non-directory for "CD" command\r | |
397 | // Filter "." and ".." for all\r | |
398 | //\r | |
399 | if (!EFI_ERROR (Status) && FileList != NULL) {\r | |
400 | //\r | |
401 | // Skip the spaces in the beginning\r | |
402 | //\r | |
403 | while (*InputString == L' ') {\r | |
404 | InputString++;\r | |
405 | }\r | |
406 | \r | |
407 | for (FileInfo = (EFI_SHELL_FILE_INFO *) GetFirstNode (&FileList->Link); !IsNull (&FileList->Link, &FileInfo->Link); ) {\r | |
408 | if (((StrCmp (FileInfo->FileName, L".") == 0) || (StrCmp (FileInfo->FileName, L"..") == 0)) ||\r | |
409 | (((InputString[0] == L'c' || InputString[0] == L'C') && (InputString[1] == L'd' || InputString[1] == L'D')) &&\r | |
410 | (ShellIsDirectory (FileInfo->FullName) != EFI_SUCCESS))) {\r | |
411 | TempFileInfo = FileInfo;\r | |
412 | FileInfo = (EFI_SHELL_FILE_INFO *) RemoveEntryList (&FileInfo->Link);\r | |
413 | InternalFreeShellFileInfoNode (TempFileInfo);\r | |
414 | } else {\r | |
415 | FileInfo = (EFI_SHELL_FILE_INFO *) GetNextNode (&FileList->Link, &FileInfo->Link);\r | |
416 | }\r | |
417 | }\r | |
418 | }\r | |
419 | \r | |
420 | if (FileList != NULL && !IsListEmpty (&FileList->Link)) {\r | |
421 | Status = EFI_SUCCESS;\r | |
422 | } else {\r | |
423 | ShellInfoObject.NewEfiShellProtocol->FreeFileList (&FileList);\r | |
424 | Status = EFI_NOT_FOUND;\r | |
425 | }\r | |
426 | \r | |
427 | FreePool (TabStr);\r | |
428 | \r | |
429 | *TabCompletionList = FileList;\r | |
430 | return Status;\r | |
431 | }\r | |
432 | \r | |
a405b86d | 433 | /**\r |
434 | File style interface for console (Read).\r | |
435 | \r | |
436 | This will return a single line of input from the console.\r | |
437 | \r | |
438 | @param This A pointer to the EFI_FILE_PROTOCOL instance that is the\r | |
439 | file handle to read data from. Not used.\r | |
440 | @param BufferSize On input, the size of the Buffer. On output, the amount\r | |
441 | of data returned in Buffer. In both cases, the size is\r | |
442 | measured in bytes.\r | |
443 | @param Buffer The buffer into which the data is read.\r | |
444 | \r | |
445 | \r | |
446 | @retval EFI_SUCCESS The data was read.\r | |
447 | @retval EFI_NO_MEDIA The device has no medium.\r | |
448 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
449 | @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.\r | |
450 | @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the end of the file.\r | |
451 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
452 | @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current directory\r | |
453 | entry. BufferSize has been updated with the size\r | |
454 | needed to complete the request.\r | |
455 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
456 | **/\r | |
457 | EFI_STATUS\r | |
458 | EFIAPI\r | |
459 | FileInterfaceStdInRead(\r | |
460 | IN EFI_FILE_PROTOCOL *This,\r | |
461 | IN OUT UINTN *BufferSize,\r | |
462 | OUT VOID *Buffer\r | |
463 | )\r | |
464 | {\r | |
465 | CHAR16 *CurrentString;\r | |
466 | BOOLEAN Done;\r | |
9fcfa150 | 467 | UINTN TabUpdatePos; // Start index of the string updated by TAB stroke\r |
a405b86d | 468 | UINTN Column; // Column of current cursor\r |
469 | UINTN Row; // Row of current cursor\r | |
470 | UINTN StartColumn; // Column at the beginning of the line\r | |
471 | UINTN Update; // Line index for update\r | |
472 | UINTN Delete; // Num of chars to delete from console after update\r | |
473 | UINTN StringLen; // Total length of the line\r | |
474 | UINTN StringCurPos; // Line index corresponding to the cursor\r | |
475 | UINTN MaxStr; // Maximum possible line length\r | |
a405b86d | 476 | UINTN TotalColumn; // Num of columns in the console\r |
477 | UINTN TotalRow; // Num of rows in the console\r | |
478 | UINTN SkipLength;\r | |
479 | UINTN OutputLength; // Length of the update string\r | |
480 | UINTN TailRow; // Row of end of line\r | |
481 | UINTN TailColumn; // Column of end of line\r | |
482 | EFI_INPUT_KEY Key;\r | |
483 | \r | |
484 | BUFFER_LIST *LinePos;\r | |
485 | BUFFER_LIST *NewPos;\r | |
486 | BOOLEAN InScrolling;\r | |
487 | EFI_STATUS Status;\r | |
488 | BOOLEAN InTabScrolling; // Whether in TAB-completion state\r | |
9fcfa150 RN |
489 | EFI_SHELL_FILE_INFO *TabCompleteList;\r |
490 | EFI_SHELL_FILE_INFO *TabCurrent;\r | |
a405b86d | 491 | UINTN EventIndex;\r |
9fcfa150 | 492 | CHAR16 *TabOutputStr;\r |
a405b86d | 493 | \r |
494 | //\r | |
495 | // If buffer is not large enough to hold a CHAR16, return minimum buffer size\r | |
496 | //\r | |
497 | if (*BufferSize < sizeof (CHAR16) * 2) {\r | |
498 | *BufferSize = sizeof (CHAR16) * 2;\r | |
499 | return (EFI_BUFFER_TOO_SMALL);\r | |
500 | }\r | |
501 | \r | |
502 | Done = FALSE;\r | |
503 | CurrentString = Buffer;\r | |
504 | StringLen = 0;\r | |
505 | StringCurPos = 0;\r | |
506 | OutputLength = 0;\r | |
507 | Update = 0;\r | |
508 | Delete = 0;\r | |
509 | LinePos = NewPos = (BUFFER_LIST*)(&ShellInfoObject.ViewingSettings.CommandHistory);\r | |
510 | InScrolling = FALSE;\r | |
511 | InTabScrolling = FALSE;\r | |
512 | Status = EFI_SUCCESS;\r | |
9fcfa150 | 513 | TabOutputStr = NULL;\r |
a405b86d | 514 | TabUpdatePos = 0;\r |
9fcfa150 RN |
515 | TabCompleteList = NULL;\r |
516 | TabCurrent = NULL;\r | |
a405b86d | 517 | \r |
518 | //\r | |
519 | // Get the screen setting and the current cursor location\r | |
520 | //\r | |
521 | Column = StartColumn = gST->ConOut->Mode->CursorColumn;\r | |
522 | Row = gST->ConOut->Mode->CursorRow;\r | |
523 | gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &TotalColumn, &TotalRow);\r | |
524 | \r | |
525 | //\r | |
526 | // Limit the line length to the buffer size or the minimun size of the\r | |
527 | // screen. (The smaller takes effect)\r | |
528 | //\r | |
529 | MaxStr = TotalColumn * (TotalRow - 1) - StartColumn;\r | |
530 | if (MaxStr > *BufferSize / sizeof (CHAR16)) {\r | |
531 | MaxStr = *BufferSize / sizeof (CHAR16);\r | |
532 | }\r | |
533 | ZeroMem (CurrentString, MaxStr * sizeof (CHAR16));\r | |
534 | do {\r | |
535 | //\r | |
536 | // Read a key\r | |
537 | //\r | |
538 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r | |
539 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
540 | if (EFI_ERROR (Status)) {\r | |
b8f3601d PL |
541 | \r |
542 | if (Status == EFI_NOT_READY)\r | |
543 | continue;\r | |
544 | \r | |
545 | ZeroMem (CurrentString, MaxStr * sizeof(CHAR16));\r | |
546 | StringLen = 0;\r | |
4dd8c7af | 547 | break;\r |
a405b86d | 548 | }\r |
549 | \r | |
550 | //\r | |
551 | // Press PageUp or PageDown to scroll the history screen up or down.\r | |
552 | // Press any other key to quit scrolling.\r | |
553 | //\r | |
554 | if (Key.UnicodeChar == 0 && (Key.ScanCode == SCAN_PAGE_UP || Key.ScanCode == SCAN_PAGE_DOWN)) {\r | |
555 | if (Key.ScanCode == SCAN_PAGE_UP) {\r | |
556 | ConsoleLoggerDisplayHistory(FALSE, 0, ShellInfoObject.ConsoleInfo);\r | |
557 | } else if (Key.ScanCode == SCAN_PAGE_DOWN) {\r | |
558 | ConsoleLoggerDisplayHistory(TRUE, 0, ShellInfoObject.ConsoleInfo);\r | |
559 | }\r | |
560 | \r | |
561 | InScrolling = TRUE;\r | |
562 | } else {\r | |
563 | if (InScrolling) {\r | |
564 | ConsoleLoggerStopHistory(ShellInfoObject.ConsoleInfo);\r | |
565 | InScrolling = FALSE;\r | |
566 | }\r | |
567 | }\r | |
568 | \r | |
569 | //\r | |
570 | // If we are quitting TAB scrolling...\r | |
571 | //\r | |
572 | if (InTabScrolling && Key.UnicodeChar != CHAR_TAB) {\r | |
9fcfa150 RN |
573 | if (TabCompleteList != NULL) {\r |
574 | ShellInfoObject.NewEfiShellProtocol->FreeFileList (&TabCompleteList);\r | |
575 | DEBUG_CODE(TabCompleteList = NULL;);\r | |
576 | }\r | |
577 | InTabScrolling = FALSE;\r | |
a405b86d | 578 | }\r |
579 | \r | |
580 | switch (Key.UnicodeChar) {\r | |
581 | case CHAR_CARRIAGE_RETURN:\r | |
582 | //\r | |
583 | // All done, print a newline at the end of the string\r | |
584 | //\r | |
585 | TailRow = Row + (StringLen - StringCurPos + Column) / TotalColumn;\r | |
586 | TailColumn = (StringLen - StringCurPos + Column) % TotalColumn;\r | |
587 | ShellPrintEx ((INT32)TailColumn, (INT32)TailRow, L"%N\n");\r | |
588 | Done = TRUE;\r | |
589 | break;\r | |
590 | \r | |
591 | case CHAR_BACKSPACE:\r | |
592 | if (StringCurPos != 0) {\r | |
593 | //\r | |
594 | // If not move back beyond string beginning, move all characters behind\r | |
595 | // the current position one character forward\r | |
596 | //\r | |
597 | StringCurPos--;\r | |
598 | Update = StringCurPos;\r | |
599 | Delete = 1;\r | |
600 | CopyMem (CurrentString + StringCurPos, CurrentString + StringCurPos + 1, sizeof (CHAR16) * (StringLen - StringCurPos));\r | |
601 | \r | |
602 | //\r | |
603 | // Adjust the current column and row\r | |
604 | //\r | |
605 | MoveCursorBackward (TotalColumn, &Column, &Row);\r | |
606 | }\r | |
607 | break;\r | |
608 | \r | |
609 | case CHAR_TAB:\r | |
9fcfa150 RN |
610 | if (!InTabScrolling) {\r |
611 | TabCurrent = NULL;\r | |
612 | //\r | |
613 | // Initialize a tab complete operation.\r | |
614 | //\r | |
615 | Status = CreateTabCompletionList (CurrentString, StringLen, *BufferSize, &TabCompleteList, &TabUpdatePos);\r | |
616 | if (!EFI_ERROR(Status)) {\r | |
617 | InTabScrolling = TRUE;\r | |
a405b86d | 618 | }\r |
9fcfa150 RN |
619 | \r |
620 | //\r | |
621 | // We do not set up the replacement.\r | |
622 | // The next section will do that.\r | |
623 | //\r | |
624 | }\r | |
625 | \r | |
626 | if (InTabScrolling) {\r | |
627 | //\r | |
628 | // We are in a tab complete operation.\r | |
629 | // set up the next replacement.\r | |
630 | //\r | |
631 | ASSERT(TabCompleteList != NULL);\r | |
632 | if (TabCurrent == NULL) {\r | |
633 | TabCurrent = (EFI_SHELL_FILE_INFO*) GetFirstNode (&TabCompleteList->Link);\r | |
a405b86d | 634 | } else {\r |
9fcfa150 | 635 | TabCurrent = (EFI_SHELL_FILE_INFO*) GetNextNode (&TabCompleteList->Link, &TabCurrent->Link);\r |
a405b86d | 636 | }\r |
9fcfa150 RN |
637 | \r |
638 | //\r | |
639 | // Skip over the empty list beginning node\r | |
640 | //\r | |
641 | if (IsNull(&TabCompleteList->Link, &TabCurrent->Link)) {\r | |
642 | TabCurrent = (EFI_SHELL_FILE_INFO*) GetNextNode (&TabCompleteList->Link, &TabCurrent->Link);\r | |
a405b86d | 643 | }\r |
644 | }\r | |
645 | break;\r | |
646 | \r | |
647 | default:\r | |
648 | if (Key.UnicodeChar >= ' ') {\r | |
649 | //\r | |
650 | // If we are at the buffer's end, drop the key\r | |
651 | //\r | |
652 | if (StringLen == MaxStr - 1 && (ShellInfoObject.ViewingSettings.InsertMode || StringCurPos == StringLen)) {\r | |
653 | break;\r | |
654 | }\r | |
655 | //\r | |
656 | // If in insert mode, make space by moving each other character 1\r | |
657 | // space higher in the array\r | |
658 | //\r | |
659 | if (ShellInfoObject.ViewingSettings.InsertMode) {\r | |
660 | CopyMem(CurrentString + StringCurPos + 1, CurrentString + StringCurPos, (StringLen - StringCurPos)*sizeof(CurrentString[0]));\r | |
661 | }\r | |
662 | \r | |
663 | CurrentString[StringCurPos] = Key.UnicodeChar;\r | |
664 | Update = StringCurPos;\r | |
665 | \r | |
666 | StringCurPos += 1;\r | |
667 | OutputLength = 1;\r | |
668 | }\r | |
669 | break;\r | |
670 | \r | |
671 | case 0:\r | |
672 | switch (Key.ScanCode) {\r | |
673 | case SCAN_DELETE:\r | |
674 | //\r | |
675 | // Move characters behind current position one character forward\r | |
676 | //\r | |
677 | if (StringLen != 0) {\r | |
678 | Update = StringCurPos;\r | |
679 | Delete = 1;\r | |
680 | CopyMem (CurrentString + StringCurPos, CurrentString + StringCurPos + 1, sizeof (CHAR16) * (StringLen - StringCurPos));\r | |
681 | }\r | |
682 | break;\r | |
683 | \r | |
684 | case SCAN_UP:\r | |
685 | //\r | |
686 | // Prepare to print the previous command\r | |
687 | //\r | |
688 | NewPos = (BUFFER_LIST*)GetPreviousNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &LinePos->Link);\r | |
689 | if (IsNull(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &LinePos->Link)) {\r | |
690 | NewPos = (BUFFER_LIST*)GetPreviousNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &LinePos->Link);\r | |
691 | }\r | |
692 | break;\r | |
693 | \r | |
694 | case SCAN_DOWN:\r | |
695 | //\r | |
696 | // Prepare to print the next command\r | |
697 | //\r | |
698 | NewPos = (BUFFER_LIST*)GetNextNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &LinePos->Link);\r | |
699 | if (NewPos == (BUFFER_LIST*)(&ShellInfoObject.ViewingSettings.CommandHistory)) {\r | |
700 | NewPos = (BUFFER_LIST*)GetNextNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &LinePos->Link);\r | |
701 | }\r | |
702 | break;\r | |
703 | \r | |
704 | case SCAN_LEFT:\r | |
705 | //\r | |
706 | // Adjust current cursor position\r | |
707 | //\r | |
708 | if (StringCurPos != 0) {\r | |
709 | --StringCurPos;\r | |
710 | MoveCursorBackward (TotalColumn, &Column, &Row);\r | |
711 | }\r | |
712 | break;\r | |
713 | \r | |
714 | case SCAN_RIGHT:\r | |
715 | //\r | |
716 | // Adjust current cursor position\r | |
717 | //\r | |
718 | if (StringCurPos < StringLen) {\r | |
719 | ++StringCurPos;\r | |
720 | MoveCursorForward (TotalColumn, TotalRow, &Column, &Row);\r | |
721 | }\r | |
722 | break;\r | |
723 | \r | |
724 | case SCAN_HOME:\r | |
725 | //\r | |
726 | // Move current cursor position to the beginning of the command line\r | |
727 | //\r | |
728 | Row -= (StringCurPos + StartColumn) / TotalColumn;\r | |
729 | Column = StartColumn;\r | |
730 | StringCurPos = 0;\r | |
731 | break;\r | |
732 | \r | |
733 | case SCAN_END:\r | |
734 | //\r | |
735 | // Move current cursor position to the end of the command line\r | |
736 | //\r | |
737 | TailRow = Row + (StringLen - StringCurPos + Column) / TotalColumn;\r | |
738 | TailColumn = (StringLen - StringCurPos + Column) % TotalColumn;\r | |
739 | Row = TailRow;\r | |
740 | Column = TailColumn;\r | |
741 | StringCurPos = StringLen;\r | |
742 | break;\r | |
743 | \r | |
744 | case SCAN_ESC:\r | |
745 | //\r | |
746 | // Prepare to clear the current command line\r | |
747 | //\r | |
748 | CurrentString[0] = 0;\r | |
749 | Update = 0;\r | |
750 | Delete = StringLen;\r | |
751 | Row -= (StringCurPos + StartColumn) / TotalColumn;\r | |
752 | Column = StartColumn;\r | |
753 | OutputLength = 0;\r | |
754 | break;\r | |
755 | \r | |
756 | case SCAN_INSERT:\r | |
757 | //\r | |
758 | // Toggle the SEnvInsertMode flag\r | |
759 | //\r | |
760 | ShellInfoObject.ViewingSettings.InsertMode = (BOOLEAN)!ShellInfoObject.ViewingSettings.InsertMode;\r | |
761 | break;\r | |
762 | \r | |
763 | case SCAN_F7:\r | |
764 | //\r | |
765 | // Print command history\r | |
766 | //\r | |
767 | PrintCommandHistory (TotalColumn, TotalRow, 4);\r | |
768 | *CurrentString = CHAR_NULL;\r | |
769 | Done = TRUE;\r | |
770 | break;\r | |
771 | }\r | |
772 | }\r | |
773 | \r | |
774 | if (Done) {\r | |
775 | break;\r | |
776 | }\r | |
777 | \r | |
778 | //\r | |
779 | // If we are in auto-complete mode, we are preparing to print\r | |
780 | // the next file or directory name\r | |
781 | //\r | |
782 | if (InTabScrolling) {\r | |
9fcfa150 RN |
783 | TabOutputStr = AllocateZeroPool (*BufferSize);\r |
784 | if (TabOutputStr == NULL) {\r | |
785 | Status = EFI_OUT_OF_RESOURCES;\r | |
786 | }\r | |
787 | }\r | |
788 | \r | |
789 | if (InTabScrolling && TabOutputStr != NULL) {\r | |
790 | \r | |
a405b86d | 791 | //\r |
792 | // Adjust the column and row to the start of TAB-completion string.\r | |
793 | //\r | |
794 | Column = (StartColumn + TabUpdatePos) % TotalColumn;\r | |
795 | Row -= (StartColumn + StringCurPos) / TotalColumn - (StartColumn + TabUpdatePos) / TotalColumn;\r | |
9fcfa150 | 796 | OutputLength = StrLen (TabCurrent->FileName);\r |
a405b86d | 797 | //\r |
798 | // if the output string contains blank space, quotation marks L'\"'\r | |
799 | // should be added to the output.\r | |
800 | //\r | |
9fcfa150 | 801 | if (StrStr(TabCurrent->FileName, L" ") != NULL){\r |
a405b86d | 802 | TabOutputStr[0] = L'\"';\r |
9fcfa150 | 803 | CopyMem (TabOutputStr + 1, TabCurrent->FileName, OutputLength * sizeof (CHAR16));\r |
a405b86d | 804 | TabOutputStr[OutputLength + 1] = L'\"';\r |
805 | TabOutputStr[OutputLength + 2] = CHAR_NULL;\r | |
806 | } else {\r | |
9fcfa150 | 807 | CopyMem (TabOutputStr, TabCurrent->FileName, OutputLength * sizeof (CHAR16));\r |
a405b86d | 808 | TabOutputStr[OutputLength] = CHAR_NULL;\r |
809 | }\r | |
810 | OutputLength = StrLen (TabOutputStr) < MaxStr - 1 ? StrLen (TabOutputStr) : MaxStr - 1;\r | |
811 | CopyMem (CurrentString + TabUpdatePos, TabOutputStr, OutputLength * sizeof (CHAR16));\r | |
812 | CurrentString[TabUpdatePos + OutputLength] = CHAR_NULL;\r | |
813 | StringCurPos = TabUpdatePos + OutputLength;\r | |
814 | Update = TabUpdatePos;\r | |
815 | if (StringLen > TabUpdatePos + OutputLength) {\r | |
816 | Delete = StringLen - TabUpdatePos - OutputLength;\r | |
817 | }\r | |
9fcfa150 RN |
818 | \r |
819 | FreePool(TabOutputStr);\r | |
a405b86d | 820 | }\r |
821 | \r | |
822 | //\r | |
823 | // If we have a new position, we are preparing to print a previous or\r | |
824 | // next command.\r | |
825 | //\r | |
826 | if (NewPos != (BUFFER_LIST*)(&ShellInfoObject.ViewingSettings.CommandHistory)) {\r | |
827 | Column = StartColumn;\r | |
828 | Row -= (StringCurPos + StartColumn) / TotalColumn;\r | |
829 | \r | |
830 | LinePos = NewPos;\r | |
831 | NewPos = (BUFFER_LIST*)(&ShellInfoObject.ViewingSettings.CommandHistory);\r | |
832 | \r | |
833 | OutputLength = StrLen (LinePos->Buffer) < MaxStr - 1 ? StrLen (LinePos->Buffer) : MaxStr - 1;\r | |
834 | CopyMem (CurrentString, LinePos->Buffer, OutputLength * sizeof (CHAR16));\r | |
835 | CurrentString[OutputLength] = CHAR_NULL;\r | |
836 | \r | |
837 | StringCurPos = OutputLength;\r | |
838 | \r | |
839 | //\r | |
840 | // Draw new input string\r | |
841 | //\r | |
842 | Update = 0;\r | |
843 | if (StringLen > OutputLength) {\r | |
844 | //\r | |
845 | // If old string was longer, blank its tail\r | |
846 | //\r | |
847 | Delete = StringLen - OutputLength;\r | |
848 | }\r | |
849 | }\r | |
850 | //\r | |
851 | // If we need to update the output do so now\r | |
852 | //\r | |
853 | if (Update != (UINTN) -1) {\r | |
854 | ShellPrintEx ((INT32)Column, (INT32)Row, L"%s%.*s", CurrentString + Update, Delete, L"");\r | |
855 | StringLen = StrLen (CurrentString);\r | |
856 | \r | |
857 | if (Delete != 0) {\r | |
858 | SetMem (CurrentString + StringLen, Delete * sizeof (CHAR16), CHAR_NULL);\r | |
859 | }\r | |
860 | \r | |
861 | if (StringCurPos > StringLen) {\r | |
862 | StringCurPos = StringLen;\r | |
863 | }\r | |
864 | \r | |
865 | Update = (UINTN) -1;\r | |
866 | \r | |
867 | //\r | |
868 | // After using print to reflect newly updates, if we're not using\r | |
869 | // BACKSPACE and DELETE, we need to move the cursor position forward,\r | |
870 | // so adjust row and column here.\r | |
871 | //\r | |
872 | if (Key.UnicodeChar != CHAR_BACKSPACE && !(Key.UnicodeChar == 0 && Key.ScanCode == SCAN_DELETE)) {\r | |
873 | //\r | |
874 | // Calulate row and column of the tail of current string\r | |
875 | //\r | |
876 | TailRow = Row + (StringLen - StringCurPos + Column + OutputLength) / TotalColumn;\r | |
877 | TailColumn = (StringLen - StringCurPos + Column + OutputLength) % TotalColumn;\r | |
878 | \r | |
879 | //\r | |
880 | // If the tail of string reaches screen end, screen rolls up, so if\r | |
881 | // Row does not equal TailRow, Row should be decremented\r | |
882 | //\r | |
883 | // (if we are recalling commands using UPPER and DOWN key, and if the\r | |
884 | // old command is too long to fit the screen, TailColumn must be 79.\r | |
885 | //\r | |
886 | if (TailColumn == 0 && TailRow >= TotalRow && Row != TailRow) {\r | |
887 | Row--;\r | |
888 | }\r | |
889 | //\r | |
890 | // Calculate the cursor position after current operation. If cursor\r | |
891 | // reaches line end, update both row and column, otherwise, only\r | |
892 | // column will be changed.\r | |
893 | //\r | |
894 | if (Column + OutputLength >= TotalColumn) {\r | |
895 | SkipLength = OutputLength - (TotalColumn - Column);\r | |
896 | \r | |
897 | Row += SkipLength / TotalColumn + 1;\r | |
898 | if (Row > TotalRow - 1) {\r | |
899 | Row = TotalRow - 1;\r | |
900 | }\r | |
901 | \r | |
902 | Column = SkipLength % TotalColumn;\r | |
903 | } else {\r | |
904 | Column += OutputLength;\r | |
905 | }\r | |
906 | }\r | |
907 | \r | |
908 | Delete = 0;\r | |
909 | }\r | |
910 | //\r | |
911 | // Set the cursor position for this key\r | |
912 | //\r | |
913 | gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);\r | |
914 | } while (!Done);\r | |
915 | \r | |
916 | if (CurrentString != NULL && StrLen(CurrentString) > 0) {\r | |
917 | //\r | |
918 | // add the line to the history buffer\r | |
919 | //\r | |
920 | AddLineToCommandHistory(CurrentString);\r | |
921 | }\r | |
922 | \r | |
a405b86d | 923 | //\r |
924 | // Return the data to the caller\r | |
925 | //\r | |
926 | *BufferSize = StringLen * sizeof (CHAR16);\r | |
927 | \r | |
928 | //\r | |
929 | // if this was used it should be deallocated by now...\r | |
930 | // prevent memory leaks...\r | |
931 | //\r | |
9fcfa150 RN |
932 | if (TabCompleteList != NULL) {\r |
933 | ShellInfoObject.NewEfiShellProtocol->FreeFileList (&TabCompleteList);\r | |
9c17810a | 934 | }\r |
9fcfa150 | 935 | ASSERT(TabCompleteList == NULL);\r |
a405b86d | 936 | \r |
4dd8c7af | 937 | return Status;\r |
a405b86d | 938 | }\r |
939 | \r | |
940 | //\r | |
941 | // FILE sytle interfaces for StdIn/StdOut/StdErr\r | |
942 | //\r | |
943 | EFI_FILE_PROTOCOL FileInterfaceStdIn = {\r | |
944 | EFI_FILE_REVISION,\r | |
945 | FileInterfaceOpenNotFound,\r | |
946 | FileInterfaceNopGeneric,\r | |
947 | FileInterfaceNopGeneric,\r | |
948 | FileInterfaceStdInRead,\r | |
949 | FileInterfaceStdInWrite,\r | |
950 | FileInterfaceNopGetPosition,\r | |
951 | FileInterfaceNopSetPosition,\r | |
952 | FileInterfaceNopGetInfo,\r | |
953 | FileInterfaceNopSetInfo,\r | |
954 | FileInterfaceNopGeneric\r | |
955 | };\r | |
956 | \r | |
957 | EFI_FILE_PROTOCOL FileInterfaceStdOut = {\r | |
958 | EFI_FILE_REVISION,\r | |
959 | FileInterfaceOpenNotFound,\r | |
960 | FileInterfaceNopGeneric,\r | |
961 | FileInterfaceNopGeneric,\r | |
962 | FileInterfaceStdOutRead,\r | |
963 | FileInterfaceStdOutWrite,\r | |
964 | FileInterfaceNopGetPosition,\r | |
965 | FileInterfaceNopSetPosition,\r | |
966 | FileInterfaceNopGetInfo,\r | |
967 | FileInterfaceNopSetInfo,\r | |
968 | FileInterfaceNopGeneric\r | |
969 | };\r | |
970 | \r | |
971 | EFI_FILE_PROTOCOL FileInterfaceStdErr = {\r | |
972 | EFI_FILE_REVISION,\r | |
973 | FileInterfaceOpenNotFound,\r | |
974 | FileInterfaceNopGeneric,\r | |
975 | FileInterfaceNopGeneric,\r | |
976 | FileInterfaceStdErrRead,\r | |
977 | FileInterfaceStdErrWrite,\r | |
978 | FileInterfaceNopGetPosition,\r | |
979 | FileInterfaceNopSetPosition,\r | |
980 | FileInterfaceNopGetInfo,\r | |
981 | FileInterfaceNopSetInfo,\r | |
982 | FileInterfaceNopGeneric\r | |
983 | };\r | |
984 | \r | |
985 | EFI_FILE_PROTOCOL FileInterfaceNulFile = {\r | |
986 | EFI_FILE_REVISION,\r | |
987 | FileInterfaceOpenNotFound,\r | |
988 | FileInterfaceNopGeneric,\r | |
989 | FileInterfaceNopGeneric,\r | |
990 | FileInterfaceNulRead,\r | |
991 | FileInterfaceNulWrite,\r | |
992 | FileInterfaceNopGetPosition,\r | |
993 | FileInterfaceNopSetPosition,\r | |
994 | FileInterfaceNopGetInfo,\r | |
995 | FileInterfaceNopSetInfo,\r | |
996 | FileInterfaceNopGeneric\r | |
997 | };\r | |
998 | \r | |
999 | \r | |
1000 | \r | |
1001 | \r | |
1002 | //\r | |
1003 | // This is identical to EFI_FILE_PROTOCOL except for the additional member\r | |
1004 | // for the name.\r | |
1005 | //\r | |
1006 | \r | |
1007 | typedef struct {\r | |
1008 | UINT64 Revision;\r | |
1009 | EFI_FILE_OPEN Open;\r | |
1010 | EFI_FILE_CLOSE Close;\r | |
1011 | EFI_FILE_DELETE Delete;\r | |
1012 | EFI_FILE_READ Read;\r | |
1013 | EFI_FILE_WRITE Write;\r | |
1014 | EFI_FILE_GET_POSITION GetPosition;\r | |
1015 | EFI_FILE_SET_POSITION SetPosition;\r | |
1016 | EFI_FILE_GET_INFO GetInfo;\r | |
1017 | EFI_FILE_SET_INFO SetInfo;\r | |
1018 | EFI_FILE_FLUSH Flush;\r | |
1019 | CHAR16 Name[1];\r | |
1020 | } EFI_FILE_PROTOCOL_ENVIRONMENT;\r | |
1021 | //ANSI compliance helper to get size of the struct.\r | |
1022 | #define SIZE_OF_EFI_FILE_PROTOCOL_ENVIRONMENT EFI_FIELD_OFFSET (EFI_FILE_PROTOCOL_ENVIRONMENT, Name)\r | |
1023 | \r | |
1024 | /**\r | |
1025 | File style interface for Environment Variable (Close).\r | |
1026 | \r | |
1027 | Frees the memory for this object.\r | |
1028 | \r | |
1029 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r | |
1030 | \r | |
1031 | @retval EFI_SUCCESS\r | |
1032 | **/\r | |
1033 | EFI_STATUS\r | |
1034 | EFIAPI\r | |
1035 | FileInterfaceEnvClose(\r | |
1036 | IN EFI_FILE_PROTOCOL *This\r | |
1037 | )\r | |
1038 | {\r | |
416a423f CP |
1039 | VOID* NewBuffer;\r |
1040 | UINTN NewSize;\r | |
1041 | EFI_STATUS Status;\r | |
31e5b912 | 1042 | BOOLEAN Volatile;\r |
416a423f CP |
1043 | \r |
1044 | //\r | |
1045 | // Most if not all UEFI commands will have an '\r\n' at the end of any output. \r | |
1046 | // Since the output was redirected to a variable, it does not make sense to \r | |
1047 | // keep this. So, before closing, strip the trailing '\r\n' from the variable\r | |
1048 | // if it exists.\r | |
1049 | //\r | |
1050 | NewBuffer = NULL;\r | |
1051 | NewSize = 0;\r | |
1052 | \r | |
31e5b912 RN |
1053 | Status = IsVolatileEnv (((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &Volatile);\r |
1054 | if (EFI_ERROR (Status)) {\r | |
1055 | return Status;\r | |
1056 | }\r | |
1057 | \r | |
416a423f CP |
1058 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r |
1059 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
1060 | NewBuffer = AllocateZeroPool(NewSize + sizeof(CHAR16));\r | |
1061 | if (NewBuffer == NULL) {\r | |
1062 | return EFI_OUT_OF_RESOURCES;\r | |
1063 | } \r | |
1064 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r | |
1065 | }\r | |
1066 | \r | |
03bc7c2b | 1067 | if (!EFI_ERROR(Status) && NewBuffer != NULL) {\r |
416a423f CP |
1068 | \r |
1069 | if (StrSize(NewBuffer) > 6)\r | |
1070 | {\r | |
1071 | if ((((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 2] == CHAR_LINEFEED) \r | |
1072 | && (((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] == CHAR_CARRIAGE_RETURN)) {\r | |
1073 | ((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] = CHAR_NULL; \r | |
1074 | }\r | |
31e5b912 RN |
1075 | \r |
1076 | if (Volatile) {\r | |
416a423f CP |
1077 | Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r |
1078 | } else {\r | |
1079 | Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r | |
1080 | }\r | |
1081 | }\r | |
1082 | } \r | |
1083 | \r | |
1084 | SHELL_FREE_NON_NULL(NewBuffer);\r | |
a405b86d | 1085 | FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT*)This);\r |
416a423f | 1086 | return (Status);\r |
a405b86d | 1087 | }\r |
1088 | \r | |
1089 | /**\r | |
1090 | File style interface for Environment Variable (Delete).\r | |
1091 | \r | |
1092 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r | |
1093 | \r | |
1094 | @retval The return value from FileInterfaceEnvClose().\r | |
1095 | **/\r | |
1096 | EFI_STATUS\r | |
1097 | EFIAPI\r | |
1098 | FileInterfaceEnvDelete(\r | |
1099 | IN EFI_FILE_PROTOCOL *This\r | |
1100 | )\r | |
1101 | {\r | |
1102 | SHELL_DELETE_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name);\r | |
1103 | return (FileInterfaceEnvClose(This));\r | |
1104 | }\r | |
1105 | \r | |
1106 | /**\r | |
1107 | File style interface for Environment Variable (Read).\r | |
1108 | \r | |
4ff7e37b ED |
1109 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
1110 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
1111 | @param[out] Buffer The pointer to the buffer to fill.\r | |
a405b86d | 1112 | \r |
1113 | @retval EFI_SUCCESS The data was read.\r | |
1114 | **/\r | |
1115 | EFI_STATUS\r | |
1116 | EFIAPI\r | |
1117 | FileInterfaceEnvRead(\r | |
1118 | IN EFI_FILE_PROTOCOL *This,\r | |
1119 | IN OUT UINTN *BufferSize,\r | |
1120 | OUT VOID *Buffer\r | |
1121 | )\r | |
1122 | {\r | |
1123 | return (SHELL_GET_ENVIRONMENT_VARIABLE(\r | |
1124 | ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r | |
1125 | BufferSize,\r | |
1126 | Buffer));\r | |
1127 | }\r | |
1128 | \r | |
1129 | /**\r | |
1130 | File style interface for Volatile Environment Variable (Write).\r | |
1131 | \r | |
4ff7e37b ED |
1132 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
1133 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
1134 | @param[in] Buffer The pointer to the buffer to write.\r | |
a405b86d | 1135 | \r |
1136 | @retval EFI_SUCCESS The data was read.\r | |
1137 | **/\r | |
1138 | EFI_STATUS\r | |
1139 | EFIAPI\r | |
1140 | FileInterfaceEnvVolWrite(\r | |
1141 | IN EFI_FILE_PROTOCOL *This,\r | |
1142 | IN OUT UINTN *BufferSize,\r | |
1143 | IN VOID *Buffer\r | |
1144 | )\r | |
1145 | {\r | |
1146 | VOID* NewBuffer;\r | |
1147 | UINTN NewSize;\r | |
1148 | EFI_STATUS Status;\r | |
1149 | \r | |
1150 | NewBuffer = NULL;\r | |
1151 | NewSize = 0;\r | |
1152 | \r | |
1153 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r | |
1154 | if (Status == EFI_BUFFER_TOO_SMALL){\r | |
1155 | NewBuffer = AllocateZeroPool(NewSize + *BufferSize + sizeof(CHAR16));\r | |
1156 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r | |
1157 | }\r | |
1158 | if (!EFI_ERROR(Status) && NewBuffer != NULL) {\r | |
1159 | while (((CHAR16*)NewBuffer)[NewSize/2] == CHAR_NULL) {\r | |
1160 | //\r | |
1161 | // We want to overwrite the CHAR_NULL\r | |
1162 | //\r | |
1163 | NewSize -= 2;\r | |
1164 | }\r | |
1165 | CopyMem((UINT8*)NewBuffer + NewSize + 2, Buffer, *BufferSize);\r | |
1166 | Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r | |
1167 | FreePool(NewBuffer);\r | |
1168 | return (Status);\r | |
1169 | } else {\r | |
1170 | SHELL_FREE_NON_NULL(NewBuffer);\r | |
1171 | return (SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, *BufferSize, Buffer));\r | |
1172 | }\r | |
1173 | }\r | |
1174 | \r | |
1175 | \r | |
1176 | /**\r | |
1177 | File style interface for Non Volatile Environment Variable (Write).\r | |
1178 | \r | |
4ff7e37b ED |
1179 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
1180 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
1181 | @param[in] Buffer The pointer to the buffer to write.\r | |
a405b86d | 1182 | \r |
1183 | @retval EFI_SUCCESS The data was read.\r | |
1184 | **/\r | |
1185 | EFI_STATUS\r | |
1186 | EFIAPI\r | |
1187 | FileInterfaceEnvNonVolWrite(\r | |
1188 | IN EFI_FILE_PROTOCOL *This,\r | |
1189 | IN OUT UINTN *BufferSize,\r | |
1190 | IN VOID *Buffer\r | |
1191 | )\r | |
1192 | {\r | |
1193 | VOID* NewBuffer;\r | |
1194 | UINTN NewSize;\r | |
1195 | EFI_STATUS Status;\r | |
1196 | \r | |
1197 | NewBuffer = NULL;\r | |
1198 | NewSize = 0;\r | |
1199 | \r | |
1200 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r | |
1201 | if (Status == EFI_BUFFER_TOO_SMALL){\r | |
1202 | NewBuffer = AllocateZeroPool(NewSize + *BufferSize);\r | |
1203 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r | |
1204 | }\r | |
1205 | if (!EFI_ERROR(Status)) {\r | |
1206 | CopyMem((UINT8*)NewBuffer + NewSize, Buffer, *BufferSize);\r | |
1207 | return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(\r | |
1208 | ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r | |
1209 | NewSize + *BufferSize,\r | |
1210 | NewBuffer));\r | |
1211 | } else {\r | |
1212 | return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(\r | |
1213 | ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r | |
1214 | *BufferSize,\r | |
1215 | Buffer));\r | |
1216 | }\r | |
1217 | }\r | |
1218 | \r | |
1219 | /**\r | |
1220 | Creates a EFI_FILE_PROTOCOL (almost) object for using to access\r | |
1221 | environment variables through file operations.\r | |
1222 | \r | |
1223 | @param EnvName The name of the Environment Variable to be operated on.\r | |
1224 | \r | |
1225 | @retval NULL Memory could not be allocated.\r | |
1226 | @return other a pointer to an EFI_FILE_PROTOCOL structure\r | |
1227 | **/\r | |
1228 | EFI_FILE_PROTOCOL*\r | |
a405b86d | 1229 | CreateFileInterfaceEnv(\r |
1230 | IN CONST CHAR16 *EnvName\r | |
1231 | )\r | |
1232 | {\r | |
31e5b912 | 1233 | EFI_STATUS Status;\r |
a405b86d | 1234 | EFI_FILE_PROTOCOL_ENVIRONMENT *EnvFileInterface;\r |
323d3d11 | 1235 | UINTN EnvNameSize;\r |
31e5b912 | 1236 | BOOLEAN Volatile;\r |
a405b86d | 1237 | \r |
1238 | if (EnvName == NULL) {\r | |
1239 | return (NULL);\r | |
1240 | }\r | |
1241 | \r | |
31e5b912 RN |
1242 | Status = IsVolatileEnv (EnvName, &Volatile);\r |
1243 | if (EFI_ERROR (Status)) {\r | |
1244 | return NULL;\r | |
1245 | }\r | |
1246 | \r | |
a405b86d | 1247 | //\r |
1248 | // Get some memory\r | |
1249 | //\r | |
323d3d11 QS |
1250 | EnvNameSize = StrSize(EnvName);\r |
1251 | EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+EnvNameSize);\r | |
a405b86d | 1252 | if (EnvFileInterface == NULL){\r |
1253 | return (NULL);\r | |
1254 | }\r | |
1255 | \r | |
1256 | //\r | |
1257 | // Assign the generic members\r | |
1258 | //\r | |
1259 | EnvFileInterface->Revision = EFI_FILE_REVISION;\r | |
1260 | EnvFileInterface->Open = FileInterfaceOpenNotFound;\r | |
1261 | EnvFileInterface->Close = FileInterfaceEnvClose;\r | |
1262 | EnvFileInterface->GetPosition = FileInterfaceNopGetPosition;\r | |
1263 | EnvFileInterface->SetPosition = FileInterfaceNopSetPosition;\r | |
1264 | EnvFileInterface->GetInfo = FileInterfaceNopGetInfo;\r | |
1265 | EnvFileInterface->SetInfo = FileInterfaceNopSetInfo;\r | |
1266 | EnvFileInterface->Flush = FileInterfaceNopGeneric;\r | |
1267 | EnvFileInterface->Delete = FileInterfaceEnvDelete;\r | |
1268 | EnvFileInterface->Read = FileInterfaceEnvRead;\r | |
323d3d11 QS |
1269 | \r |
1270 | CopyMem(EnvFileInterface->Name, EnvName, EnvNameSize);\r | |
a405b86d | 1271 | \r |
1272 | //\r | |
1273 | // Assign the different members for Volatile and Non-Volatile variables\r | |
1274 | //\r | |
31e5b912 | 1275 | if (Volatile) {\r |
a405b86d | 1276 | EnvFileInterface->Write = FileInterfaceEnvVolWrite;\r |
1277 | } else {\r | |
1278 | EnvFileInterface->Write = FileInterfaceEnvNonVolWrite;\r | |
1279 | }\r | |
1280 | return ((EFI_FILE_PROTOCOL *)EnvFileInterface);\r | |
1281 | }\r | |
1282 | \r | |
1283 | /**\r | |
1284 | Move the cursor position one character backward.\r | |
1285 | \r | |
1286 | @param[in] LineLength Length of a line. Get it by calling QueryMode\r | |
4ff7e37b ED |
1287 | @param[in, out] Column Current column of the cursor position\r |
1288 | @param[in, out] Row Current row of the cursor position\r | |
a405b86d | 1289 | **/\r |
1290 | VOID\r | |
a405b86d | 1291 | MoveCursorBackward (\r |
1292 | IN UINTN LineLength,\r | |
1293 | IN OUT UINTN *Column,\r | |
1294 | IN OUT UINTN *Row\r | |
1295 | )\r | |
1296 | {\r | |
1297 | //\r | |
1298 | // If current column is 0, move to the last column of the previous line,\r | |
1299 | // otherwise, just decrement column.\r | |
1300 | //\r | |
1301 | if (*Column == 0) {\r | |
1302 | *Column = LineLength - 1;\r | |
1303 | if (*Row > 0) {\r | |
1304 | (*Row)--;\r | |
1305 | }\r | |
1306 | return;\r | |
1307 | }\r | |
1308 | (*Column)--;\r | |
1309 | }\r | |
1310 | \r | |
1311 | /**\r | |
1312 | Move the cursor position one character forward.\r | |
1313 | \r | |
1314 | @param[in] LineLength Length of a line.\r | |
1315 | @param[in] TotalRow Total row of a screen\r | |
4ff7e37b ED |
1316 | @param[in, out] Column Current column of the cursor position\r |
1317 | @param[in, out] Row Current row of the cursor position\r | |
a405b86d | 1318 | **/\r |
1319 | VOID\r | |
a405b86d | 1320 | MoveCursorForward (\r |
1321 | IN UINTN LineLength,\r | |
1322 | IN UINTN TotalRow,\r | |
1323 | IN OUT UINTN *Column,\r | |
1324 | IN OUT UINTN *Row\r | |
1325 | )\r | |
1326 | {\r | |
1327 | //\r | |
1328 | // Increment Column.\r | |
1329 | // If this puts column past the end of the line, move to first column\r | |
1330 | // of the next row.\r | |
1331 | //\r | |
1332 | (*Column)++;\r | |
1333 | if (*Column >= LineLength) {\r | |
1334 | (*Column) = 0;\r | |
1335 | if ((*Row) < TotalRow - 1) {\r | |
1336 | (*Row)++;\r | |
1337 | }\r | |
1338 | }\r | |
1339 | }\r | |
1340 | \r | |
1341 | /**\r | |
1342 | Prints out each previously typed command in the command list history log.\r | |
1343 | \r | |
1344 | When each screen is full it will pause for a key before continuing.\r | |
1345 | \r | |
1346 | @param[in] TotalCols How many columns are on the screen\r | |
1347 | @param[in] TotalRows How many rows are on the screen\r | |
1348 | @param[in] StartColumn which column to start at\r | |
1349 | **/\r | |
1350 | VOID\r | |
a405b86d | 1351 | PrintCommandHistory (\r |
1352 | IN CONST UINTN TotalCols,\r | |
1353 | IN CONST UINTN TotalRows,\r | |
1354 | IN CONST UINTN StartColumn\r | |
1355 | )\r | |
1356 | {\r | |
1357 | BUFFER_LIST *Node;\r | |
1358 | UINTN Index;\r | |
1359 | UINTN LineNumber;\r | |
1360 | UINTN LineCount;\r | |
1361 | \r | |
1362 | ShellPrintEx (-1, -1, L"\n");\r | |
1363 | Index = 0;\r | |
1364 | LineNumber = 0;\r | |
1365 | //\r | |
1366 | // go through history list...\r | |
1367 | //\r | |
1368 | for ( Node = (BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link)\r | |
1369 | ; !IsNull(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link)\r | |
1370 | ; Node = (BUFFER_LIST*)GetNextNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link)\r | |
1371 | ){\r | |
1372 | Index++;\r | |
1373 | LineCount = ((StrLen (Node->Buffer) + StartColumn + 1) / TotalCols) + 1;\r | |
1374 | \r | |
1375 | if (LineNumber + LineCount >= TotalRows) {\r | |
1376 | ShellPromptForResponseHii(\r | |
1377 | ShellPromptResponseTypeEnterContinue,\r | |
1378 | STRING_TOKEN (STR_SHELL_ENTER_TO_CONT),\r | |
1379 | ShellInfoObject.HiiHandle,\r | |
1380 | NULL\r | |
1381 | );\r | |
1382 | LineNumber = 0;\r | |
1383 | }\r | |
1384 | ShellPrintEx (-1, -1, L"%2d. %s\n", Index, Node->Buffer);\r | |
1385 | LineNumber += LineCount;\r | |
1386 | }\r | |
1387 | }\r | |
1388 | \r | |
1389 | \r | |
1390 | \r | |
1391 | \r | |
1392 | \r | |
1393 | \r | |
1394 | //\r | |
1395 | // This is identical to EFI_FILE_PROTOCOL except for the additional members\r | |
1396 | // for the buffer, size, and position.\r | |
1397 | //\r | |
1398 | \r | |
1399 | typedef struct {\r | |
1400 | UINT64 Revision;\r | |
1401 | EFI_FILE_OPEN Open;\r | |
1402 | EFI_FILE_CLOSE Close;\r | |
1403 | EFI_FILE_DELETE Delete;\r | |
1404 | EFI_FILE_READ Read;\r | |
1405 | EFI_FILE_WRITE Write;\r | |
1406 | EFI_FILE_GET_POSITION GetPosition;\r | |
1407 | EFI_FILE_SET_POSITION SetPosition;\r | |
1408 | EFI_FILE_GET_INFO GetInfo;\r | |
1409 | EFI_FILE_SET_INFO SetInfo;\r | |
1410 | EFI_FILE_FLUSH Flush;\r | |
1411 | VOID *Buffer;\r | |
1412 | UINT64 Position;\r | |
1413 | UINT64 BufferSize;\r | |
1414 | BOOLEAN Unicode;\r | |
7bcd3ff6 | 1415 | UINT64 FileSize;\r |
a405b86d | 1416 | } EFI_FILE_PROTOCOL_MEM;\r |
1417 | \r | |
1418 | /**\r | |
1419 | File style interface for Mem (SetPosition).\r | |
1420 | \r | |
1421 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r | |
1422 | @param[out] Position The position to set.\r | |
1423 | \r | |
1424 | @retval EFI_SUCCESS The position was successfully changed.\r | |
1425 | @retval EFI_INVALID_PARAMETER The Position was invalid.\r | |
1426 | **/\r | |
1427 | EFI_STATUS\r | |
1428 | EFIAPI\r | |
1429 | FileInterfaceMemSetPosition(\r | |
1430 | IN EFI_FILE_PROTOCOL *This,\r | |
1431 | OUT UINT64 Position\r | |
1432 | )\r | |
1433 | {\r | |
7bcd3ff6 | 1434 | if (Position <= ((EFI_FILE_PROTOCOL_MEM*)This)->FileSize) {\r |
a405b86d | 1435 | ((EFI_FILE_PROTOCOL_MEM*)This)->Position = Position;\r |
1436 | return (EFI_SUCCESS);\r | |
1437 | } else {\r | |
1438 | return (EFI_INVALID_PARAMETER);\r | |
1439 | }\r | |
1440 | }\r | |
1441 | \r | |
1442 | /**\r | |
1443 | File style interface for Mem (GetPosition).\r | |
1444 | \r | |
1445 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r | |
1446 | @param[out] Position The pointer to the position.\r | |
1447 | \r | |
1448 | @retval EFI_SUCCESS The position was retrieved.\r | |
1449 | **/ \r | |
1450 | EFI_STATUS\r | |
1451 | EFIAPI\r | |
1452 | FileInterfaceMemGetPosition(\r | |
1453 | IN EFI_FILE_PROTOCOL *This,\r | |
1454 | OUT UINT64 *Position\r | |
1455 | )\r | |
1456 | {\r | |
1457 | *Position = ((EFI_FILE_PROTOCOL_MEM*)This)->Position;\r | |
1458 | return (EFI_SUCCESS);\r | |
1459 | }\r | |
1460 | \r | |
1461 | /**\r | |
1462 | File style interface for Mem (Write).\r | |
1463 | \r | |
4ff7e37b ED |
1464 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
1465 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
1466 | @param[in] Buffer The pointer to the buffer to write.\r | |
a405b86d | 1467 | \r |
ecae5117 | 1468 | @retval EFI_OUT_OF_RESOURCES The operation failed due to lack of resources.\r |
1469 | @retval EFI_SUCCESS The data was written.\r | |
a405b86d | 1470 | **/\r |
1471 | EFI_STATUS\r | |
1472 | EFIAPI\r | |
1473 | FileInterfaceMemWrite(\r | |
1474 | IN EFI_FILE_PROTOCOL *This,\r | |
1475 | IN OUT UINTN *BufferSize,\r | |
1476 | IN VOID *Buffer\r | |
1477 | )\r | |
1478 | {\r | |
9ed21946 | 1479 | CHAR8 *AsciiBuffer;\r |
1480 | EFI_FILE_PROTOCOL_MEM *MemFile;\r | |
1481 | \r | |
1482 | MemFile = (EFI_FILE_PROTOCOL_MEM *) This;\r | |
1483 | if (MemFile->Unicode) {\r | |
a405b86d | 1484 | //\r |
1485 | // Unicode\r | |
1486 | //\r | |
9ed21946 | 1487 | if ((UINTN)(MemFile->Position + (*BufferSize)) > (UINTN)(MemFile->BufferSize)) {\r |
c8d9d0e2 JD |
1488 | MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize), (UINTN)(MemFile->BufferSize) + (*BufferSize) + MEM_WRITE_REALLOC_OVERHEAD, MemFile->Buffer);\r |
1489 | MemFile->BufferSize += (*BufferSize) + MEM_WRITE_REALLOC_OVERHEAD;\r | |
a405b86d | 1490 | }\r |
9ed21946 | 1491 | CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer, *BufferSize);\r |
1492 | MemFile->Position += (*BufferSize);\r | |
7bcd3ff6 | 1493 | MemFile->FileSize = MemFile->Position;\r |
a405b86d | 1494 | return (EFI_SUCCESS);\r |
1495 | } else {\r | |
1496 | //\r | |
1497 | // Ascii\r | |
1498 | //\r | |
733f138d | 1499 | AsciiBuffer = AllocateZeroPool(*BufferSize);\r |
ecae5117 | 1500 | if (AsciiBuffer == NULL) {\r |
1501 | return (EFI_OUT_OF_RESOURCES);\r | |
1502 | }\r | |
a405b86d | 1503 | AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer);\r |
9ed21946 | 1504 | if ((UINTN)(MemFile->Position + AsciiStrSize(AsciiBuffer)) > (UINTN)(MemFile->BufferSize)) {\r |
c8d9d0e2 JD |
1505 | MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize), (UINTN)(MemFile->BufferSize) + AsciiStrSize(AsciiBuffer) + MEM_WRITE_REALLOC_OVERHEAD, MemFile->Buffer);\r |
1506 | MemFile->BufferSize += AsciiStrSize(AsciiBuffer) + MEM_WRITE_REALLOC_OVERHEAD;\r | |
a405b86d | 1507 | }\r |
9ed21946 | 1508 | CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer, AsciiStrSize(AsciiBuffer));\r |
1509 | MemFile->Position += (*BufferSize / sizeof(CHAR16));\r | |
7bcd3ff6 | 1510 | MemFile->FileSize = MemFile->Position;\r |
a405b86d | 1511 | FreePool(AsciiBuffer);\r |
1512 | return (EFI_SUCCESS);\r | |
1513 | }\r | |
1514 | }\r | |
1515 | \r | |
1516 | /**\r | |
1517 | File style interface for Mem (Read).\r | |
1518 | \r | |
4ff7e37b ED |
1519 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
1520 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
1521 | @param[in] Buffer The pointer to the buffer to fill.\r | |
a405b86d | 1522 | \r |
1523 | @retval EFI_SUCCESS The data was read.\r | |
1524 | **/\r | |
1525 | EFI_STATUS\r | |
1526 | EFIAPI\r | |
1527 | FileInterfaceMemRead(\r | |
1528 | IN EFI_FILE_PROTOCOL *This,\r | |
1529 | IN OUT UINTN *BufferSize,\r | |
1530 | IN VOID *Buffer\r | |
1531 | )\r | |
1532 | {\r | |
9ed21946 | 1533 | EFI_FILE_PROTOCOL_MEM *MemFile;\r |
1534 | \r | |
1535 | MemFile = (EFI_FILE_PROTOCOL_MEM *) This;\r | |
7bcd3ff6 JD |
1536 | if (*BufferSize > (UINTN)((MemFile->FileSize) - (UINTN)(MemFile->Position))) {\r |
1537 | (*BufferSize) = (UINTN)((MemFile->FileSize) - (UINTN)(MemFile->Position));\r | |
a405b86d | 1538 | }\r |
9ed21946 | 1539 | CopyMem(Buffer, ((UINT8*)MemFile->Buffer) + MemFile->Position, (*BufferSize));\r |
1540 | MemFile->Position = MemFile->Position + (*BufferSize);\r | |
a405b86d | 1541 | return (EFI_SUCCESS);\r |
1542 | }\r | |
1543 | \r | |
1544 | /**\r | |
1545 | File style interface for Mem (Close).\r | |
1546 | \r | |
1547 | Frees all memory associated with this object.\r | |
1548 | \r | |
1549 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r | |
1550 | \r | |
1551 | @retval EFI_SUCCESS The 'file' was closed.\r | |
1552 | **/ \r | |
1553 | EFI_STATUS\r | |
1554 | EFIAPI\r | |
1555 | FileInterfaceMemClose(\r | |
1556 | IN EFI_FILE_PROTOCOL *This\r | |
1557 | )\r | |
1558 | {\r | |
1559 | SHELL_FREE_NON_NULL(((EFI_FILE_PROTOCOL_MEM*)This)->Buffer);\r | |
3c865f20 | 1560 | SHELL_FREE_NON_NULL(This);\r |
a405b86d | 1561 | return (EFI_SUCCESS);\r |
1562 | }\r | |
1563 | \r | |
1564 | /**\r | |
1565 | Creates a EFI_FILE_PROTOCOL (almost) object for using to access\r | |
1566 | a file entirely in memory through file operations.\r | |
1567 | \r | |
1568 | @param[in] Unicode Boolean value with TRUE for Unicode and FALSE for Ascii.\r | |
1569 | \r | |
1570 | @retval NULL Memory could not be allocated.\r | |
1571 | @return other A pointer to an EFI_FILE_PROTOCOL structure.\r | |
1572 | **/\r | |
1573 | EFI_FILE_PROTOCOL*\r | |
a405b86d | 1574 | CreateFileInterfaceMem(\r |
1575 | IN CONST BOOLEAN Unicode\r | |
1576 | )\r | |
1577 | {\r | |
1578 | EFI_FILE_PROTOCOL_MEM *FileInterface;\r | |
1579 | \r | |
1580 | //\r | |
1581 | // Get some memory\r | |
1582 | //\r | |
1583 | FileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_MEM));\r | |
1584 | if (FileInterface == NULL){\r | |
1585 | return (NULL);\r | |
1586 | }\r | |
1587 | \r | |
1588 | //\r | |
1589 | // Assign the generic members\r | |
1590 | //\r | |
1591 | FileInterface->Revision = EFI_FILE_REVISION;\r | |
1592 | FileInterface->Open = FileInterfaceOpenNotFound;\r | |
1593 | FileInterface->Close = FileInterfaceMemClose;\r | |
1594 | FileInterface->GetPosition = FileInterfaceMemGetPosition;\r | |
1595 | FileInterface->SetPosition = FileInterfaceMemSetPosition;\r | |
1596 | FileInterface->GetInfo = FileInterfaceNopGetInfo;\r | |
1597 | FileInterface->SetInfo = FileInterfaceNopSetInfo;\r | |
1598 | FileInterface->Flush = FileInterfaceNopGeneric;\r | |
1599 | FileInterface->Delete = FileInterfaceNopGeneric;\r | |
1600 | FileInterface->Read = FileInterfaceMemRead;\r | |
1601 | FileInterface->Write = FileInterfaceMemWrite;\r | |
1602 | FileInterface->Unicode = Unicode;\r | |
1603 | \r | |
1604 | ASSERT(FileInterface->Buffer == NULL);\r | |
1605 | ASSERT(FileInterface->BufferSize == 0);\r | |
1606 | ASSERT(FileInterface->Position == 0);\r | |
1607 | \r | |
9ed21946 | 1608 | if (Unicode) {\r |
1609 | FileInterface->Buffer = AllocateZeroPool(sizeof(gUnicodeFileTag));\r | |
9eec4d38 QS |
1610 | if (FileInterface->Buffer == NULL) {\r |
1611 | FreePool (FileInterface);\r | |
1612 | return NULL;\r | |
1613 | }\r | |
9ed21946 | 1614 | *((CHAR16 *) (FileInterface->Buffer)) = EFI_UNICODE_BYTE_ORDER_MARK;\r |
1615 | FileInterface->BufferSize = 2;\r | |
1616 | FileInterface->Position = 2;\r | |
1617 | }\r | |
1618 | \r | |
a405b86d | 1619 | return ((EFI_FILE_PROTOCOL *)FileInterface);\r |
1620 | }\r | |
1621 | \r | |
1622 | typedef struct {\r | |
1623 | UINT64 Revision;\r | |
1624 | EFI_FILE_OPEN Open;\r | |
1625 | EFI_FILE_CLOSE Close;\r | |
1626 | EFI_FILE_DELETE Delete;\r | |
1627 | EFI_FILE_READ Read;\r | |
1628 | EFI_FILE_WRITE Write;\r | |
1629 | EFI_FILE_GET_POSITION GetPosition;\r | |
1630 | EFI_FILE_SET_POSITION SetPosition;\r | |
1631 | EFI_FILE_GET_INFO GetInfo;\r | |
1632 | EFI_FILE_SET_INFO SetInfo;\r | |
1633 | EFI_FILE_FLUSH Flush;\r | |
1634 | BOOLEAN Unicode;\r | |
1635 | EFI_FILE_PROTOCOL *Orig;\r | |
1636 | } EFI_FILE_PROTOCOL_FILE;\r | |
1637 | \r | |
733f138d | 1638 | /**\r |
1639 | Set a files current position\r | |
1640 | \r | |
1641 | @param This Protocol instance pointer.\r | |
1642 | @param Position Byte position from the start of the file.\r | |
1643 | \r | |
1644 | @retval EFI_SUCCESS Data was written.\r | |
1645 | @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.\r | |
1646 | \r | |
1647 | **/\r | |
1648 | EFI_STATUS\r | |
1649 | EFIAPI\r | |
1650 | FileInterfaceFileSetPosition(\r | |
1651 | IN EFI_FILE_PROTOCOL *This,\r | |
1652 | IN UINT64 Position\r | |
1653 | )\r | |
1654 | {\r | |
1655 | return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->SetPosition(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, Position);\r | |
1656 | }\r | |
1657 | \r | |
1658 | /**\r | |
1659 | Get a file's current position\r | |
1660 | \r | |
1661 | @param This Protocol instance pointer.\r | |
1662 | @param Position Byte position from the start of the file.\r | |
1663 | \r | |
1664 | @retval EFI_SUCCESS Data was written.\r | |
1665 | @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..\r | |
1666 | \r | |
1667 | **/\r | |
1668 | EFI_STATUS\r | |
1669 | EFIAPI\r | |
1670 | FileInterfaceFileGetPosition(\r | |
1671 | IN EFI_FILE_PROTOCOL *This,\r | |
1672 | OUT UINT64 *Position\r | |
1673 | )\r | |
1674 | {\r | |
1675 | return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->GetPosition(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, Position);\r | |
1676 | }\r | |
1677 | \r | |
1678 | /**\r | |
1679 | Get information about a file.\r | |
1680 | \r | |
1681 | @param This Protocol instance pointer.\r | |
1682 | @param InformationType Type of information to return in Buffer.\r | |
1683 | @param BufferSize On input size of buffer, on output amount of data in buffer.\r | |
1684 | @param Buffer The buffer to return data.\r | |
1685 | \r | |
1686 | @retval EFI_SUCCESS Data was returned.\r | |
1687 | @retval EFI_UNSUPPORT InformationType is not supported.\r | |
1688 | @retval EFI_NO_MEDIA The device has no media.\r | |
1689 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
1690 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
1691 | @retval EFI_WRITE_PROTECTED The device is write protected.\r | |
1692 | @retval EFI_ACCESS_DENIED The file was open for read only.\r | |
1693 | @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.\r | |
1694 | \r | |
1695 | **/\r | |
1696 | EFI_STATUS\r | |
1697 | EFIAPI\r | |
1698 | FileInterfaceFileGetInfo(\r | |
1699 | IN EFI_FILE_PROTOCOL *This,\r | |
1700 | IN EFI_GUID *InformationType,\r | |
1701 | IN OUT UINTN *BufferSize,\r | |
1702 | OUT VOID *Buffer\r | |
1703 | )\r | |
1704 | {\r | |
1705 | return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->GetInfo(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, InformationType, BufferSize, Buffer);\r | |
1706 | }\r | |
1707 | \r | |
1708 | /**\r | |
1709 | Set information about a file\r | |
1710 | \r | |
ae724571 | 1711 | @param This Protocol instance pointer.\r |
733f138d | 1712 | @param InformationType Type of information in Buffer.\r |
1713 | @param BufferSize Size of buffer.\r | |
1714 | @param Buffer The data to write.\r | |
1715 | \r | |
1716 | @retval EFI_SUCCESS Data was returned.\r | |
1717 | @retval EFI_UNSUPPORT InformationType is not supported.\r | |
1718 | @retval EFI_NO_MEDIA The device has no media.\r | |
1719 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
1720 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
1721 | @retval EFI_WRITE_PROTECTED The device is write protected.\r | |
1722 | @retval EFI_ACCESS_DENIED The file was open for read only.\r | |
1723 | \r | |
1724 | **/\r | |
1725 | EFI_STATUS\r | |
1726 | EFIAPI\r | |
1727 | FileInterfaceFileSetInfo(\r | |
1728 | IN EFI_FILE_PROTOCOL *This,\r | |
1729 | IN EFI_GUID *InformationType,\r | |
1730 | IN UINTN BufferSize,\r | |
1731 | IN VOID *Buffer\r | |
1732 | )\r | |
1733 | {\r | |
1734 | return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->SetInfo(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, InformationType, BufferSize, Buffer);\r | |
1735 | }\r | |
1736 | \r | |
1737 | /**\r | |
1738 | Flush data back for the file handle.\r | |
1739 | \r | |
1740 | @param This Protocol instance pointer.\r | |
1741 | \r | |
1742 | @retval EFI_SUCCESS Data was written.\r | |
1743 | @retval EFI_UNSUPPORT Writes to Open directory are not supported.\r | |
1744 | @retval EFI_NO_MEDIA The device has no media.\r | |
1745 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
1746 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
1747 | @retval EFI_WRITE_PROTECTED The device is write protected.\r | |
1748 | @retval EFI_ACCESS_DENIED The file was open for read only.\r | |
1749 | @retval EFI_VOLUME_FULL The volume is full.\r | |
1750 | \r | |
1751 | **/\r | |
1752 | EFI_STATUS\r | |
1753 | EFIAPI\r | |
1754 | FileInterfaceFileFlush(\r | |
1755 | IN EFI_FILE_PROTOCOL *This\r | |
1756 | )\r | |
1757 | {\r | |
1758 | return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Flush(((EFI_FILE_PROTOCOL_FILE*)This)->Orig);\r | |
1759 | }\r | |
1760 | \r | |
1761 | /**\r | |
1762 | Read data from the file.\r | |
1763 | \r | |
1764 | @param This Protocol instance pointer.\r | |
1765 | @param BufferSize On input size of buffer, on output amount of data in buffer.\r | |
1766 | @param Buffer The buffer in which data is read.\r | |
1767 | \r | |
1768 | @retval EFI_SUCCESS Data was read.\r | |
1769 | @retval EFI_NO_MEDIA The device has no media.\r | |
1770 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
1771 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
1772 | @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.\r | |
1773 | \r | |
1774 | **/\r | |
1775 | EFI_STATUS\r | |
1776 | EFIAPI\r | |
1777 | FileInterfaceFileRead(\r | |
1778 | IN EFI_FILE_PROTOCOL *This,\r | |
1779 | IN OUT UINTN *BufferSize,\r | |
1780 | OUT VOID *Buffer\r | |
1781 | )\r | |
1782 | {\r | |
48cb33ec QS |
1783 | CHAR8 *AsciiStrBuffer;\r |
1784 | CHAR16 *UscStrBuffer;\r | |
733f138d | 1785 | UINTN Size;\r |
48cb33ec | 1786 | UINTN CharNum;\r |
733f138d | 1787 | EFI_STATUS Status;\r |
1788 | if (((EFI_FILE_PROTOCOL_FILE*)This)->Unicode) {\r | |
1789 | //\r | |
1790 | // Unicode\r | |
1791 | //\r | |
1792 | return (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, BufferSize, Buffer));\r | |
1793 | } else {\r | |
1794 | //\r | |
1795 | // Ascii\r | |
1796 | //\r | |
48cb33ec QS |
1797 | Size = (*BufferSize) / sizeof(CHAR16);\r |
1798 | AsciiStrBuffer = AllocateZeroPool(Size + sizeof(CHAR8));\r | |
1799 | if (AsciiStrBuffer == NULL) {\r | |
1800 | return EFI_OUT_OF_RESOURCES;\r | |
1801 | }\r | |
1802 | UscStrBuffer = AllocateZeroPool(*BufferSize + sizeof(CHAR16));\r | |
1803 | if (UscStrBuffer== NULL) {\r | |
1804 | SHELL_FREE_NON_NULL(AsciiStrBuffer);\r | |
1805 | return EFI_OUT_OF_RESOURCES;\r | |
1806 | }\r | |
1807 | Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiStrBuffer));\r | |
1808 | if (!EFI_ERROR(Status)) {\r | |
1809 | CharNum = UnicodeSPrint(UscStrBuffer, *BufferSize + sizeof(CHAR16), L"%a", AsciiStrBuffer);\r | |
1810 | if (CharNum == Size) {\r | |
1811 | CopyMem (Buffer, UscStrBuffer, *BufferSize);\r | |
1812 | } else {\r | |
1813 | Status = EFI_UNSUPPORTED;\r | |
1814 | }\r | |
1815 | }\r | |
1816 | SHELL_FREE_NON_NULL(AsciiStrBuffer);\r | |
1817 | SHELL_FREE_NON_NULL(UscStrBuffer);\r | |
733f138d | 1818 | return (Status);\r |
1819 | }\r | |
1820 | }\r | |
1821 | \r | |
1822 | /**\r | |
1823 | Opens a new file relative to the source file's location.\r | |
1824 | \r | |
1825 | @param[in] This The protocol instance pointer.\r | |
1826 | @param[out] NewHandle Returns File Handle for FileName.\r | |
1827 | @param[in] FileName Null terminated string. "\", ".", and ".." are supported.\r | |
1828 | @param[in] OpenMode Open mode for file.\r | |
1829 | @param[in] Attributes Only used for EFI_FILE_MODE_CREATE.\r | |
1830 | \r | |
1831 | @retval EFI_SUCCESS The device was opened.\r | |
1832 | @retval EFI_NOT_FOUND The specified file could not be found on the device.\r | |
1833 | @retval EFI_NO_MEDIA The device has no media.\r | |
1834 | @retval EFI_MEDIA_CHANGED The media has changed.\r | |
1835 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
1836 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
1837 | @retval EFI_ACCESS_DENIED The service denied access to the file.\r | |
1838 | @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r | |
1839 | @retval EFI_VOLUME_FULL The volume is full.\r | |
1840 | **/\r | |
1841 | EFI_STATUS\r | |
1842 | EFIAPI\r | |
1843 | FileInterfaceFileOpen (\r | |
1844 | IN EFI_FILE_PROTOCOL *This,\r | |
1845 | OUT EFI_FILE_PROTOCOL **NewHandle,\r | |
1846 | IN CHAR16 *FileName,\r | |
1847 | IN UINT64 OpenMode,\r | |
1848 | IN UINT64 Attributes\r | |
1849 | )\r | |
1850 | {\r | |
1851 | return ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Open(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, NewHandle, FileName, OpenMode, Attributes);\r | |
1852 | }\r | |
1853 | \r | |
1854 | /**\r | |
1855 | Close and delete the file handle.\r | |
1856 | \r | |
1857 | @param This Protocol instance pointer.\r | |
1858 | \r | |
1859 | @retval EFI_SUCCESS The device was opened.\r | |
1860 | @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.\r | |
1861 | \r | |
1862 | **/\r | |
1863 | EFI_STATUS\r | |
1864 | EFIAPI\r | |
1865 | FileInterfaceFileDelete(\r | |
1866 | IN EFI_FILE_PROTOCOL *This\r | |
1867 | )\r | |
1868 | {\r | |
1869 | EFI_STATUS Status;\r | |
1870 | Status = ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Delete(((EFI_FILE_PROTOCOL_FILE*)This)->Orig);\r | |
1871 | FreePool(This);\r | |
1872 | return (Status);\r | |
1873 | }\r | |
1874 | \r | |
a405b86d | 1875 | /**\r |
1876 | File style interface for File (Close).\r | |
1877 | \r | |
1878 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r | |
1879 | \r | |
1880 | @retval EFI_SUCCESS The file was closed.\r | |
1881 | **/\r | |
1882 | EFI_STATUS\r | |
1883 | EFIAPI\r | |
1884 | FileInterfaceFileClose(\r | |
1885 | IN EFI_FILE_PROTOCOL *This\r | |
1886 | )\r | |
1887 | {\r | |
733f138d | 1888 | EFI_STATUS Status;\r |
1889 | Status = ((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Close(((EFI_FILE_PROTOCOL_FILE*)This)->Orig);\r | |
a405b86d | 1890 | FreePool(This);\r |
733f138d | 1891 | return (Status);\r |
a405b86d | 1892 | }\r |
1893 | \r | |
1894 | /**\r | |
1895 | File style interface for File (Write).\r | |
1896 | \r | |
1897 | If the file was opened with ASCII mode the data will be processed through \r | |
1898 | AsciiSPrint before writing.\r | |
1899 | \r | |
4ff7e37b ED |
1900 | @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r |
1901 | @param[in, out] BufferSize Size in bytes of Buffer.\r | |
1902 | @param[in] Buffer The pointer to the buffer to write.\r | |
a405b86d | 1903 | \r |
1904 | @retval EFI_SUCCESS The data was written.\r | |
1905 | **/\r | |
1906 | EFI_STATUS\r | |
1907 | EFIAPI\r | |
1908 | FileInterfaceFileWrite(\r | |
733f138d | 1909 | IN EFI_FILE_PROTOCOL *This,\r |
1910 | IN OUT UINTN *BufferSize,\r | |
1911 | IN VOID *Buffer\r | |
a405b86d | 1912 | )\r |
1913 | {\r | |
1914 | CHAR8 *AsciiBuffer;\r | |
1915 | UINTN Size;\r | |
1916 | EFI_STATUS Status;\r | |
1917 | if (((EFI_FILE_PROTOCOL_FILE*)This)->Unicode) {\r | |
1918 | //\r | |
1919 | // Unicode\r | |
1920 | //\r | |
1921 | return (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Write(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, BufferSize, Buffer));\r | |
1922 | } else {\r | |
1923 | //\r | |
1924 | // Ascii\r | |
1925 | //\r | |
733f138d | 1926 | AsciiBuffer = AllocateZeroPool(*BufferSize);\r |
a405b86d | 1927 | AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer);\r |
1928 | Size = AsciiStrSize(AsciiBuffer) - 1; // (we dont need the null terminator)\r | |
1929 | Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Write(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiBuffer));\r | |
1930 | FreePool(AsciiBuffer);\r | |
1931 | return (Status);\r | |
1932 | }\r | |
1933 | }\r | |
1934 | \r | |
1935 | /**\r | |
1936 | Create a file interface with unicode information.\r | |
1937 | \r | |
1938 | This will create a new EFI_FILE_PROTOCOL identical to the Templace\r | |
1939 | except that the new one has Unicode and Ascii knowledge.\r | |
1940 | \r | |
1941 | @param[in] Template A pointer to the EFI_FILE_PROTOCOL object.\r | |
1942 | @param[in] Unicode TRUE for UCS-2, FALSE for ASCII.\r | |
1943 | \r | |
1944 | @return a new EFI_FILE_PROTOCOL object to be used instead of the template.\r | |
1945 | **/\r | |
1946 | EFI_FILE_PROTOCOL*\r | |
1947 | CreateFileInterfaceFile(\r | |
1948 | IN CONST EFI_FILE_PROTOCOL *Template,\r | |
1949 | IN CONST BOOLEAN Unicode\r | |
1950 | )\r | |
1951 | {\r | |
1952 | EFI_FILE_PROTOCOL_FILE *NewOne;\r | |
1953 | \r | |
733f138d | 1954 | NewOne = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_FILE));\r |
3c865f20 | 1955 | if (NewOne == NULL) {\r |
1956 | return (NULL);\r | |
1957 | }\r | |
a405b86d | 1958 | CopyMem(NewOne, Template, sizeof(EFI_FILE_PROTOCOL_FILE));\r |
733f138d | 1959 | NewOne->Orig = (EFI_FILE_PROTOCOL *)Template;\r |
1960 | NewOne->Unicode = Unicode;\r | |
1961 | NewOne->Open = FileInterfaceFileOpen;\r | |
1962 | NewOne->Close = FileInterfaceFileClose;\r | |
1963 | NewOne->Delete = FileInterfaceFileDelete;\r | |
1964 | NewOne->Read = FileInterfaceFileRead;\r | |
1965 | NewOne->Write = FileInterfaceFileWrite;\r | |
1966 | NewOne->GetPosition = FileInterfaceFileGetPosition;\r | |
1967 | NewOne->SetPosition = FileInterfaceFileSetPosition;\r | |
1968 | NewOne->GetInfo = FileInterfaceFileGetInfo;\r | |
1969 | NewOne->SetInfo = FileInterfaceFileSetInfo;\r | |
1970 | NewOne->Flush = FileInterfaceFileFlush;\r | |
a405b86d | 1971 | \r |
1972 | return ((EFI_FILE_PROTOCOL *)NewOne);\r | |
1973 | }\r |