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