1 | /** @file
|
---|
2 | Main file for SetSize shell Debug1 function.
|
---|
3 |
|
---|
4 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
---|
5 | Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "UefiShellDebug1CommandsLib.h"
|
---|
11 |
|
---|
12 | /**
|
---|
13 | Function for 'setsize' command.
|
---|
14 |
|
---|
15 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
---|
16 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
---|
17 | **/
|
---|
18 | SHELL_STATUS
|
---|
19 | EFIAPI
|
---|
20 | ShellCommandRunSetSize (
|
---|
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 (!ShellIsHexOrDecimalNumber (Temp1, FALSE, FALSE)) {
|
---|
66 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");
|
---|
67 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
68 | NewSize = 0;
|
---|
69 | } else {
|
---|
70 | NewSize = ShellStrToUintn (Temp1);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | for (LoopVar = 2; LoopVar < ShellCommandLineGetCount (Package) && ShellStatus == SHELL_SUCCESS; LoopVar++) {
|
---|
75 | Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
|
---|
76 | if (EFI_ERROR (Status)) {
|
---|
77 | Status = ShellOpenFileByName (ShellCommandLineGetRawValue (Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (EFI_ERROR (Status) && (LoopVar == 2)) {
|
---|
81 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");
|
---|
82 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
83 | } else if (EFI_ERROR (Status)) {
|
---|
84 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar));
|
---|
85 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
86 | break;
|
---|
87 | } else {
|
---|
88 | Status = FileHandleSetSize (FileHandle, NewSize);
|
---|
89 | if (Status == EFI_VOLUME_FULL) {
|
---|
90 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle, L"setsize");
|
---|
91 | ShellStatus = SHELL_VOLUME_FULL;
|
---|
92 | } else if (EFI_ERROR (Status)) {
|
---|
93 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue (Package, LoopVar));
|
---|
94 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
95 | } else {
|
---|
96 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, LoopVar));
|
---|
97 | }
|
---|
98 |
|
---|
99 | ShellCloseFile (&FileHandle);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | ShellCommandLineFreeVarList (Package);
|
---|
104 | }
|
---|
105 |
|
---|
106 | return (ShellStatus);
|
---|
107 | }
|
---|