1 /** @file
2   Main file for NULL named library for level 2 shell command functions.
3 
4   these functions are:
5   attrib,   cd,   cp,   date*,  time*,  rm,   reset,
6   load,     ls,   map,  mkdir,  mv,     parse,  set,  timezone*
7 
8 
9   * functions are non-interactive only
10 
11 
12   Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
13   SPDX-License-Identifier: BSD-2-Clause-Patent
14 
15 **/
16 
17 #ifndef _UEFI_SHELL_LEVEL2_COMMANDS_LIB_H_
18 #define _UEFI_SHELL_LEVEL2_COMMANDS_LIB_H_
19 
20 #include <Uefi.h>
21 
22 #include <Guid/GlobalVariable.h>
23 #include <Guid/ShellLibHiiGuid.h>
24 
25 #include <Protocol/Shell.h>
26 #include <Protocol/ShellParameters.h>
27 #include <Protocol/DevicePath.h>
28 #include <Protocol/LoadedImage.h>
29 #include <Protocol/UnicodeCollation.h>
30 
31 #include <Library/BaseLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/PcdLib.h>
36 #include <Library/ShellCommandLib.h>
37 #include <Library/ShellLib.h>
38 #include <Library/UefiLib.h>
39 #include <Library/UefiRuntimeServicesTableLib.h>
40 #include <Library/UefiBootServicesTableLib.h>
41 #include <Library/HiiLib.h>
42 #include <Library/SortLib.h>
43 #include <Library/FileHandleLib.h>
44 
45 extern CONST  CHAR16                            mFileName[];
46 extern        EFI_HANDLE                        gShellLevel2HiiHandle;
47 
48 /**
49   Function for 'attrib' command.
50 
51   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
52   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
53 **/
54 SHELL_STATUS
55 EFIAPI
56 ShellCommandRunAttrib (
57   IN EFI_HANDLE        ImageHandle,
58   IN EFI_SYSTEM_TABLE  *SystemTable
59   );
60 
61 /**
62   Function for 'date' command.
63 
64   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
65   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
66 **/
67 SHELL_STATUS
68 EFIAPI
69 ShellCommandRunDate (
70   IN EFI_HANDLE        ImageHandle,
71   IN EFI_SYSTEM_TABLE  *SystemTable
72   );
73 
74 /**
75   Function for 'time' command.
76 
77   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
78   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
79 **/
80 SHELL_STATUS
81 EFIAPI
82 ShellCommandRunTime (
83   IN EFI_HANDLE        ImageHandle,
84   IN EFI_SYSTEM_TABLE  *SystemTable
85   );
86 
87 /**
88   Function for 'load' command.
89 
90   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
91   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
92 **/
93 SHELL_STATUS
94 EFIAPI
95 ShellCommandRunLoad (
96   IN EFI_HANDLE        ImageHandle,
97   IN EFI_SYSTEM_TABLE  *SystemTable
98   );
99 
100 /**
101   Function for 'ls' command.
102 
103   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
104   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
105 **/
106 SHELL_STATUS
107 EFIAPI
108 ShellCommandRunLs (
109   IN EFI_HANDLE        ImageHandle,
110   IN EFI_SYSTEM_TABLE  *SystemTable
111   );
112 
113 /**
114   Function for 'map' command.
115 
116   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
117   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
118 **/
119 SHELL_STATUS
120 EFIAPI
121 ShellCommandRunMap (
122   IN EFI_HANDLE        ImageHandle,
123   IN EFI_SYSTEM_TABLE  *SystemTable
124   );
125 
126 /**
127   Function for 'reset' command.
128 
129   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
130   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
131 **/
132 SHELL_STATUS
133 EFIAPI
134 ShellCommandRunReset (
135   IN EFI_HANDLE        ImageHandle,
136   IN EFI_SYSTEM_TABLE  *SystemTable
137   );
138 
139 /**
140   Function for 'timezone' command.
141 
142   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
143   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
144 **/
145 SHELL_STATUS
146 EFIAPI
147 ShellCommandRunTimeZone (
148   IN EFI_HANDLE        ImageHandle,
149   IN EFI_SYSTEM_TABLE  *SystemTable
150   );
151 
152 /**
153   Function for 'set' command.
154 
155   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
156   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
157 **/
158 SHELL_STATUS
159 EFIAPI
160 ShellCommandRunSet (
161   IN EFI_HANDLE        ImageHandle,
162   IN EFI_SYSTEM_TABLE  *SystemTable
163   );
164 
165 /**
166   Function for 'mkdir' command.
167 
168   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
169   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
170 **/
171 SHELL_STATUS
172 EFIAPI
173 ShellCommandRunMkDir (
174   IN EFI_HANDLE        ImageHandle,
175   IN EFI_SYSTEM_TABLE  *SystemTable
176   );
177 
178 /**
179   Function for 'cd' command.
180 
181   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
182   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
183 **/
184 SHELL_STATUS
185 EFIAPI
186 ShellCommandRunCd (
187   IN EFI_HANDLE        ImageHandle,
188   IN EFI_SYSTEM_TABLE  *SystemTable
189   );
190 
191 /**
192   Function for 'cp' command.
193 
194   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
195   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
196 **/
197 SHELL_STATUS
198 EFIAPI
199 ShellCommandRunCp (
200   IN EFI_HANDLE        ImageHandle,
201   IN EFI_SYSTEM_TABLE  *SystemTable
202   );
203 
204 /**
205   Function for 'parse' command.
206 
207   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
208   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
209 **/
210 SHELL_STATUS
211 EFIAPI
212 ShellCommandRunParse (
213   IN EFI_HANDLE        ImageHandle,
214   IN EFI_SYSTEM_TABLE  *SystemTable
215   );
216 
217 /**
218   Function for 'rm' command.
219 
220   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
221   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
222 **/
223 SHELL_STATUS
224 EFIAPI
225 ShellCommandRunRm (
226   IN EFI_HANDLE        ImageHandle,
227   IN EFI_SYSTEM_TABLE  *SystemTable
228   );
229 
230 /**
231   Function for 'mv' command.
232 
233   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
234   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
235 **/
236 SHELL_STATUS
237 EFIAPI
238 ShellCommandRunMv (
239   IN EFI_HANDLE        ImageHandle,
240   IN EFI_SYSTEM_TABLE  *SystemTable
241   );
242 
243 /**
244   returns a fully qualified directory (contains a map drive at the begining)
245   path from a unknown directory path.
246 
247   If Path is already fully qualified this will return a duplicat otherwise this
248   will use get the current directory and use that to build the fully qualified
249   version.
250 
251   if the return value is not NULL it must be caller freed.
252 
253   @param[in] Path         The unknown Path Value
254 
255   @retval NULL            A memory allocation failed
256   @retval NULL            a fully qualified path could not be discovered.
257   @retval other           pointer to a fuly qualified path.
258 **/
259 CHAR16*
260 GetFullyQualifiedPath(
261   IN CONST CHAR16* Path
262   );
263 
264 /**
265   Function to verify all intermediate directories in the path.
266 
267   @param[in] Path       The pointer to the path to fix.
268 
269   @retval EFI_SUCCESS   The operation was successful.
270 **/
271 EFI_STATUS
272 VerifyIntermediateDirectories (
273   IN CONST CHAR16 *Path
274   );
275 
276 /**
277   String comparison without regard to case for a limited number of characters.
278 
279   @param[in] Source   The first item to compare.
280   @param[in] Target   The second item to compare.
281   @param[in] Count    How many characters to compare.
282 
283   @retval 0    Source and Target are identical strings without regard to case.
284   @retval !=0  Source is not identical to Target.
285 
286 **/
287 INTN
288 StrniCmp(
289   IN CONST CHAR16 *Source,
290   IN CONST CHAR16 *Target,
291   IN CONST UINTN  Count
292   );
293 
294 /**
295   Cleans off all the quotes in the string.
296 
297   @param[in]     OriginalString   pointer to the string to be cleaned.
298   @param[out]   CleanString      The new string with all quotes removed.
299                                                   Memory allocated in the function and free
300                                                   by caller.
301 
302   @retval EFI_SUCCESS   The operation was successful.
303 **/
304 EFI_STATUS
305 ShellLevel2StripQuotes (
306   IN  CONST CHAR16     *OriginalString,
307   OUT CHAR16           **CleanString
308   );
309 
310 /**
311   Function for 'Vol' command.
312 
313   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
314   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
315 **/
316 SHELL_STATUS
317 EFIAPI
318 ShellCommandRunVol (
319   IN EFI_HANDLE        ImageHandle,
320   IN EFI_SYSTEM_TABLE  *SystemTable
321   );
322 
323 /**
324   Function to Copy one file to another location
325 
326   If the destination exists the user will be prompted and the result put into *resp
327 
328   @param[in] Source     pointer to source file name
329   @param[in] Dest       pointer to destination file name
330   @param[out] Resp      pointer to response from question.  Pass back on looped calling
331   @param[in] SilentMode whether to run in quiet mode or not
332   @param[in] CmdName    Source command name requesting single file copy
333 
334   @retval SHELL_SUCCESS   The source file was copied to the destination
335 **/
336 SHELL_STATUS
337 CopySingleFile(
338   IN CONST CHAR16 *Source,
339   IN CONST CHAR16 *Dest,
340   OUT VOID        **Resp,
341   IN BOOLEAN      SilentMode,
342   IN CONST CHAR16 *CmdName
343   );
344 
345 /**
346   Delete a node and all nodes under it (including sub directories).
347 
348   @param[in] Node   The node to start deleting with.
349   @param[in] Quiet  TRUE to print no messages.
350 
351   @retval SHELL_SUCCESS       The operation was successful.
352   @retval SHELL_ACCESS_DENIED A file was read only.
353   @retval SHELL_ABORTED       The abort message was received.
354   @retval SHELL_DEVICE_ERROR  A device error occured reading this Node.
355 **/
356 SHELL_STATUS
357 CascadeDelete(
358   IN EFI_SHELL_FILE_INFO  *Node,
359   IN CONST BOOLEAN        Quiet
360   );
361 
362 #endif
363 
364