]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Main file for mv shell level 2 function.\r | |
3 | \r | |
83c7a556 CP |
4 | (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r |
5 | Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r | |
a405b86d | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "UefiShellLevel2CommandsLib.h"\r | |
17 | \r | |
18 | /**\r | |
19 | Function to validate that moving a specific file (FileName) to a specific\r | |
20 | location (DestPath) is valid.\r | |
21 | \r | |
22 | This function will verify that the destination is not a subdirectory of\r | |
23 | FullName, that the Current working Directory is not being moved, and that\r | |
24 | the directory is not read only.\r | |
25 | \r | |
26 | if the move is invalid this function will report the error to StdOut.\r | |
27 | \r | |
28 | @param FullName [in] The name of the file to move.\r | |
29 | @param Cwd [in] The current working directory\r | |
30 | @param DestPath [in] The target location to move to\r | |
31 | @param Attribute[in] The Attribute of the file\r | |
83c7a556 | 32 | @param FileStatus[in] The Status of the file when opened\r |
a405b86d | 33 | \r |
34 | @retval TRUE The move is valid\r | |
35 | @retval FALSE The move is not\r | |
36 | **/\r | |
37 | BOOLEAN\r | |
38 | EFIAPI\r | |
39 | IsValidMove(\r | |
83c7a556 CP |
40 | IN CONST CHAR16 *FullName,\r |
41 | IN CONST CHAR16 *Cwd,\r | |
42 | IN CONST CHAR16 *DestPath,\r | |
43 | IN CONST UINT64 Attribute,\r | |
44 | IN CONST EFI_STATUS FileStatus\r | |
a405b86d | 45 | )\r |
46 | {\r | |
47 | CHAR16 *Test;\r | |
48 | CHAR16 *Test1;\r | |
49 | CHAR16 *TestWalker;\r | |
3e082d58 | 50 | INTN Result;\r |
a405b86d | 51 | UINTN TempLen;\r |
52 | if (Cwd != NULL && StrCmp(FullName, Cwd) == 0) {\r | |
53 | //\r | |
54 | // Invalid move\r | |
55 | //\r | |
56 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);\r | |
57 | return (FALSE);\r | |
58 | }\r | |
59 | Test = NULL;\r | |
60 | Test = StrnCatGrow(&Test, NULL, DestPath, 0);\r | |
61 | TestWalker = Test;\r | |
62 | ASSERT(TestWalker != NULL);\r | |
63 | while(*TestWalker == L'\\') {\r | |
64 | TestWalker++;\r | |
65 | }\r | |
66 | while(TestWalker != NULL && TestWalker[StrLen(TestWalker)-1] == L'\\') {\r | |
67 | TestWalker[StrLen(TestWalker)-1] = CHAR_NULL;\r | |
68 | }\r | |
69 | ASSERT(TestWalker != NULL);\r | |
70 | ASSERT(FullName != NULL);\r | |
71 | if (StrStr(FullName, TestWalker) != 0) {\r | |
72 | TempLen = StrLen(FullName);\r | |
73 | if (StrStr(FullName, TestWalker) != FullName // not the first items... (could below it)\r | |
74 | && TempLen <= (StrLen(TestWalker) + 1)\r | |
75 | && StrStr(FullName+StrLen(TestWalker) + 1, L"\\") == NULL) {\r | |
76 | //\r | |
77 | // Invalid move\r | |
78 | //\r | |
79 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);\r | |
80 | FreePool(Test);\r | |
81 | return (FALSE);\r | |
82 | }\r | |
83 | }\r | |
84 | FreePool(Test);\r | |
85 | if (StrStr(DestPath, FullName) != 0 && StrStr(DestPath, FullName) != DestPath) {\r | |
86 | //\r | |
87 | // Invalid move\r | |
88 | //\r | |
89 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);\r | |
90 | return (FALSE);\r | |
91 | }\r | |
83c7a556 | 92 | if (((Attribute & EFI_FILE_READ_ONLY) != 0) || (FileStatus == EFI_WRITE_PROTECTED)) {\r |
a405b86d | 93 | //\r |
94 | // invalid to move read only\r | |
95 | //\r | |
83c7a556 | 96 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle, FullName);\r |
a405b86d | 97 | return (FALSE);\r |
98 | }\r | |
99 | Test = StrStr(FullName, L":");\r | |
100 | Test1 = StrStr(DestPath, L":");\r | |
101 | if (Test1 != NULL && Test != NULL) {\r | |
102 | *Test = CHAR_NULL;\r | |
103 | *Test1 = CHAR_NULL;\r | |
104 | Result = StringNoCaseCompare(&FullName, &DestPath);\r | |
105 | *Test = L':';\r | |
106 | *Test1 = L':';\r | |
107 | if (Result != 0) {\r | |
108 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_FS), gShellLevel2HiiHandle);\r | |
109 | return (FALSE);\r | |
110 | }\r | |
111 | }\r | |
112 | return (TRUE);\r | |
113 | }\r | |
114 | \r | |
115 | /**\r | |
116 | Function to take a destination path that might contain wildcards and verify\r | |
117 | that there is only a single possible target (IE we cant have wildcards that\r | |
118 | have 2 possible destination).\r | |
119 | \r | |
120 | if the result is sucessful the caller must free *DestPathPointer.\r | |
121 | \r | |
4ff7e37b ED |
122 | @param[in] DestDir The original path to the destination.\r |
123 | @param[in, out] DestPathPointer A pointer to the callee allocated final path.\r | |
124 | @param[in] Cwd A pointer to the current working directory.\r | |
a405b86d | 125 | \r |
beab0fc5 | 126 | @retval SHELL_INVALID_PARAMETER The DestDir could not be resolved to a location.\r |
127 | @retval SHELL_INVALID_PARAMETER The DestDir could be resolved to more than 1 location.\r | |
128 | @retval SHELL_INVALID_PARAMETER Cwd is required and is NULL.\r | |
129 | @retval SHELL_SUCCESS The operation was sucessful.\r | |
a405b86d | 130 | **/\r |
131 | SHELL_STATUS\r | |
132 | EFIAPI\r | |
133 | GetDestinationLocation(\r | |
134 | IN CONST CHAR16 *DestDir,\r | |
135 | IN OUT CHAR16 **DestPathPointer,\r | |
136 | IN CONST CHAR16 *Cwd\r | |
137 | )\r | |
138 | {\r | |
139 | EFI_SHELL_FILE_INFO *DestList;\r | |
140 | EFI_SHELL_FILE_INFO *Node;\r | |
a405b86d | 141 | CHAR16 *DestPath;\r |
a405b86d | 142 | UINTN NewSize;\r |
c32ad351 | 143 | UINTN CurrentSize;\r |
a405b86d | 144 | \r |
145 | DestList = NULL;\r | |
146 | DestPath = NULL;\r | |
b54fd049 | 147 | \r |
148 | if (StrStr(DestDir, L"\\") == DestDir) {\r | |
beab0fc5 | 149 | if (Cwd == NULL) {\r |
150 | return SHELL_INVALID_PARAMETER;\r | |
151 | }\r | |
b54fd049 | 152 | DestPath = AllocateZeroPool(StrSize(Cwd));\r |
153 | if (DestPath == NULL) {\r | |
154 | return (SHELL_OUT_OF_RESOURCES);\r | |
155 | }\r | |
156 | StrCpy(DestPath, Cwd);\r | |
ab94587a | 157 | while (PathRemoveLastItem(DestPath)) ;\r |
c32ad351 CP |
158 | \r |
159 | //\r | |
160 | // Append DestDir beyond '\' which may be present\r | |
161 | //\r | |
162 | CurrentSize = StrSize(DestPath);\r | |
163 | StrnCatGrow(&DestPath, &CurrentSize, &DestDir[1], 0);\r | |
164 | \r | |
b54fd049 | 165 | *DestPathPointer = DestPath;\r |
166 | return (SHELL_SUCCESS);\r | |
167 | }\r | |
a405b86d | 168 | //\r |
169 | // get the destination path\r | |
170 | //\r | |
e755a4ca | 171 | ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);\r |
a405b86d | 172 | if (DestList == NULL || IsListEmpty(&DestList->Link)) {\r |
173 | //\r | |
174 | // Not existing... must be renaming\r | |
175 | //\r | |
5051c287 | 176 | if (StrStr(DestDir, L":") == NULL) {\r |
beab0fc5 | 177 | if (Cwd == NULL) {\r |
178 | ShellCloseFileMetaArg(&DestList);\r | |
179 | return (SHELL_INVALID_PARAMETER);\r | |
180 | }\r | |
a405b86d | 181 | NewSize = StrSize(Cwd);\r |
182 | NewSize += StrSize(DestDir);\r | |
183 | DestPath = AllocateZeroPool(NewSize);\r | |
9ea69f8a | 184 | if (DestPath == NULL) {\r |
185 | ShellCloseFileMetaArg(&DestList);\r | |
186 | return (SHELL_OUT_OF_RESOURCES);\r | |
187 | }\r | |
a405b86d | 188 | StrCpy(DestPath, Cwd);\r |
189 | if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {\r | |
190 | StrCat(DestPath, L"\\");\r | |
191 | } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {\r | |
192 | ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r | |
193 | }\r | |
194 | StrCat(DestPath, DestDir);\r | |
195 | } else {\r | |
196 | ASSERT(DestPath == NULL);\r | |
197 | DestPath = StrnCatGrow(&DestPath, NULL, DestDir, 0);\r | |
9ea69f8a | 198 | if (DestPath == NULL) {\r |
199 | ShellCloseFileMetaArg(&DestList);\r | |
200 | return (SHELL_OUT_OF_RESOURCES);\r | |
201 | }\r | |
a405b86d | 202 | }\r |
203 | } else {\r | |
204 | Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);\r | |
205 | //\r | |
206 | // Make sure there is only 1 node in the list.\r | |
207 | //\r | |
208 | if (!IsNodeAtEnd(&DestList->Link, &Node->Link)) {\r | |
209 | ShellCloseFileMetaArg(&DestList);\r | |
210 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);\r | |
211 | return (SHELL_INVALID_PARAMETER);\r | |
212 | }\r | |
213 | if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS) {\r | |
214 | DestPath = AllocateZeroPool(StrSize(Node->FullName)+sizeof(CHAR16));\r | |
9ea69f8a | 215 | if (DestPath == NULL) {\r |
216 | ShellCloseFileMetaArg(&DestList);\r | |
217 | return (SHELL_OUT_OF_RESOURCES);\r | |
218 | }\r | |
a405b86d | 219 | StrCpy(DestPath, Node->FullName);\r |
220 | StrCat(DestPath, L"\\");\r | |
221 | } else {\r | |
222 | //\r | |
223 | // cant move onto another file.\r | |
224 | //\r | |
225 | ShellCloseFileMetaArg(&DestList);\r | |
226 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, DestDir);\r | |
227 | return (SHELL_INVALID_PARAMETER);\r | |
228 | }\r | |
229 | }\r | |
230 | \r | |
231 | *DestPathPointer = DestPath;\r | |
232 | ShellCloseFileMetaArg(&DestList);\r | |
233 | \r | |
234 | return (SHELL_SUCCESS);\r | |
235 | }\r | |
236 | \r | |
237 | /**\r | |
238 | function to take a list of files to move and a destination location and do\r | |
239 | the verification and moving of those files to that location. This function\r | |
240 | will report any errors to the user and continue to move the rest of the files.\r | |
241 | \r | |
242 | @param[in] FileList A LIST_ENTRY* based list of files to move\r | |
b54fd049 | 243 | @param[out] Resp pointer to response from question. Pass back on looped calling\r |
a405b86d | 244 | @param[in] DestDir the destination location\r |
245 | \r | |
246 | @retval SHELL_SUCCESS the files were all moved.\r | |
247 | @retval SHELL_INVALID_PARAMETER a parameter was invalid\r | |
248 | @retval SHELL_SECURITY_VIOLATION a security violation ocurred\r | |
249 | @retval SHELL_WRITE_PROTECTED the destination was write protected\r | |
250 | @retval SHELL_OUT_OF_RESOURCES a memory allocation failed\r | |
251 | **/\r | |
252 | SHELL_STATUS\r | |
253 | EFIAPI\r | |
254 | ValidateAndMoveFiles(\r | |
255 | IN CONST EFI_SHELL_FILE_INFO *FileList,\r | |
b54fd049 | 256 | OUT VOID **Resp,\r |
a405b86d | 257 | IN CONST CHAR16 *DestDir\r |
258 | )\r | |
259 | {\r | |
260 | EFI_STATUS Status;\r | |
261 | CHAR16 *HiiOutput;\r | |
262 | CHAR16 *HiiResultOk;\r | |
263 | CHAR16 *DestPath;\r | |
264 | CONST CHAR16 *Cwd;\r | |
265 | SHELL_STATUS ShellStatus;\r | |
266 | CONST EFI_SHELL_FILE_INFO *Node;\r | |
267 | EFI_FILE_INFO *NewFileInfo;\r | |
268 | CHAR16 *TempLocation;\r | |
269 | UINTN NewSize;\r | |
3e082d58 | 270 | UINTN Length;\r |
b54fd049 | 271 | VOID *Response;\r |
272 | SHELL_FILE_HANDLE DestHandle;\r | |
a405b86d | 273 | \r |
274 | ASSERT(FileList != NULL);\r | |
275 | ASSERT(DestDir != NULL);\r | |
276 | \r | |
277 | DestPath = NULL;\r | |
278 | Cwd = ShellGetCurrentDir(NULL);\r | |
b54fd049 | 279 | Response = *Resp;\r |
a405b86d | 280 | \r |
281 | //\r | |
282 | // Get and validate the destination location\r | |
283 | //\r | |
284 | ShellStatus = GetDestinationLocation(DestDir, &DestPath, Cwd);\r | |
285 | if (ShellStatus != SHELL_SUCCESS) {\r | |
286 | return (ShellStatus);\r | |
287 | }\r | |
ab94587a | 288 | DestPath = PathCleanUpDirectories(DestPath);\r |
a405b86d | 289 | \r |
290 | HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);\r | |
291 | HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);\r | |
292 | ASSERT (DestPath != NULL);\r | |
293 | ASSERT (HiiResultOk != NULL);\r | |
294 | ASSERT (HiiOutput != NULL);\r | |
a405b86d | 295 | \r |
296 | //\r | |
297 | // Go through the list of files and directories to move...\r | |
298 | //\r | |
299 | for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)\r | |
300 | ; !IsNull(&FileList->Link, &Node->Link)\r | |
301 | ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)\r | |
302 | ){\r | |
303 | if (ShellGetExecutionBreakFlag()) {\r | |
304 | break;\r | |
305 | }\r | |
83c7a556 CP |
306 | \r |
307 | //\r | |
308 | // These should never be NULL\r | |
309 | //\r | |
a405b86d | 310 | ASSERT(Node->FileName != NULL);\r |
311 | ASSERT(Node->FullName != NULL);\r | |
83c7a556 | 312 | ASSERT(Node->Info != NULL);\r |
a405b86d | 313 | \r |
314 | //\r | |
315 | // skip the directory traversing stuff...\r | |
316 | //\r | |
317 | if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {\r | |
318 | continue;\r | |
319 | }\r | |
320 | \r | |
321 | //\r | |
322 | // Validate that the move is valid\r | |
323 | //\r | |
83c7a556 | 324 | if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute, Node->Status)) {\r |
a405b86d | 325 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
326 | continue;\r | |
327 | }\r | |
328 | \r | |
329 | //\r | |
330 | // Chop off map info from "DestPath"\r | |
331 | //\r | |
332 | if ((TempLocation = StrStr(DestPath, L":")) != NULL) {\r | |
333 | CopyMem(DestPath, TempLocation+1, StrSize(TempLocation+1));\r | |
334 | }\r | |
335 | \r | |
336 | //\r | |
337 | // construct the new file info block\r | |
338 | //\r | |
339 | NewSize = StrSize(DestPath);\r | |
73c83c69 | 340 | NewSize += StrSize(Node->FileName) + SIZE_OF_EFI_FILE_INFO + sizeof(CHAR16);\r |
a405b86d | 341 | NewFileInfo = AllocateZeroPool(NewSize);\r |
9ea69f8a | 342 | if (NewFileInfo == NULL) {\r |
343 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);\r | |
344 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
a405b86d | 345 | } else {\r |
73c83c69 | 346 | CopyMem(NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);\r |
9ea69f8a | 347 | if (DestPath[0] != L'\\') {\r |
348 | StrCpy(NewFileInfo->FileName, L"\\");\r | |
349 | StrCat(NewFileInfo->FileName, DestPath);\r | |
350 | } else {\r | |
351 | StrCpy(NewFileInfo->FileName, DestPath);\r | |
a405b86d | 352 | }\r |
3e082d58 | 353 | Length = StrLen(NewFileInfo->FileName);\r |
354 | if (Length > 0) {\r | |
355 | Length--;\r | |
356 | }\r | |
357 | if (NewFileInfo->FileName[Length] == L'\\') {\r | |
9ea69f8a | 358 | if (Node->FileName[0] == L'\\') {\r |
359 | //\r | |
360 | // Don't allow for double slashes. Eliminate one of them.\r | |
361 | //\r | |
3e082d58 | 362 | NewFileInfo->FileName[Length] = CHAR_NULL;\r |
9ea69f8a | 363 | }\r |
364 | StrCat(NewFileInfo->FileName, Node->FileName);\r | |
365 | }\r | |
73c83c69 | 366 | NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);\r |
9ea69f8a | 367 | ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);\r |
a405b86d | 368 | \r |
b54fd049 | 369 | if (!EFI_ERROR(ShellFileExists(NewFileInfo->FileName))) {\r |
370 | if (Response == NULL) {\r | |
371 | ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);\r | |
372 | }\r | |
373 | switch (*(SHELL_PROMPT_RESPONSE*)Response) {\r | |
374 | case ShellPromptResponseNo:\r | |
375 | FreePool(NewFileInfo);\r | |
376 | continue;\r | |
377 | case ShellPromptResponseCancel:\r | |
378 | *Resp = Response;\r | |
379 | //\r | |
380 | // indicate to stop everything\r | |
381 | //\r | |
382 | FreePool(NewFileInfo);\r | |
383 | FreePool(DestPath);\r | |
384 | FreePool(HiiOutput);\r | |
385 | FreePool(HiiResultOk);\r | |
386 | return (SHELL_ABORTED);\r | |
387 | case ShellPromptResponseAll:\r | |
388 | *Resp = Response;\r | |
389 | break;\r | |
390 | case ShellPromptResponseYes:\r | |
391 | FreePool(Response);\r | |
392 | break;\r | |
393 | default:\r | |
394 | FreePool(Response);\r | |
395 | FreePool(NewFileInfo);\r | |
396 | FreePool(DestPath);\r | |
397 | FreePool(HiiOutput);\r | |
398 | FreePool(HiiResultOk);\r | |
399 | return SHELL_ABORTED;\r | |
400 | }\r | |
401 | Status = ShellOpenFileByName(NewFileInfo->FileName, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);\r | |
402 | ShellDeleteFile(&DestHandle);\r | |
403 | }\r | |
404 | \r | |
405 | \r | |
9ea69f8a | 406 | //\r |
407 | // Perform the move operation\r | |
408 | //\r | |
409 | Status = ShellSetFileInfo(Node->Handle, NewFileInfo);\r | |
a405b86d | 410 | \r |
9ea69f8a | 411 | //\r |
412 | // Free the info object we used...\r | |
413 | //\r | |
9ea69f8a | 414 | FreePool(NewFileInfo);\r |
a405b86d | 415 | \r |
a405b86d | 416 | //\r |
9ea69f8a | 417 | // Check our result\r |
a405b86d | 418 | //\r |
9ea69f8a | 419 | if (EFI_ERROR(Status)) {\r |
420 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);\r | |
cbcccd2c LG |
421 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
422 | if (Status == EFI_SECURITY_VIOLATION) {\r | |
423 | ShellStatus = SHELL_SECURITY_VIOLATION;\r | |
424 | } else if (Status == EFI_WRITE_PROTECTED) {\r | |
425 | ShellStatus = SHELL_WRITE_PROTECTED;\r | |
426 | } else if (Status == EFI_OUT_OF_RESOURCES) {\r | |
427 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
428 | } else if (Status == EFI_DEVICE_ERROR) {\r | |
429 | ShellStatus = SHELL_DEVICE_ERROR;\r | |
430 | } else if (Status == EFI_ACCESS_DENIED) {\r | |
431 | ShellStatus = SHELL_ACCESS_DENIED;\r | |
432 | }\r | |
9ea69f8a | 433 | } else {\r |
434 | ShellPrintEx(-1, -1, L"%s", HiiResultOk);\r | |
435 | }\r | |
a405b86d | 436 | }\r |
437 | } // for loop\r | |
438 | \r | |
439 | FreePool(DestPath);\r | |
440 | FreePool(HiiOutput);\r | |
441 | FreePool(HiiResultOk);\r | |
442 | return (ShellStatus);\r | |
443 | }\r | |
444 | \r | |
b54fd049 | 445 | /**\r |
446 | Function for 'mv' command.\r | |
447 | \r | |
448 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
449 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
450 | **/\r | |
a405b86d | 451 | SHELL_STATUS\r |
452 | EFIAPI\r | |
453 | ShellCommandRunMv (\r | |
454 | IN EFI_HANDLE ImageHandle,\r | |
455 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
456 | )\r | |
457 | {\r | |
458 | EFI_STATUS Status;\r | |
459 | LIST_ENTRY *Package;\r | |
460 | CHAR16 *ProblemParam;\r | |
461 | SHELL_STATUS ShellStatus;\r | |
462 | UINTN ParamCount;\r | |
463 | UINTN LoopCounter;\r | |
464 | EFI_SHELL_FILE_INFO *FileList;\r | |
b54fd049 | 465 | VOID *Response;\r |
a405b86d | 466 | \r |
467 | ProblemParam = NULL;\r | |
468 | ShellStatus = SHELL_SUCCESS;\r | |
469 | ParamCount = 0;\r | |
470 | FileList = NULL;\r | |
b54fd049 | 471 | Response = NULL;\r |
a405b86d | 472 | \r |
473 | //\r | |
474 | // initialize the shell lib (we must be in non-auto-init...)\r | |
475 | //\r | |
476 | Status = ShellInitialize();\r | |
477 | ASSERT_EFI_ERROR(Status);\r | |
478 | \r | |
479 | //\r | |
480 | // parse the command line\r | |
481 | //\r | |
482 | Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r | |
483 | if (EFI_ERROR(Status)) {\r | |
484 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
485 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r | |
486 | FreePool(ProblemParam);\r | |
487 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
488 | } else {\r | |
489 | ASSERT(FALSE);\r | |
490 | }\r | |
491 | } else {\r | |
492 | //\r | |
493 | // check for "-?"\r | |
494 | //\r | |
495 | if (ShellCommandLineGetFlag(Package, L"-?")) {\r | |
496 | ASSERT(FALSE);\r | |
497 | }\r | |
498 | \r | |
499 | switch (ParamCount = ShellCommandLineGetCount(Package)) {\r | |
500 | case 0:\r | |
501 | case 1:\r | |
502 | //\r | |
503 | // we have insufficient parameters\r | |
504 | //\r | |
505 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);\r | |
506 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
507 | break;\r | |
508 | case 2:\r | |
509 | //\r | |
510 | // must have valid CWD for single parameter...\r | |
511 | //\r | |
512 | if (ShellGetCurrentDir(NULL) == NULL){\r | |
513 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r | |
514 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
515 | } else {\r | |
516 | Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);\r | |
517 | if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {\r | |
518 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r | |
519 | ShellStatus = SHELL_NOT_FOUND;\r | |
520 | } else {\r | |
521 | //\r | |
522 | // ValidateAndMoveFiles will report errors to the screen itself\r | |
523 | //\r | |
b54fd049 | 524 | ShellStatus = ValidateAndMoveFiles(FileList, &Response, ShellGetCurrentDir(NULL));\r |
a405b86d | 525 | }\r |
526 | }\r | |
527 | \r | |
528 | break;\r | |
529 | default:\r | |
530 | ///@todo make sure this works with error half way through and continues...\r | |
b54fd049 | 531 | for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount ; LoopCounter++) {\r |
a405b86d | 532 | if (ShellGetExecutionBreakFlag()) {\r |
533 | break;\r | |
534 | }\r | |
535 | Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);\r | |
536 | if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {\r | |
b54fd049 | 537 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter));\r |
a405b86d | 538 | ShellStatus = SHELL_NOT_FOUND;\r |
539 | } else {\r | |
540 | //\r | |
541 | // ValidateAndMoveFiles will report errors to the screen itself\r | |
542 | // Only change ShellStatus if it's sucessful\r | |
543 | //\r | |
544 | if (ShellStatus == SHELL_SUCCESS) {\r | |
b54fd049 | 545 | ShellStatus = ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount));\r |
a405b86d | 546 | } else {\r |
b54fd049 | 547 | ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount));\r |
a405b86d | 548 | }\r |
549 | }\r | |
550 | if (FileList != NULL && !IsListEmpty(&FileList->Link)) {\r | |
551 | Status = ShellCloseFileMetaArg(&FileList);\r | |
552 | if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {\r | |
553 | ShellStatus = SHELL_ACCESS_DENIED;\r | |
554 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);\r | |
555 | }\r | |
556 | }\r | |
557 | }\r | |
558 | break;\r | |
559 | } // switch on parameter count\r | |
560 | \r | |
561 | if (FileList != NULL) {\r | |
562 | ShellCloseFileMetaArg(&FileList);\r | |
563 | }\r | |
564 | \r | |
565 | //\r | |
566 | // free the command line package\r | |
567 | //\r | |
568 | ShellCommandLineFreeVarList (Package);\r | |
569 | }\r | |
570 | \r | |
b54fd049 | 571 | SHELL_FREE_NON_NULL(Response);\r |
572 | \r | |
a405b86d | 573 | if (ShellGetExecutionBreakFlag()) {\r |
574 | return (SHELL_ABORTED);\r | |
575 | }\r | |
576 | \r | |
577 | return (ShellStatus);\r | |
578 | }\r |