]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Include/Library/ShellLib.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Include / Library / ShellLib.h
CommitLineData
94b17fa1 1/** @file\r
2 Provides interface to shell functionality for shell commands and applications.\r
3\r
ba0014b9 4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9ba404d6 5 Copyright 2018 Dell Technologies.<BR>\r
56ba3746 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
94b17fa1 7\r
8**/\r
9\r
a405b86d 10#ifndef __SHELL_LIB__\r
94b17fa1 11#define __SHELL_LIB__\r
12\r
b3011f40 13#include <Uefi.h>\r
14#include <Guid/FileInfo.h>\r
94b17fa1 15#include <Protocol/SimpleFileSystem.h>\r
b3011f40 16#include <Protocol/LoadedImage.h>\r
17#include <Protocol/EfiShellInterface.h>\r
18#include <Protocol/EfiShellEnvironment2.h>\r
28165f24
RN
19#include <Protocol/Shell.h>\r
20#include <Protocol/ShellParameters.h>\r
94b17fa1 21\r
c6377bfa
RN
22#define SHELL_FREE_NON_NULL(Pointer) \\r
23 do { \\r
24 if ((Pointer) != NULL) { \\r
25 FreePool((Pointer)); \\r
26 (Pointer) = NULL; \\r
27 } \\r
28 } while(FALSE)\r
29\r
47d20b54
MK
30extern EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;\r
31extern EFI_SHELL_PROTOCOL *gEfiShellProtocol;\r
a405b86d 32\r
9ba404d6
JD
33/**\r
34 Return a clean, fully-qualified version of an input path. If the return value\r
35 is non-NULL the caller must free the memory when it is no longer needed.\r
36\r
37 If asserts are disabled, and if the input parameter is NULL, NULL is returned.\r
38\r
39 If there is not enough memory available to create the fully-qualified path or\r
40 a copy of the input path, NULL is returned.\r
41\r
42 If there is no working directory, a clean copy of Path is returned.\r
43\r
44 Otherwise, the current file system or working directory (as appropriate) is\r
45 prepended to Path and the resulting path is cleaned and returned.\r
46\r
47 NOTE: If the input path is an empty string, then the current working directory\r
48 (if it exists) is returned. In other words, an empty input path is treated\r
49 exactly the same as ".".\r
50\r
51 @param[in] Path A pointer to some file or directory path.\r
52\r
53 @retval NULL The input path is NULL or out of memory.\r
54\r
55 @retval non-NULL A pointer to a clean, fully-qualified version of Path.\r
56 If there is no working directory, then a pointer to a\r
57 clean, but not necessarily fully-qualified version of\r
58 Path. The caller must free this memory when it is no\r
59 longer needed.\r
60**/\r
47d20b54 61CHAR16 *\r
9ba404d6 62EFIAPI\r
47d20b54
MK
63FullyQualifyPath (\r
64 IN CONST CHAR16 *Path\r
9ba404d6
JD
65 );\r
66\r
94b17fa1 67/**\r
1e6e84c7 68 This function will retrieve the information about the file for the handle\r
94b17fa1 69 specified and store it in allocated pool memory.\r
70\r
1e6e84c7 71 This function allocates a buffer to store the file's information. It is the\r
18cefebe 72 caller's responsibility to free the buffer.\r
94b17fa1 73\r
1e6e84c7 74 @param[in] FileHandle The file handle of the file for which information is\r
18cefebe 75 being requested.\r
94b17fa1 76\r
18cefebe 77 @retval NULL Information could not be retrieved.\r
94b17fa1 78\r
18cefebe 79 @return The information about the file.\r
94b17fa1 80**/\r
47d20b54 81EFI_FILE_INFO *\r
94b17fa1 82EFIAPI\r
83ShellGetFileInfo (\r
47d20b54 84 IN SHELL_FILE_HANDLE FileHandle\r
94b17fa1 85 );\r
86\r
87/**\r
a405b86d 88 This function sets the information about the file for the opened handle\r
94b17fa1 89 specified.\r
90\r
1e6e84c7 91 @param[in] FileHandle The file handle of the file for which information\r
a5bd42b9 92 is being set.\r
94b17fa1 93\r
a405b86d 94 @param[in] FileInfo The information to set.\r
94b17fa1 95\r
b0934ac4 96 @retval EFI_SUCCESS The information was set.\r
a405b86d 97 @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
98 @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.\r
b0934ac4 99 @retval EFI_NO_MEDIA The device has no medium.\r
100 @retval EFI_DEVICE_ERROR The device reported an error.\r
101 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
102 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
a405b86d 103 @retval EFI_ACCESS_DENIED The file was opened read only.\r
104 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 105**/\r
106EFI_STATUS\r
107EFIAPI\r
108ShellSetFileInfo (\r
47d20b54
MK
109 IN SHELL_FILE_HANDLE FileHandle,\r
110 IN EFI_FILE_INFO *FileInfo\r
94b17fa1 111 );\r
112\r
113/**\r
114 This function will open a file or directory referenced by DevicePath.\r
115\r
1e6e84c7 116 This function opens a file with the open mode according to the file path. The\r
94b17fa1 117 Attributes is valid only for EFI_FILE_MODE_CREATE.\r
118\r
4ff7e37b
ED
119 @param[in, out] FilePath On input, the device path to the file. On output,\r
120 the remaining device path.\r
4ff7e37b
ED
121 @param[out] FileHandle Pointer to the file handle.\r
122 @param[in] OpenMode The mode to open the file with.\r
123 @param[in] Attributes The file's file attributes.\r
94b17fa1 124\r
b0934ac4 125 @retval EFI_SUCCESS The information was set.\r
126 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
a405b86d 127 @retval EFI_UNSUPPORTED Could not open the file path.\r
b0934ac4 128 @retval EFI_NOT_FOUND The specified file could not be found on the\r
1e6e84c7 129 device or the file system could not be found on\r
94b17fa1 130 the device.\r
a405b86d 131 @retval EFI_NO_MEDIA The device has no medium.\r
132 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the\r
94b17fa1 133 medium is no longer supported.\r
a405b86d 134 @retval EFI_DEVICE_ERROR The device reported an error.\r
b0934ac4 135 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
a405b86d 136 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
137 @retval EFI_ACCESS_DENIED The file was opened read only.\r
b0934ac4 138 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
94b17fa1 139 file.\r
a405b86d 140 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 141**/\r
142EFI_STATUS\r
143EFIAPI\r
47d20b54
MK
144ShellOpenFileByDevicePath (\r
145 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
146 OUT SHELL_FILE_HANDLE *FileHandle,\r
147 IN UINT64 OpenMode,\r
148 IN UINT64 Attributes\r
94b17fa1 149 );\r
150\r
151/**\r
152 This function will open a file or directory referenced by filename.\r
153\r
1e6e84c7 154 If return is EFI_SUCCESS, the Filehandle is the opened file's handle;\r
a405b86d 155 otherwise, the Filehandle is NULL. Attributes is valid only for\r
94b17fa1 156 EFI_FILE_MODE_CREATE.\r
157\r
43b1be74 158 @param[in] FileName The pointer to file name.\r
a405b86d 159 @param[out] FileHandle The pointer to the file handle.\r
160 @param[in] OpenMode The mode to open the file with.\r
161 @param[in] Attributes The file's file attributes.\r
94b17fa1 162\r
b0934ac4 163 @retval EFI_SUCCESS The information was set.\r
164 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
a405b86d 165 @retval EFI_UNSUPPORTED Could not open the file path.\r
b0934ac4 166 @retval EFI_NOT_FOUND The specified file could not be found on the\r
1e6e84c7 167 device or the file system could not be found\r
94b17fa1 168 on the device.\r
a405b86d 169 @retval EFI_NO_MEDIA The device has no medium.\r
170 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the\r
94b17fa1 171 medium is no longer supported.\r
a405b86d 172 @retval EFI_DEVICE_ERROR The device reported an error.\r
b0934ac4 173 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
a405b86d 174 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
175 @retval EFI_ACCESS_DENIED The file was opened read only.\r
b0934ac4 176 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
94b17fa1 177 file.\r
a405b86d 178 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 179**/\r
180EFI_STATUS\r
181EFIAPI\r
47d20b54
MK
182ShellOpenFileByName (\r
183 IN CONST CHAR16 *FileName,\r
184 OUT SHELL_FILE_HANDLE *FileHandle,\r
185 IN UINT64 OpenMode,\r
186 IN UINT64 Attributes\r
94b17fa1 187 );\r
188\r
189/**\r
18cefebe 190 This function creates a directory.\r
94b17fa1 191\r
1e6e84c7 192 If return is EFI_SUCCESS, the Filehandle is the opened directory's handle;\r
193 otherwise, the Filehandle is NULL. If the directory already existed, this\r
94b17fa1 194 function opens the existing directory.\r
195\r
a405b86d 196 @param[in] DirectoryName The pointer to Directory name.\r
197 @param[out] FileHandle The pointer to the file handle.\r
94b17fa1 198\r
b0934ac4 199 @retval EFI_SUCCESS The information was set.\r
200 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
a405b86d 201 @retval EFI_UNSUPPORTED Could not open the file path.\r
b0934ac4 202 @retval EFI_NOT_FOUND The specified file could not be found on the\r
a405b86d 203 device, or the file system could not be found\r
94b17fa1 204 on the device.\r
a405b86d 205 @retval EFI_NO_MEDIA The device has no medium.\r
206 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the\r
94b17fa1 207 medium is no longer supported.\r
a405b86d 208 @retval EFI_DEVICE_ERROR The device reported an error.\r
b0934ac4 209 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
a405b86d 210 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
211 @retval EFI_ACCESS_DENIED The file was opened read only.\r
b0934ac4 212 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
94b17fa1 213 file.\r
a405b86d 214 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 215**/\r
216EFI_STATUS\r
217EFIAPI\r
47d20b54
MK
218ShellCreateDirectory (\r
219 IN CONST CHAR16 *DirectoryName,\r
220 OUT SHELL_FILE_HANDLE *FileHandle\r
94b17fa1 221 );\r
222\r
223/**\r
224 This function reads information from an opened file.\r
225\r
1e6e84c7 226 If FileHandle is not a directory, the function reads the requested number of\r
227 bytes from the file at the file's current position and returns them in Buffer.\r
94b17fa1 228 If the read goes beyond the end of the file, the read length is truncated to the\r
1e6e84c7 229 end of the file. The file's current position is increased by the number of bytes\r
230 returned. If FileHandle is a directory, the function reads the directory entry\r
231 at the file's current position and returns the entry in Buffer. If the Buffer\r
232 is not large enough to hold the current directory entry, then\r
233 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.\r
234 BufferSize is set to be the size of the buffer needed to read the entry. On\r
235 success, the current position is updated to the next directory entry. If there\r
236 are no more directory entries, the read returns a zero-length buffer.\r
94b17fa1 237 EFI_FILE_INFO is the structure returned as the directory entry.\r
238\r
4ff7e37b
ED
239 @param[in] FileHandle The opened file handle.\r
240 @param[in, out] ReadSize On input the size of buffer in bytes. On return\r
241 the number of bytes written.\r
242 @param[out] Buffer The buffer to put read data into.\r
94b17fa1 243\r
a405b86d 244 @retval EFI_SUCCESS Data was read.\r
b0934ac4 245 @retval EFI_NO_MEDIA The device has no media.\r
a405b86d 246 @retval EFI_DEVICE_ERROR The device reported an error.\r
b0934ac4 247 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
a405b86d 248 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required\r
94b17fa1 249 size.\r
250\r
251**/\r
252EFI_STATUS\r
253EFIAPI\r
47d20b54
MK
254ShellReadFile (\r
255 IN SHELL_FILE_HANDLE FileHandle,\r
256 IN OUT UINTN *ReadSize,\r
257 OUT VOID *Buffer\r
94b17fa1 258 );\r
259\r
260/**\r
261 Write data to a file.\r
262\r
1e6e84c7 263 This function writes the specified number of bytes to the file at the current\r
264 file position. The current file position is advanced the actual number of bytes\r
265 written, which is returned in BufferSize. Partial writes only occur when there\r
266 has been a data error during the write attempt (such as "volume space full").\r
267 The file is automatically grown to hold the data if required. Direct writes to\r
94b17fa1 268 opened directories are not supported.\r
269\r
4ff7e37b 270 @param[in] FileHandle The opened file for writing.\r
94b17fa1 271\r
4ff7e37b
ED
272 @param[in, out] BufferSize On input the number of bytes in Buffer. On output\r
273 the number of bytes written.\r
94b17fa1 274\r
4ff7e37b 275 @param[in] Buffer The buffer containing data to write is stored.\r
94b17fa1 276\r
a405b86d 277 @retval EFI_SUCCESS Data was written.\r
278 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.\r
b0934ac4 279 @retval EFI_NO_MEDIA The device has no media.\r
a405b86d 280 @retval EFI_DEVICE_ERROR The device reported an error.\r
281 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
282 @retval EFI_WRITE_PROTECTED The device is write-protected.\r
283 @retval EFI_ACCESS_DENIED The file was open for read only.\r
284 @retval EFI_VOLUME_FULL The volume is full.\r
94b17fa1 285**/\r
286EFI_STATUS\r
287EFIAPI\r
47d20b54
MK
288ShellWriteFile (\r
289 IN SHELL_FILE_HANDLE FileHandle,\r
290 IN OUT UINTN *BufferSize,\r
291 IN VOID *Buffer\r
94b17fa1 292 );\r
293\r
1e6e84c7 294/**\r
94b17fa1 295 Close an open file handle.\r
296\r
1e6e84c7 297 This function closes a specified file handle. All "dirty" cached file data is\r
298 flushed to the device, and the file is closed. In all cases the handle is\r
94b17fa1 299 closed.\r
300\r
18cefebe 301 @param[in] FileHandle The file handle to close.\r
94b17fa1 302\r
125c2cf4 303 @retval EFI_SUCCESS The file handle was closed sucessfully.\r
a405b86d 304 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
94b17fa1 305**/\r
306EFI_STATUS\r
307EFIAPI\r
308ShellCloseFile (\r
47d20b54 309 IN SHELL_FILE_HANDLE *FileHandle\r
94b17fa1 310 );\r
311\r
312/**\r
313 Delete a file and close the handle\r
314\r
315 This function closes and deletes a file. In all cases the file handle is closed.\r
1e6e84c7 316 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is\r
94b17fa1 317 returned, but the handle is still closed.\r
318\r
18cefebe 319 @param[in] FileHandle The file handle to delete.\r
94b17fa1 320\r
125c2cf4 321 @retval EFI_SUCCESS The file was closed sucessfully.\r
1e6e84c7 322 @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not\r
125c2cf4 323 deleted.\r
b0934ac4 324 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
94b17fa1 325**/\r
326EFI_STATUS\r
327EFIAPI\r
328ShellDeleteFile (\r
47d20b54 329 IN SHELL_FILE_HANDLE *FileHandle\r
94b17fa1 330 );\r
331\r
332/**\r
333 Set the current position in a file.\r
334\r
1e6e84c7 335 This function sets the current file position for the handle to the position\r
94b17fa1 336 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only\r
a405b86d 337 absolute positioning is supported, and moving past the end of the file is\r
338 allowed (a subsequent write would grow the file). Moving to position\r
94b17fa1 339 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
1e6e84c7 340 If FileHandle is a directory, the only position that may be set is zero. This\r
94b17fa1 341 has the effect of starting the read process of the directory entries over.\r
342\r
18cefebe 343 @param[in] FileHandle The file handle on which the position is being set.\r
94b17fa1 344\r
a405b86d 345 @param[in] Position The byte position from the begining of the file.\r
94b17fa1 346\r
347 @retval EFI_SUCCESS Operation completed sucessfully.\r
1e6e84c7 348 @retval EFI_UNSUPPORTED The seek request for non-zero is not valid on\r
94b17fa1 349 directories.\r
350 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
351**/\r
352EFI_STATUS\r
353EFIAPI\r
354ShellSetFilePosition (\r
b0934ac4 355 IN SHELL_FILE_HANDLE FileHandle,\r
356 IN UINT64 Position\r
94b17fa1 357 );\r
358\r
1e6e84c7 359/**\r
94b17fa1 360 Gets a file's current position\r
361\r
1e6e84c7 362 This function retrieves the current file position for the file handle. For\r
363 directories, the current file position has no meaning outside of the file\r
94b17fa1 364 system driver and as such the operation is not supported. An error is returned\r
365 if FileHandle is a directory.\r
366\r
18cefebe 367 @param[in] FileHandle The open file handle on which to get the position.\r
a405b86d 368 @param[out] Position The byte position from the begining of the file.\r
94b17fa1 369\r
18cefebe 370 @retval EFI_SUCCESS The operation completed sucessfully.\r
94b17fa1 371 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
18cefebe 372 @retval EFI_UNSUPPORTED The request is not valid on directories.\r
94b17fa1 373**/\r
374EFI_STATUS\r
375EFIAPI\r
376ShellGetFilePosition (\r
47d20b54
MK
377 IN SHELL_FILE_HANDLE FileHandle,\r
378 OUT UINT64 *Position\r
94b17fa1 379 );\r
380\r
381/**\r
382 Flushes data on a file\r
1e6e84c7 383\r
94b17fa1 384 This function flushes all modified data associated with a file to a device.\r
385\r
18cefebe 386 @param[in] FileHandle The file handle on which to flush data.\r
94b17fa1 387\r
388 @retval EFI_SUCCESS The data was flushed.\r
389 @retval EFI_NO_MEDIA The device has no media.\r
390 @retval EFI_DEVICE_ERROR The device reported an error.\r
391 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
392 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
393 @retval EFI_ACCESS_DENIED The file was opened for read only.\r
394**/\r
395EFI_STATUS\r
396EFIAPI\r
397ShellFlushFile (\r
47d20b54 398 IN SHELL_FILE_HANDLE FileHandle\r
94b17fa1 399 );\r
400\r
b0934ac4 401/** Retrieve first entry from a directory.\r
94b17fa1 402\r
b0934ac4 403 This function takes an open directory handle and gets information from the\r
404 first entry in the directory. A buffer is allocated to contain\r
405 the information and a pointer to the buffer is returned in *Buffer. The\r
406 caller can use ShellFindNextFile() to get subsequent directory entries.\r
94b17fa1 407\r
b0934ac4 408 The buffer will be freed by ShellFindNextFile() when the last directory\r
409 entry is read. Otherwise, the caller must free the buffer, using FreePool,\r
410 when finished with it.\r
d2b4564b 411\r
b0934ac4 412 @param[in] DirHandle The file handle of the directory to search.\r
a405b86d 413 @param[out] Buffer The pointer to the buffer for the file's information.\r
94b17fa1 414\r
415 @retval EFI_SUCCESS Found the first file.\r
416 @retval EFI_NOT_FOUND Cannot find the directory.\r
417 @retval EFI_NO_MEDIA The device has no media.\r
418 @retval EFI_DEVICE_ERROR The device reported an error.\r
419 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
b0934ac4 420 @return Others Status of ShellGetFileInfo, ShellSetFilePosition,\r
421 or ShellReadFile.\r
422\r
a405b86d 423 @sa ShellReadFile\r
94b17fa1 424**/\r
425EFI_STATUS\r
426EFIAPI\r
427ShellFindFirstFile (\r
47d20b54
MK
428 IN SHELL_FILE_HANDLE DirHandle,\r
429 OUT EFI_FILE_INFO **Buffer\r
94b17fa1 430 );\r
431\r
b0934ac4 432/** Retrieve next entries from a directory.\r
94b17fa1 433\r
b0934ac4 434 To use this function, the caller must first call the ShellFindFirstFile()\r
435 function to get the first directory entry. Subsequent directory entries are\r
436 retrieved by using the ShellFindNextFile() function. This function can\r
437 be called several times to get each entry from the directory. If the call of\r
438 ShellFindNextFile() retrieved the last directory entry, the next call of\r
439 this function will set *NoFile to TRUE and free the buffer.\r
94b17fa1 440\r
b0934ac4 441 @param[in] DirHandle The file handle of the directory.\r
37d5c6ee
ED
442 @param[in, out] Buffer The pointer to buffer for file's information.\r
443 @param[in, out] NoFile The pointer to boolean when last file is found.\r
94b17fa1 444\r
445 @retval EFI_SUCCESS Found the next file.\r
446 @retval EFI_NO_MEDIA The device has no media.\r
447 @retval EFI_DEVICE_ERROR The device reported an error.\r
448 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
b0934ac4 449\r
a405b86d 450 @sa ShellReadFile\r
94b17fa1 451**/\r
452EFI_STATUS\r
453EFIAPI\r
47d20b54
MK
454ShellFindNextFile (\r
455 IN SHELL_FILE_HANDLE DirHandle,\r
456 IN OUT EFI_FILE_INFO *Buffer,\r
457 IN OUT BOOLEAN *NoFile\r
94b17fa1 458 );\r
459\r
460/**\r
461 Retrieve the size of a file.\r
462\r
1e6e84c7 463 This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
94b17fa1 464 data.\r
465\r
18cefebe 466 @param[in] FileHandle The file handle from which size is retrieved.\r
a405b86d 467 @param[out] Size The pointer to size.\r
94b17fa1 468\r
125c2cf4 469 @retval EFI_SUCCESS The operation was completed sucessfully.\r
a31bd33c 470 @retval EFI_DEVICE_ERROR Cannot access the file.\r
94b17fa1 471**/\r
472EFI_STATUS\r
473EFIAPI\r
474ShellGetFileSize (\r
47d20b54
MK
475 IN SHELL_FILE_HANDLE FileHandle,\r
476 OUT UINT64 *Size\r
94b17fa1 477 );\r
478\r
479/**\r
480 Retrieves the status of the break execution flag\r
481\r
18cefebe 482 This function is useful to check whether the application is being asked to halt by the shell.\r
94b17fa1 483\r
a405b86d 484 @retval TRUE The execution break is enabled.\r
485 @retval FALSE The execution break is not enabled.\r
94b17fa1 486**/\r
487BOOLEAN\r
488EFIAPI\r
47d20b54 489ShellGetExecutionBreakFlag (\r
94b17fa1 490 VOID\r
491 );\r
492\r
493/**\r
125c2cf4 494 Return the value of an environment variable.\r
94b17fa1 495\r
1e6e84c7 496 This function gets the value of the environment variable set by the\r
125c2cf4 497 ShellSetEnvironmentVariable function.\r
94b17fa1 498\r
18cefebe 499 @param[in] EnvKey The key name of the environment variable.\r
94b17fa1 500\r
a31bd33c 501 @retval NULL The named environment variable does not exist.\r
a405b86d 502 @return != NULL The pointer to the value of the environment variable.\r
94b17fa1 503**/\r
47d20b54 504CONST CHAR16 *\r
94b17fa1 505EFIAPI\r
506ShellGetEnvironmentVariable (\r
47d20b54 507 IN CONST CHAR16 *EnvKey\r
94b17fa1 508 );\r
509\r
510/**\r
18cefebe 511 Set the value of an environment variable.\r
94b17fa1 512\r
125c2cf4 513 This function changes the current value of the specified environment variable. If the\r
514 environment variable exists and the Value is an empty string, then the environment\r
515 variable is deleted. If the environment variable exists and the Value is not an empty\r
516 string, then the value of the environment variable is changed. If the environment\r
517 variable does not exist and the Value is an empty string, there is no action. If the\r
518 environment variable does not exist and the Value is a non-empty string, then the\r
519 environment variable is created and assigned the specified value.\r
94b17fa1 520\r
521 This is not supported pre-UEFI Shell 2.0.\r
522\r
18cefebe 523 @param[in] EnvKey The key name of the environment variable.\r
524 @param[in] EnvVal The Value of the environment variable\r
525 @param[in] Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).\r
94b17fa1 526\r
a405b86d 527 @retval EFI_SUCCESS The operation completed sucessfully\r
528 @retval EFI_UNSUPPORTED This operation is not allowed in pre-UEFI 2.0 Shell environments.\r
94b17fa1 529**/\r
530EFI_STATUS\r
531EFIAPI\r
532ShellSetEnvironmentVariable (\r
47d20b54
MK
533 IN CONST CHAR16 *EnvKey,\r
534 IN CONST CHAR16 *EnvVal,\r
535 IN BOOLEAN Volatile\r
94b17fa1 536 );\r
537\r
538/**\r
125c2cf4 539 Cause the shell to parse and execute a command line.\r
94b17fa1 540\r
541 This function creates a nested instance of the shell and executes the specified\r
125c2cf4 542 command (CommandLine) with the specified environment (Environment). Upon return,\r
543 the status code returned by the specified command is placed in StatusCode.\r
544 If Environment is NULL, then the current environment is used and all changes made\r
545 by the commands executed will be reflected in the current environment. If the\r
546 Environment is non-NULL, then the changes made will be discarded.\r
547 The CommandLine is executed from the current working directory on the current\r
548 device.\r
94b17fa1 549\r
7e4ed4b8 550 The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0\r
551 environment. The values pointed to by the parameters will be unchanged by the\r
552 ShellExecute() function. The Output parameter has no effect in a\r
553 UEFI Shell 2.0 environment.\r
94b17fa1 554\r
a405b86d 555 @param[in] ParentHandle The parent image starting the operation.\r
556 @param[in] CommandLine The pointer to a NULL terminated command line.\r
18cefebe 557 @param[in] Output True to display debug output. False to hide it.\r
558 @param[in] EnvironmentVariables Optional pointer to array of environment variables\r
a405b86d 559 in the form "x=y". If NULL, the current set is used.\r
18cefebe 560 @param[out] Status The status of the run command line.\r
94b17fa1 561\r
18cefebe 562 @retval EFI_SUCCESS The operation completed sucessfully. Status\r
563 contains the status code returned.\r
564 @retval EFI_INVALID_PARAMETER A parameter contains an invalid value.\r
565 @retval EFI_OUT_OF_RESOURCES Out of resources.\r
566 @retval EFI_UNSUPPORTED The operation is not allowed.\r
94b17fa1 567**/\r
568EFI_STATUS\r
569EFIAPI\r
570ShellExecute (\r
47d20b54
MK
571 IN EFI_HANDLE *ParentHandle,\r
572 IN CHAR16 *CommandLine,\r
573 IN BOOLEAN Output,\r
574 IN CHAR16 **EnvironmentVariables,\r
575 OUT EFI_STATUS *Status\r
94b17fa1 576 );\r
577\r
578/**\r
a31bd33c 579 Retreives the current directory path.\r
94b17fa1 580\r
1e6e84c7 581 If the DeviceName is NULL, it returns the current device's current directory\r
582 name. If the DeviceName is not NULL, it returns the current directory name\r
94b17fa1 583 on specified drive.\r
584\r
fbd2dfad
QS
585 Note that the current directory string should exclude the tailing backslash character.\r
586\r
18cefebe 587 @param[in] DeviceName The name of the file system to get directory on.\r
94b17fa1 588\r
a31bd33c 589 @retval NULL The directory does not exist.\r
18cefebe 590 @retval != NULL The directory.\r
94b17fa1 591**/\r
47d20b54 592CONST CHAR16 *\r
94b17fa1 593EFIAPI\r
594ShellGetCurrentDir (\r
47d20b54 595 IN CHAR16 *CONST DeviceName OPTIONAL\r
94b17fa1 596 );\r
597\r
598/**\r
125c2cf4 599 Sets (enabled or disabled) the page break mode.\r
94b17fa1 600\r
1e6e84c7 601 When page break mode is enabled the screen will stop scrolling\r
94b17fa1 602 and wait for operator input before scrolling a subsequent screen.\r
603\r
18cefebe 604 @param[in] CurrentState TRUE to enable and FALSE to disable.\r
94b17fa1 605**/\r
1e6e84c7 606VOID\r
94b17fa1 607EFIAPI\r
608ShellSetPageBreakMode (\r
47d20b54 609 IN BOOLEAN CurrentState\r
94b17fa1 610 );\r
611\r
612/**\r
613 Opens a group of files based on a path.\r
614\r
1e6e84c7 615 This function uses the Arg to open all the matching files. Each matched\r
616 file has a SHELL_FILE_ARG structure to record the file information. These\r
617 structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG\r
94b17fa1 618 structures from ListHead to access each file. This function supports wildcards\r
1e6e84c7 619 and will process '?' and '*' as such. The list must be freed with a call to\r
94b17fa1 620 ShellCloseFileMetaArg().\r
621\r
1e6e84c7 622 If you are NOT appending to an existing list *ListHead must be NULL. If\r
eb646684 623 *ListHead is NULL then it must be callee freed.\r
94b17fa1 624\r
4ff7e37b
ED
625 @param[in] Arg The pointer to path string.\r
626 @param[in] OpenMode Mode to open files with.\r
627 @param[in, out] ListHead Head of linked list of results.\r
94b17fa1 628\r
1e6e84c7 629 @retval EFI_SUCCESS The operation was sucessful and the list head\r
125c2cf4 630 contains the list of opened files.\r
a31bd33c 631 @retval != EFI_SUCCESS The operation failed.\r
94b17fa1 632\r
633 @sa InternalShellConvertFileListType\r
634**/\r
635EFI_STATUS\r
636EFIAPI\r
637ShellOpenFileMetaArg (\r
47d20b54
MK
638 IN CHAR16 *Arg,\r
639 IN UINT64 OpenMode,\r
640 IN OUT EFI_SHELL_FILE_INFO **ListHead\r
94b17fa1 641 );\r
642\r
643/**\r
a31bd33c 644 Free the linked list returned from ShellOpenFileMetaArg.\r
94b17fa1 645\r
4ff7e37b 646 @param[in, out] ListHead The pointer to free.\r
94b17fa1 647\r
a31bd33c 648 @retval EFI_SUCCESS The operation was sucessful.\r
649 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
94b17fa1 650**/\r
651EFI_STATUS\r
652EFIAPI\r
653ShellCloseFileMetaArg (\r
47d20b54 654 IN OUT EFI_SHELL_FILE_INFO **ListHead\r
94b17fa1 655 );\r
656\r
125c2cf4 657/**\r
658 Find a file by searching the CWD and then the path.\r
659\r
a31bd33c 660 If FileName is NULL, then ASSERT.\r
125c2cf4 661\r
a31bd33c 662 If the return value is not NULL then the memory must be caller freed.\r
125c2cf4 663\r
18cefebe 664 @param[in] FileName Filename string.\r
125c2cf4 665\r
a31bd33c 666 @retval NULL The file was not found.\r
18cefebe 667 @retval !NULL The path to the file.\r
125c2cf4 668**/\r
669CHAR16 *\r
670EFIAPI\r
671ShellFindFilePath (\r
47d20b54 672 IN CONST CHAR16 *FileName\r
125c2cf4 673 );\r
674\r
b3011f40 675/**\r
1e6e84c7 676 Find a file by searching the CWD and then the path with a variable set of file\r
677 extensions. If the file is not found it will append each extension in the list\r
b3011f40 678 in the order provided and return the first one that is successful.\r
679\r
680 If FileName is NULL, then ASSERT.\r
a405b86d 681 If FileExtension is NULL, then the behavior is identical to ShellFindFilePath.\r
b3011f40 682\r
683 If the return value is not NULL then the memory must be caller freed.\r
684\r
a405b86d 685 @param[in] FileName The filename string.\r
686 @param[in] FileExtension Semicolon delimited list of possible extensions.\r
b3011f40 687\r
688 @retval NULL The file was not found.\r
689 @retval !NULL The path to the file.\r
690**/\r
691CHAR16 *\r
692EFIAPI\r
693ShellFindFilePathEx (\r
47d20b54
MK
694 IN CONST CHAR16 *FileName,\r
695 IN CONST CHAR16 *FileExtension\r
b3011f40 696 );\r
697\r
94b17fa1 698typedef enum {\r
47d20b54 699 TypeFlag = 0, ///< A flag that is present or not present only (IE "-a").\r
18cefebe 700 TypeValue, ///< A flag that has some data following it with a space (IE "-a 1").\r
701 TypePosition, ///< Some data that did not follow a parameter (IE "filename.txt").\r
702 TypeStart, ///< A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc...).\r
703 TypeDoubleValue, ///< A flag that has 2 space seperated value data following it (IE "-a 1 2").\r
704 TypeMaxValue, ///< A flag followed by all the command line data before the next flag.\r
658bf43e 705 TypeTimeValue, ///< A flag that has a time value following it (IE "-a -5:00").\r
94b17fa1 706 TypeMax,\r
a405b86d 707} SHELL_PARAM_TYPE;\r
94b17fa1 708\r
709typedef struct {\r
47d20b54
MK
710 CHAR16 *Name;\r
711 SHELL_PARAM_TYPE Type;\r
94b17fa1 712} SHELL_PARAM_ITEM;\r
713\r
d2b4564b 714/// Helper structure for no parameters (besides -? and -b)\r
47d20b54 715extern SHELL_PARAM_ITEM EmptyParamList[];\r
d2b4564b 716\r
a405b86d 717/// Helper structure for -sfo only (besides -? and -b)\r
47d20b54 718extern SHELL_PARAM_ITEM SfoParamList[];\r
a405b86d 719\r
94b17fa1 720/**\r
1e6e84c7 721 Checks the command line arguments passed against the list of valid ones.\r
94b17fa1 722 Optionally removes NULL values first.\r
1e6e84c7 723\r
94b17fa1 724 If no initialization is required, then return RETURN_SUCCESS.\r
1e6e84c7 725\r
a405b86d 726 @param[in] CheckList The pointer to list of parameters to check.\r
727 @param[out] CheckPackage The package of checked values.\r
1e6e84c7 728 @param[out] ProblemParam Optional pointer to pointer to unicode string for\r
94b17fa1 729 the paramater that caused failure.\r
18cefebe 730 @param[in] AutoPageBreak Will automatically set PageBreakEnabled.\r
731 @param[in] AlwaysAllowNumbers Will never fail for number based flags.\r
94b17fa1 732\r
733 @retval EFI_SUCCESS The operation completed sucessfully.\r
a31bd33c 734 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
735 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
a405b86d 736 @retval EFI_VOLUME_CORRUPTED The command line was corrupt.\r
a31bd33c 737 @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One\r
1e6e84c7 738 of the command line arguments was returned in\r
94b17fa1 739 ProblemParam if provided.\r
1e6e84c7 740 @retval EFI_NOT_FOUND A argument required a value that was missing.\r
a31bd33c 741 The invalid command line argument was returned in\r
94b17fa1 742 ProblemParam if provided.\r
743**/\r
744EFI_STATUS\r
745EFIAPI\r
2247dde4 746ShellCommandLineParseEx (\r
47d20b54
MK
747 IN CONST SHELL_PARAM_ITEM *CheckList,\r
748 OUT LIST_ENTRY **CheckPackage,\r
749 OUT CHAR16 **ProblemParam OPTIONAL,\r
750 IN BOOLEAN AutoPageBreak,\r
751 IN BOOLEAN AlwaysAllowNumbers\r
94b17fa1 752 );\r
753\r
18cefebe 754/// Make it easy to upgrade from older versions of the shell library.\r
47d20b54 755#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak) ShellCommandLineParseEx(CheckList,CheckPackage,ProblemParam,AutoPageBreak,FALSE)\r
2247dde4 756\r
94b17fa1 757/**\r
758 Frees shell variable list that was returned from ShellCommandLineParse.\r
759\r
760 This function will free all the memory that was used for the CheckPackage\r
761 list of postprocessed shell arguments.\r
762\r
a31bd33c 763 If CheckPackage is NULL, then return.\r
94b17fa1 764\r
18cefebe 765 @param[in] CheckPackage The list to de-allocate.\r
94b17fa1 766 **/\r
767VOID\r
768EFIAPI\r
769ShellCommandLineFreeVarList (\r
47d20b54 770 IN LIST_ENTRY *CheckPackage\r
94b17fa1 771 );\r
772\r
773/**\r
a31bd33c 774 Checks for presence of a flag parameter.\r
94b17fa1 775\r
18cefebe 776 Flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key.\r
94b17fa1 777\r
18cefebe 778 If CheckPackage is NULL then return FALSE.\r
779 If KeyString is NULL then ASSERT().\r
1e6e84c7 780\r
18cefebe 781 @param[in] CheckPackage The package of parsed command line arguments.\r
782 @param[in] KeyString The Key of the command line argument to check for.\r
94b17fa1 783\r
a31bd33c 784 @retval TRUE The flag is on the command line.\r
785 @retval FALSE The flag is not on the command line.\r
a405b86d 786**/\r
94b17fa1 787BOOLEAN\r
788EFIAPI\r
789ShellCommandLineGetFlag (\r
47d20b54
MK
790 IN CONST LIST_ENTRY *CONST CheckPackage,\r
791 IN CONST CHAR16 *CONST KeyString\r
94b17fa1 792 );\r
793\r
794/**\r
a31bd33c 795 Returns value from command line argument.\r
94b17fa1 796\r
18cefebe 797 Value parameters are in the form of "-<Key> value" or "/<Key> value".\r
1e6e84c7 798\r
a31bd33c 799 If CheckPackage is NULL, then return NULL.\r
94b17fa1 800\r
36a9d672 801 @param[in] CheckPackage The package of parsed command line arguments.\r
802 @param[in] KeyString The Key of the command line argument to check for.\r
94b17fa1 803\r
a31bd33c 804 @retval NULL The flag is not on the command line.\r
a405b86d 805 @retval !=NULL The pointer to unicode string of the value.\r
806**/\r
47d20b54 807CONST CHAR16 *\r
94b17fa1 808EFIAPI\r
809ShellCommandLineGetValue (\r
47d20b54
MK
810 IN CONST LIST_ENTRY *CheckPackage,\r
811 IN CHAR16 *KeyString\r
94b17fa1 812 );\r
813\r
814/**\r
a31bd33c 815 Returns raw value from command line argument.\r
94b17fa1 816\r
a31bd33c 817 Raw value parameters are in the form of "value" in a specific position in the list.\r
1e6e84c7 818\r
36a9d672 819 If CheckPackage is NULL, then return NULL.\r
94b17fa1 820\r
36a9d672 821 @param[in] CheckPackage The package of parsed command line arguments.\r
822 @param[in] Position The position of the value.\r
94b17fa1 823\r
a31bd33c 824 @retval NULL The flag is not on the command line.\r
a405b86d 825 @retval !=NULL The pointer to unicode string of the value.\r
826**/\r
47d20b54 827CONST CHAR16 *\r
94b17fa1 828EFIAPI\r
829ShellCommandLineGetRawValue (\r
47d20b54
MK
830 IN CONST LIST_ENTRY *CONST CheckPackage,\r
831 IN UINTN Position\r
94b17fa1 832 );\r
833\r
2247dde4 834/**\r
1e6e84c7 835 Returns the number of command line value parameters that were parsed.\r
836\r
a31bd33c 837 This will not include flags.\r
2247dde4 838\r
a405b86d 839 @param[in] CheckPackage The package of parsed command line arguments.\r
840\r
841 @retval (UINTN)-1 No parsing has occurred.\r
842 @retval other The number of value parameters found.\r
2247dde4 843**/\r
844UINTN\r
845EFIAPI\r
47d20b54
MK
846ShellCommandLineGetCount (\r
847 IN CONST LIST_ENTRY *CheckPackage\r
2247dde4 848 );\r
849\r
36a9d672 850/**\r
a405b86d 851 Determines if a parameter is duplicated.\r
36a9d672 852\r
a405b86d 853 If Param is not NULL, then it will point to a callee-allocated string buffer\r
854 with the parameter value, if a duplicate is found.\r
36a9d672 855\r
856 If CheckPackage is NULL, then ASSERT.\r
857\r
858 @param[in] CheckPackage The package of parsed command line arguments.\r
859 @param[out] Param Upon finding one, a pointer to the duplicated parameter.\r
860\r
861 @retval EFI_SUCCESS No parameters were duplicated.\r
862 @retval EFI_DEVICE_ERROR A duplicate was found.\r
863 **/\r
864EFI_STATUS\r
865EFIAPI\r
866ShellCommandLineCheckDuplicate (\r
47d20b54
MK
867 IN CONST LIST_ENTRY *CheckPackage,\r
868 OUT CHAR16 **Param\r
36a9d672 869 );\r
870\r
d2b4564b 871/**\r
872 This function causes the shell library to initialize itself. If the shell library\r
a405b86d 873 is already initialized it will de-initialize all the current protocol pointers and\r
d2b4564b 874 re-populate them again.\r
875\r
876 When the library is used with PcdShellLibAutoInitialize set to true this function\r
877 will return EFI_SUCCESS and perform no actions.\r
878\r
879 This function is intended for internal access for shell commands only.\r
880\r
a405b86d 881 @retval EFI_SUCCESS The initialization was complete sucessfully.\r
d2b4564b 882\r
883**/\r
884EFI_STATUS\r
885EFIAPI\r
886ShellInitialize (\r
125c2cf4 887 VOID\r
d2b4564b 888 );\r
889\r
b1f95a06 890/**\r
891 Print at a specific location on the screen.\r
892\r
a5bd42b9 893 This function will move the cursor to a given screen location and print the specified string.\r
1e6e84c7 894\r
895 If -1 is specified for either the Row or Col the current screen location for BOTH\r
a5bd42b9 896 will be used.\r
b1f95a06 897\r
a31bd33c 898 If either Row or Col is out of range for the current console, then ASSERT.\r
899 If Format is NULL, then ASSERT.\r
b1f95a06 900\r
1e6e84c7 901 In addition to the standard %-based flags as supported by UefiLib Print() this supports\r
b1f95a06 902 the following additional flags:\r
903 %N - Set output attribute to normal\r
904 %H - Set output attribute to highlight\r
905 %E - Set output attribute to error\r
906 %B - Set output attribute to blue color\r
907 %V - Set output attribute to green color\r
908\r
909 Note: The background color is controlled by the shell command cls.\r
910\r
18cefebe 911 @param[in] Col The column to print at.\r
a405b86d 912 @param[in] Row The row to print at.\r
18cefebe 913 @param[in] Format The format string.\r
a405b86d 914 @param[in] ... The variable argument list.\r
b1f95a06 915\r
a405b86d 916 @return EFI_SUCCESS The printing was successful.\r
917 @return EFI_DEVICE_ERROR The console device reported an error.\r
b1f95a06 918**/\r
a405b86d 919EFI_STATUS\r
b1f95a06 920EFIAPI\r
47d20b54
MK
921ShellPrintEx (\r
922 IN INT32 Col OPTIONAL,\r
923 IN INT32 Row OPTIONAL,\r
924 IN CONST CHAR16 *Format,\r
b1f95a06 925 ...\r
926 );\r
927\r
2247dde4 928/**\r
929 Print at a specific location on the screen.\r
930\r
a5bd42b9 931 This function will move the cursor to a given screen location and print the specified string.\r
1e6e84c7 932\r
933 If -1 is specified for either the Row or Col the current screen location for BOTH\r
a5bd42b9 934 will be used.\r
2247dde4 935\r
a5bd42b9 936 If either Row or Col is out of range for the current console, then ASSERT.\r
937 If Format is NULL, then ASSERT.\r
2247dde4 938\r
1e6e84c7 939 In addition to the standard %-based flags as supported by UefiLib Print() this supports\r
2247dde4 940 the following additional flags:\r
18cefebe 941 %N - Set output attribute to normal.\r
942 %H - Set output attribute to highlight.\r
943 %E - Set output attribute to error.\r
944 %B - Set output attribute to blue color.\r
945 %V - Set output attribute to green color.\r
2247dde4 946\r
947 Note: The background color is controlled by the shell command cls.\r
948\r
18cefebe 949 @param[in] Col The column to print at.\r
a405b86d 950 @param[in] Row The row to print at.\r
1e6e84c7 951 @param[in] Language The language of the string to retrieve. If this parameter\r
952 is NULL, then the current platform language is used.\r
18cefebe 953 @param[in] HiiFormatStringId The format string Id for getting from Hii.\r
954 @param[in] HiiFormatHandle The format string Handle for getting from Hii.\r
a405b86d 955 @param[in] ... The variable argument list.\r
2247dde4 956\r
a405b86d 957 @return EFI_SUCCESS The printing was successful.\r
958 @return EFI_DEVICE_ERROR The console device reported an error.\r
2247dde4 959**/\r
a405b86d 960EFI_STATUS\r
2247dde4 961EFIAPI\r
47d20b54
MK
962ShellPrintHiiEx (\r
963 IN INT32 Col OPTIONAL,\r
964 IN INT32 Row OPTIONAL,\r
965 IN CONST CHAR8 *Language OPTIONAL,\r
966 IN CONST EFI_STRING_ID HiiFormatStringId,\r
967 IN CONST EFI_HII_HANDLE HiiFormatHandle,\r
2247dde4 968 ...\r
969 );\r
970\r
971/**\r
a31bd33c 972 Function to determine if a given filename represents a directory.\r
2247dde4 973\r
18cefebe 974 If DirName is NULL, then ASSERT.\r
975\r
2247dde4 976 @param[in] DirName Path to directory to test.\r
977\r
a31bd33c 978 @retval EFI_SUCCESS The Path represents a directory.\r
979 @retval EFI_NOT_FOUND The Path does not represent a directory.\r
980 @retval other The path failed to open.\r
2247dde4 981**/\r
982EFI_STATUS\r
983EFIAPI\r
47d20b54
MK
984ShellIsDirectory (\r
985 IN CONST CHAR16 *DirName\r
2247dde4 986 );\r
987\r
a31bd33c 988/**\r
989 Function to determine if a given filename represents a file.\r
990\r
b3011f40 991 This will search the CWD only.\r
992\r
18cefebe 993 If Name is NULL, then ASSERT.\r
994\r
a31bd33c 995 @param[in] Name Path to file to test.\r
996\r
997 @retval EFI_SUCCESS The Path represents a file.\r
998 @retval EFI_NOT_FOUND The Path does not represent a file.\r
999 @retval other The path failed to open.\r
1000**/\r
1001EFI_STATUS\r
1002EFIAPI\r
47d20b54
MK
1003ShellIsFile (\r
1004 IN CONST CHAR16 *Name\r
a31bd33c 1005 );\r
1006\r
b3011f40 1007/**\r
1008 Function to determine if a given filename represents a file.\r
1009\r
1010 This will search the CWD and then the Path.\r
1011\r
1012 If Name is NULL, then ASSERT.\r
1013\r
1014 @param[in] Name Path to file to test.\r
1015\r
1016 @retval EFI_SUCCESS The Path represents a file.\r
1017 @retval EFI_NOT_FOUND The Path does not represent a file.\r
1018 @retval other The path failed to open.\r
1019**/\r
1020EFI_STATUS\r
1021EFIAPI\r
47d20b54
MK
1022ShellIsFileInPath (\r
1023 IN CONST CHAR16 *Name\r
b3011f40 1024 );\r
1025\r
125c2cf4 1026/**\r
1e6e84c7 1027 Function to determine whether a string is decimal or hex representation of a number\r
125c2cf4 1028 and return the number converted from the string.\r
1029\r
b0934ac4 1030 Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid\r
4bbdc0e1 1031 result. Use ShellConvertStringToUint64 instead.\r
1032\r
1033 @param[in] String String representation of a number.\r
125c2cf4 1034\r
a31bd33c 1035 @return The unsigned integer result of the conversion.\r
a048af3c 1036 @retval (UINTN)(-1) An error occurred.\r
125c2cf4 1037**/\r
1038UINTN\r
1039EFIAPI\r
47d20b54
MK
1040ShellStrToUintn (\r
1041 IN CONST CHAR16 *String\r
74b0fb8c
JC
1042 );\r
1043\r
1044/**\r
1045 Function return the number converted from a hex representation of a number.\r
1046\r
1047 Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid\r
1048 result. Use ShellConvertStringToUint64 instead.\r
1049\r
1050 @param[in] String String representation of a number.\r
1051\r
1052 @return The unsigned integer result of the conversion.\r
a048af3c 1053 @retval (UINTN)(-1) An error occurred.\r
74b0fb8c
JC
1054**/\r
1055UINTN\r
1056EFIAPI\r
47d20b54
MK
1057ShellHexStrToUintn (\r
1058 IN CONST CHAR16 *String\r
125c2cf4 1059 );\r
1060\r
1061/**\r
1e6e84c7 1062 Safely append with automatic string resizing given length of Destination and\r
125c2cf4 1063 desired length of copy from Source.\r
1064\r
1e6e84c7 1065 Append the first D characters of Source to the end of Destination, where D is\r
1066 the lesser of Count and the StrLen() of Source. If appending those D characters\r
1067 will fit within Destination (whose Size is given as CurrentSize) and\r
1068 still leave room for a NULL terminator, then those characters are appended,\r
1069 starting at the original terminating NULL of Destination, and a new terminating\r
1070 NULL is appended.\r
125c2cf4 1071\r
1072 If appending D characters onto Destination will result in a overflow of the size\r
1073 given in CurrentSize the string will be grown such that the copy can be performed\r
1074 and CurrentSize will be updated to the new size.\r
1075\r
a405b86d 1076 If Source is NULL, there is nothing to append, so return the current buffer in\r
125c2cf4 1077 Destination.\r
1078\r
18cefebe 1079 If Destination is NULL, then ASSERT().\r
1e6e84c7 1080 If Destination's current length (including NULL terminator) is already more than\r
a31bd33c 1081 CurrentSize, then ASSERT().\r
125c2cf4 1082\r
4ff7e37b
ED
1083 @param[in, out] Destination The String to append onto.\r
1084 @param[in, out] CurrentSize On call, the number of bytes in Destination. On\r
1085 return, possibly the new size (still in bytes). If NULL,\r
1086 then allocate whatever is needed.\r
1087 @param[in] Source The String to append from.\r
1088 @param[in] Count The maximum number of characters to append. If 0, then\r
1089 all are appended.\r
125c2cf4 1090\r
a405b86d 1091 @return The Destination after appending the Source.\r
125c2cf4 1092**/\r
47d20b54 1093CHAR16 *\r
125c2cf4 1094EFIAPI\r
1095StrnCatGrow (\r
47d20b54
MK
1096 IN OUT CHAR16 **Destination,\r
1097 IN OUT UINTN *CurrentSize,\r
1098 IN CONST CHAR16 *Source,\r
1099 IN UINTN Count\r
125c2cf4 1100 );\r
2247dde4 1101\r
b3011f40 1102/**\r
1e6e84c7 1103 This is a find and replace function. Upon successful return the NewString is a copy of\r
b3011f40 1104 SourceString with each instance of FindTarget replaced with ReplaceWith.\r
1105\r
1106 If SourceString and NewString overlap the behavior is undefined.\r
1107\r
1108 If the string would grow bigger than NewSize it will halt and return error.\r
1109\r
4ff7e37b
ED
1110 @param[in] SourceString The string with source buffer.\r
1111 @param[in, out] NewString The string with resultant buffer.\r
1112 @param[in] NewSize The size in bytes of NewString.\r
1113 @param[in] FindTarget The string to look for.\r
1114 @param[in] ReplaceWith The string to replace FindTarget with.\r
1115 @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^'\r
1116 immediately before it.\r
1117 @param[in] ParameterReplacing If TRUE will add "" around items with spaces.\r
b3011f40 1118\r
1119 @retval EFI_INVALID_PARAMETER SourceString was NULL.\r
1120 @retval EFI_INVALID_PARAMETER NewString was NULL.\r
1121 @retval EFI_INVALID_PARAMETER FindTarget was NULL.\r
1122 @retval EFI_INVALID_PARAMETER ReplaceWith was NULL.\r
1123 @retval EFI_INVALID_PARAMETER FindTarget had length < 1.\r
1124 @retval EFI_INVALID_PARAMETER SourceString had length < 1.\r
1e6e84c7 1125 @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold\r
b3011f40 1126 the new string (truncation occurred).\r
a405b86d 1127 @retval EFI_SUCCESS The string was successfully copied with replacement.\r
b3011f40 1128**/\r
b3011f40 1129EFI_STATUS\r
1130EFIAPI\r
47d20b54
MK
1131ShellCopySearchAndReplace (\r
1132 IN CHAR16 CONST *SourceString,\r
1133 IN OUT CHAR16 *NewString,\r
1134 IN UINTN NewSize,\r
1135 IN CONST CHAR16 *FindTarget,\r
1136 IN CONST CHAR16 *ReplaceWith,\r
1137 IN CONST BOOLEAN SkipPreCarrot,\r
1138 IN CONST BOOLEAN ParameterReplacing\r
b3011f40 1139 );\r
1140\r
1141/**\r
1142 Check if a Unicode character is a hexadecimal character.\r
1143\r
1e6e84c7 1144 This internal function checks if a Unicode character is a\r
a405b86d 1145 numeric character. The valid hexadecimal characters are\r
b3011f40 1146 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
1147\r
b3011f40 1148\r
a405b86d 1149 @param Char The character to check against.\r
1150\r
1151 @retval TRUE The Char is a hexadecmial character.\r
1152 @retval FALSE The Char is not a hexadecmial character.\r
b3011f40 1153\r
1154**/\r
1155BOOLEAN\r
1156EFIAPI\r
969c783b 1157ShellIsHexaDecimalDigitCharacter (\r
47d20b54 1158 IN CHAR16 Char\r
b3011f40 1159 );\r
1160\r
a405b86d 1161/**\r
1162 Check if a Unicode character is a decimal character.\r
1163\r
1164 This internal function checks if a Unicode character is a\r
1165 decimal character. The valid characters are\r
1166 L'0' to L'9'.\r
1167\r
1168\r
1169 @param Char The character to check against.\r
1170\r
1171 @retval TRUE The Char is a hexadecmial character.\r
1172 @retval FALSE The Char is not a hexadecmial character.\r
1173\r
1174**/\r
1175BOOLEAN\r
1176EFIAPI\r
1177ShellIsDecimalDigitCharacter (\r
47d20b54 1178 IN CHAR16 Char\r
a405b86d 1179 );\r
1180\r
334f978e 1181///\r
a405b86d 1182/// What type of answer is requested.\r
334f978e 1183///\r
1184typedef enum {\r
a405b86d 1185 ShellPromptResponseTypeYesNo,\r
1186 ShellPromptResponseTypeYesNoCancel,\r
1187 ShellPromptResponseTypeFreeform,\r
1188 ShellPromptResponseTypeQuitContinue,\r
1189 ShellPromptResponseTypeYesNoAllCancel,\r
1190 ShellPromptResponseTypeEnterContinue,\r
1191 ShellPromptResponseTypeAnyKeyContinue,\r
1192 ShellPromptResponseTypeMax\r
334f978e 1193} SHELL_PROMPT_REQUEST_TYPE;\r
1194\r
1195///\r
a405b86d 1196/// What answer was given.\r
334f978e 1197///\r
1198typedef enum {\r
a405b86d 1199 ShellPromptResponseYes,\r
1200 ShellPromptResponseNo,\r
1201 ShellPromptResponseCancel,\r
1202 ShellPromptResponseQuit,\r
1203 ShellPromptResponseContinue,\r
1204 ShellPromptResponseAll,\r
1205 ShellPromptResponseMax\r
334f978e 1206} SHELL_PROMPT_RESPONSE;\r
1207\r
1208/**\r
1209 Prompt the user and return the resultant answer to the requestor.\r
1210\r
1211 This function will display the requested question on the shell prompt and then\r
1d322461 1212 wait for an appropriate answer to be input from the console.\r
334f978e 1213\r
a405b86d 1214 If the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue\r
334f978e 1215 or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.\r
1216\r
a405b86d 1217 If the SHELL_PROMPT_REQUEST_TYPE is ShellPromptResponseTypeFreeform then *Response is of type\r
334f978e 1218 CHAR16*.\r
1219\r
1220 In either case *Response must be callee freed if Response was not NULL;\r
1221\r
1222 @param Type What type of question is asked. This is used to filter the input\r
1223 to prevent invalid answers to question.\r
a405b86d 1224 @param Prompt The pointer to a string prompt used to request input.\r
1225 @param Response The pointer to Response, which will be populated upon return.\r
334f978e 1226\r
a405b86d 1227 @retval EFI_SUCCESS The operation was successful.\r
334f978e 1228 @retval EFI_UNSUPPORTED The operation is not supported as requested.\r
1229 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
1230 @return other The operation failed.\r
1231**/\r
1232EFI_STATUS\r
1233EFIAPI\r
1234ShellPromptForResponse (\r
47d20b54
MK
1235 IN SHELL_PROMPT_REQUEST_TYPE Type,\r
1236 IN CHAR16 *Prompt OPTIONAL,\r
1237 IN OUT VOID **Response OPTIONAL\r
334f978e 1238 );\r
1239\r
1240/**\r
1241 Prompt the user and return the resultant answer to the requestor.\r
1242\r
1243 This function is the same as ShellPromptForResponse, except that the prompt is\r
1244 automatically pulled from HII.\r
1245\r
4bbdc0e1 1246 @param[in] Type What type of question is asked. This is used to filter the input\r
334f978e 1247 to prevent invalid answers to question.\r
4ff7e37b
ED
1248 @param[in] HiiFormatStringId The format string Id for getting from Hii.\r
1249 @param[in] HiiFormatHandle The format string Handle for getting from Hii.\r
1250 @param[in, out] Response The pointer to Response, which will be populated upon return.\r
334f978e 1251\r
a405b86d 1252 @retval EFI_SUCCESS The operation was sucessful.\r
1253 @return other The operation failed.\r
334f978e 1254\r
1255 @sa ShellPromptForResponse\r
1256**/\r
1257EFI_STATUS\r
1258EFIAPI\r
1259ShellPromptForResponseHii (\r
47d20b54
MK
1260 IN SHELL_PROMPT_REQUEST_TYPE Type,\r
1261 IN CONST EFI_STRING_ID HiiFormatStringId,\r
1262 IN CONST EFI_HII_HANDLE HiiFormatHandle,\r
1263 IN OUT VOID **Response\r
334f978e 1264 );\r
1265\r
a405b86d 1266/**\r
1267 Function to determin if an entire string is a valid number.\r
1268\r
4bbdc0e1 1269 If Hex it must be preceeded with a 0x, 0X, or has ForceHex set TRUE.\r
a405b86d 1270\r
1271 @param[in] String The string to evaluate.\r
1272 @param[in] ForceHex TRUE - always assume hex.\r
1273 @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to keep going.\r
1274\r
1275 @retval TRUE It is all numeric (dec/hex) characters.\r
1276 @retval FALSE There is a non-numeric character.\r
1277**/\r
1278BOOLEAN\r
1279EFIAPI\r
1280ShellIsHexOrDecimalNumber (\r
1281 IN CONST CHAR16 *String,\r
1282 IN CONST BOOLEAN ForceHex,\r
1283 IN CONST BOOLEAN StopAtSpace\r
1284 );\r
1285\r
4bbdc0e1 1286/**\r
1287 Function to verify and convert a string to its numerical 64 bit representation.\r
1288\r
1289 If Hex it must be preceeded with a 0x, 0X, or has ForceHex set TRUE.\r
1290\r
1291 @param[in] String The string to evaluate.\r
1292 @param[out] Value Upon a successful return the value of the conversion.\r
1293 @param[in] ForceHex TRUE - always assume hex.\r
b0934ac4 1294 @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to\r
4bbdc0e1 1295 process the entire String.\r
b0934ac4 1296\r
4bbdc0e1 1297 @retval EFI_SUCCESS The conversion was successful.\r
1298 @retval EFI_INVALID_PARAMETER String contained an invalid character.\r
1299 @retval EFI_NOT_FOUND String was a number, but Value was NULL.\r
1300**/\r
1301EFI_STATUS\r
1302EFIAPI\r
47d20b54 1303ShellConvertStringToUint64 (\r
4bbdc0e1 1304 IN CONST CHAR16 *String,\r
47d20b54 1305 OUT UINT64 *Value,\r
4bbdc0e1 1306 IN CONST BOOLEAN ForceHex,\r
1307 IN CONST BOOLEAN StopAtSpace\r
1308 );\r
1309\r
a405b86d 1310/**\r
1311 Function to determine if a given filename exists.\r
1312\r
1313 @param[in] Name Path to test.\r
1314\r
1315 @retval EFI_SUCCESS The Path represents a file.\r
1316 @retval EFI_NOT_FOUND The Path does not represent a file.\r
1317 @retval other The path failed to open.\r
1318**/\r
1319EFI_STATUS\r
1320EFIAPI\r
47d20b54
MK
1321ShellFileExists (\r
1322 IN CONST CHAR16 *Name\r
a405b86d 1323 );\r
334f978e 1324\r
4d0a4fce 1325/**\r
1326 Function to read a single line from a SHELL_FILE_HANDLE. The \n is not included in the returned\r
1327 buffer. The returned buffer must be callee freed.\r
1328\r
1329 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
1330 maintained and not changed for all operations with the same file.\r
1331\r
4ff7e37b
ED
1332 @param[in] Handle SHELL_FILE_HANDLE to read from.\r
1333 @param[in, out] Ascii Boolean value for indicating whether the file is\r
1334 Ascii (TRUE) or UCS2 (FALSE).\r
4d0a4fce 1335\r
4ff7e37b 1336 @return The line of text from the file.\r
4d0a4fce 1337\r
1338 @sa ShellFileHandleReadLine\r
1339**/\r
47d20b54 1340CHAR16 *\r
4d0a4fce 1341EFIAPI\r
47d20b54
MK
1342ShellFileHandleReturnLine (\r
1343 IN SHELL_FILE_HANDLE Handle,\r
1344 IN OUT BOOLEAN *Ascii\r
4d0a4fce 1345 );\r
1346\r
1347/**\r
1348 Function to read a single line (up to but not including the \n) from a SHELL_FILE_HANDLE.\r
1349\r
1350 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
1351 maintained and not changed for all operations with the same file.\r
1352\r
4ff7e37b
ED
1353 @param[in] Handle SHELL_FILE_HANDLE to read from.\r
1354 @param[in, out] Buffer The pointer to buffer to read into.\r
1355 @param[in, out] Size The pointer to number of bytes in Buffer.\r
1356 @param[in] Truncate If the buffer is large enough, this has no effect.\r
1357 If the buffer is is too small and Truncate is TRUE,\r
1358 the line will be truncated.\r
1359 If the buffer is is too small and Truncate is FALSE,\r
1360 then no read will occur.\r
1361\r
1362 @param[in, out] Ascii Boolean value for indicating whether the file is\r
1363 Ascii (TRUE) or UCS2 (FALSE).\r
4d0a4fce 1364\r
1365 @retval EFI_SUCCESS The operation was successful. The line is stored in\r
1366 Buffer.\r
9ed21946 1367 @retval EFI_END_OF_FILE There are no more lines in the file.\r
4d0a4fce 1368 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
1369 @retval EFI_INVALID_PARAMETER Size was NULL.\r
1370 @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.\r
1371 Size was updated to the minimum space required.\r
1372**/\r
1373EFI_STATUS\r
1374EFIAPI\r
47d20b54
MK
1375ShellFileHandleReadLine (\r
1376 IN SHELL_FILE_HANDLE Handle,\r
1377 IN OUT CHAR16 *Buffer,\r
1378 IN OUT UINTN *Size,\r
1379 IN BOOLEAN Truncate,\r
1380 IN OUT BOOLEAN *Ascii\r
4d0a4fce 1381 );\r
1382\r
fb5278ef 1383/**\r
1384 Function to delete a file by name\r
ba0014b9 1385\r
fb5278ef 1386 @param[in] FileName Pointer to file name to delete.\r
ba0014b9 1387\r
fb5278ef 1388 @retval EFI_SUCCESS the file was deleted sucessfully\r
1389 @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
1390 deleted\r
1391 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
1392 @retval EFI_NOT_FOUND The specified file could not be found on the\r
1393 device or the file system could not be found\r
1394 on the device.\r
1395 @retval EFI_NO_MEDIA The device has no medium.\r
1396 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the\r
1397 medium is no longer supported.\r
1398 @retval EFI_DEVICE_ERROR The device reported an error.\r
1399 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
1400 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
1401 @retval EFI_ACCESS_DENIED The file was opened read only.\r
1402 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
1403 file.\r
1404 @retval other The file failed to open\r
1405**/\r
1406EFI_STATUS\r
1407EFIAPI\r
47d20b54
MK
1408ShellDeleteFileByName (\r
1409 IN CONST CHAR16 *FileName\r
fb5278ef 1410 );\r
1411\r
365aa98a 1412/**\r
1413 Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.\r
1414\r
1415 @param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed.\r
1416 @param[in] SectionToGetHelpOn Pointer to the section specifier(s).\r
ba0014b9 1417 @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints\r
365aa98a 1418 the help content only.\r
1419 @retval EFI_DEVICE_ERROR The help data format was incorrect.\r
1420 @retval EFI_NOT_FOUND The help data could not be found.\r
1421 @retval EFI_SUCCESS The operation was successful.\r
1422**/\r
1423EFI_STATUS\r
1424EFIAPI\r
1425ShellPrintHelp (\r
47d20b54
MK
1426 IN CONST CHAR16 *CommandToGetHelpOn,\r
1427 IN CONST CHAR16 *SectionToGetHelpOn,\r
1428 IN BOOLEAN PrintCommandText\r
365aa98a 1429 );\r
1430\r
e9880e25 1431#endif // __SHELL_LIB__\r