]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c
ShellPkg:Fix bug in FileBuffer.c
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SetSize.c
CommitLineData
5d73d92f 1/** @file\r
2 Main file for SetSize shell Debug1 function.\r
3\r
c011b6c9 4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
ba0014b9 5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
56ba3746 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
5d73d92f 7\r
8**/\r
9\r
10#include "UefiShellDebug1CommandsLib.h"\r
11\r
3737ac2b 12/**\r
13 Function for 'setsize' command.\r
14\r
15 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
16 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
17**/\r
5d73d92f 18SHELL_STATUS\r
19EFIAPI\r
20ShellCommandRunSetSize (\r
21 IN EFI_HANDLE ImageHandle,\r
22 IN EFI_SYSTEM_TABLE *SystemTable\r
23 )\r
24{\r
25 EFI_STATUS Status;\r
26 LIST_ENTRY *Package;\r
27 CHAR16 *ProblemParam;\r
28 SHELL_STATUS ShellStatus;\r
29 CONST CHAR16 *Temp1;\r
30 UINTN NewSize;\r
31 UINTN LoopVar;\r
32 SHELL_FILE_HANDLE FileHandle;\r
33\r
34 ShellStatus = SHELL_SUCCESS;\r
35 Status = EFI_SUCCESS;\r
36\r
37 //\r
38 // initialize the shell lib (we must be in non-auto-init...)\r
39 //\r
40 Status = ShellInitialize();\r
41 ASSERT_EFI_ERROR(Status);\r
42\r
43 Status = CommandInit();\r
44 ASSERT_EFI_ERROR(Status);\r
45\r
46 //\r
47 // parse the command line\r
48 //\r
49 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r
50 if (EFI_ERROR(Status)) {\r
51 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
ba0014b9 52 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam);\r
5d73d92f 53 FreePool(ProblemParam);\r
54 ShellStatus = SHELL_INVALID_PARAMETER;\r
55 } else {\r
56 ASSERT(FALSE);\r
57 }\r
58 } else {\r
3737ac2b 59 if (ShellCommandLineGetCount(Package) < 3) {\r
ba0014b9 60 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize");\r
5d73d92f 61 ShellStatus = SHELL_INVALID_PARAMETER;\r
62 NewSize = 0;\r
63 } else {\r
3737ac2b 64 Temp1 = ShellCommandLineGetRawValue(Package, 1);\r
65 if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) {\r
ba0014b9 66 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");\r
3737ac2b 67 ShellStatus = SHELL_INVALID_PARAMETER;\r
68 NewSize = 0;\r
69 } else {\r
70 NewSize = ShellStrToUintn(Temp1);\r
71 }\r
5d73d92f 72 }\r
73 for (LoopVar = 2 ; LoopVar < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS ; LoopVar++) {\r
3737ac2b 74 Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);\r
75 if (EFI_ERROR(Status)) {\r
76 Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
77 }\r
5d73d92f 78 if (EFI_ERROR(Status) && LoopVar == 2) {\r
ba0014b9 79 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");\r
5d73d92f 80 ShellStatus = SHELL_INVALID_PARAMETER;\r
81 } else if (EFI_ERROR(Status)) {\r
ba0014b9 82 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue(Package, LoopVar));\r
3737ac2b 83 ShellStatus = SHELL_INVALID_PARAMETER;\r
5d73d92f 84 break;\r
85 } else {\r
86 Status = FileHandleSetSize(FileHandle, NewSize);\r
87 if (Status == EFI_VOLUME_FULL) {\r
ba0014b9 88 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle, L"setsize");\r
5d73d92f 89 ShellStatus = SHELL_VOLUME_FULL;\r
90 } else if (EFI_ERROR(Status)) {\r
ba0014b9 91 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue(Package, LoopVar));\r
5d73d92f 92 ShellStatus = SHELL_INVALID_PARAMETER;\r
3737ac2b 93 } else {\r
94 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, LoopVar));\r
5d73d92f 95 }\r
96 ShellCloseFile(&FileHandle);\r
97 }\r
98 }\r
99\r
100 ShellCommandLineFreeVarList (Package);\r
101 }\r
102\r
103 return (ShellStatus);\r
104}\r