TianoCore EDK2 master
Loading...
Searching...
No Matches
SetSize.c
Go to the documentation of this file.
1
11
19EFIAPI
21 IN EFI_HANDLE ImageHandle,
22 IN EFI_SYSTEM_TABLE *SystemTable
23 )
24{
25 EFI_STATUS Status;
26 LIST_ENTRY *Package;
27 CHAR16 *ProblemParam;
28 SHELL_STATUS ShellStatus;
29 CONST CHAR16 *Temp1;
30 UINTN NewSize;
31 UINTN LoopVar;
32 SHELL_FILE_HANDLE FileHandle;
33
34 ShellStatus = SHELL_SUCCESS;
35 Status = EFI_SUCCESS;
36
37 //
38 // initialize the shell lib (we must be in non-auto-init...)
39 //
40 Status = ShellInitialize ();
41 ASSERT_EFI_ERROR (Status);
42
43 Status = CommandInit ();
44 ASSERT_EFI_ERROR (Status);
45
46 //
47 // parse the command line
48 //
49 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
50 if (EFI_ERROR (Status)) {
51 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
52 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam);
53 FreePool (ProblemParam);
54 ShellStatus = SHELL_INVALID_PARAMETER;
55 } else {
56 ASSERT (FALSE);
57 }
58 } else {
59 if (ShellCommandLineGetCount (Package) < 3) {
60 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize");
61 ShellStatus = SHELL_INVALID_PARAMETER;
62 NewSize = 0;
63 } else {
64 Temp1 = ShellCommandLineGetRawValue (Package, 1);
65 if (Temp1 == NULL) {
66 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setsize");
67 ShellStatus = SHELL_INVALID_PARAMETER;
68 NewSize = 0;
69 } else if (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) {
70 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");
71 ShellStatus = SHELL_INVALID_PARAMETER;
72 NewSize = 0;
73 } else {
74 NewSize = ShellStrToUintn (Temp1);
75 }
76 }
77
78 for (LoopVar = 2; LoopVar < ShellCommandLineGetCount (Package) && ShellStatus == SHELL_SUCCESS; LoopVar++) {
79 Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
80 if (EFI_ERROR (Status)) {
81 Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
82 }
83
84 if (EFI_ERROR (Status) && (LoopVar == 2)) {
85 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");
86 ShellStatus = SHELL_INVALID_PARAMETER;
87 } else if (EFI_ERROR (Status)) {
88 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar));
89 ShellStatus = SHELL_INVALID_PARAMETER;
90 break;
91 } else {
92 Status = FileHandleSetSize (FileHandle, NewSize);
93 if (Status == EFI_VOLUME_FULL) {
94 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle, L"setsize");
95 ShellStatus = SHELL_VOLUME_FULL;
96 } else if (EFI_ERROR (Status)) {
97 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar));
98 ShellStatus = SHELL_INVALID_PARAMETER;
99 } else {
100 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, LoopVar));
101 }
102
103 ShellCloseFile (&FileHandle);
104 }
105 }
106
108 }
109
110 return (ShellStatus);
111}
UINT64 UINTN
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI FileHandleSetSize(IN EFI_FILE_HANDLE FileHandle, IN UINT64 Size)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_VOLUME_FULL
Definition: Shell.h:84
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
SHELL_STATUS EFIAPI ShellCommandRunSetSize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SetSize.c:20
EFI_STATUS EFIAPI CommandInit(VOID)
UINTN EFIAPI ShellStrToUintn(IN CONST CHAR16 *String)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellIsHexOrDecimalNumber(IN CONST CHAR16 *String, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiShellLib.c:720
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
SHELL_PARAM_ITEM EmptyParamList[]
Helper structure for no parameters (besides -? and -b)
Definition: UefiShellLib.c:19
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:969
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define STRING_TOKEN(t)