]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDebug1CommandsLib/SetSize.c
Add "Debug1" profile (all but Edit and HexEdit commands)
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / SetSize.c
1 /** @file
2 Main file for SetSize shell Debug1 function.
3
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "UefiShellDebug1CommandsLib.h"
16
17 SHELL_STATUS
18 EFIAPI
19 ShellCommandRunSetSize (
20 IN EFI_HANDLE ImageHandle,
21 IN EFI_SYSTEM_TABLE *SystemTable
22 )
23 {
24 EFI_STATUS Status;
25 LIST_ENTRY *Package;
26 CHAR16 *ProblemParam;
27 SHELL_STATUS ShellStatus;
28 CONST CHAR16 *Temp1;
29 UINTN NewSize;
30 UINTN LoopVar;
31 SHELL_FILE_HANDLE FileHandle;
32
33 ShellStatus = SHELL_SUCCESS;
34 Status = EFI_SUCCESS;
35
36 //
37 // initialize the shell lib (we must be in non-auto-init...)
38 //
39 Status = ShellInitialize();
40 ASSERT_EFI_ERROR(Status);
41
42 Status = CommandInit();
43 ASSERT_EFI_ERROR(Status);
44
45 //
46 // parse the command line
47 //
48 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
49 if (EFI_ERROR(Status)) {
50 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
51 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
52 FreePool(ProblemParam);
53 ShellStatus = SHELL_INVALID_PARAMETER;
54 } else {
55 ASSERT(FALSE);
56 }
57 } else {
58 Temp1 = ShellCommandLineGetRawValue(Package, 1);
59 if (Temp1 == NULL) {
60 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle);
61 ShellStatus = SHELL_INVALID_PARAMETER;
62 NewSize = 0;
63 } else {
64 NewSize = ShellStrToUintn(Temp1);
65 }
66 for (LoopVar = 2 ; LoopVar < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS ; LoopVar++) {
67 Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
68 if (EFI_ERROR(Status) && LoopVar == 2) {
69 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle);
70 ShellStatus = SHELL_INVALID_PARAMETER;
71 } else if (EFI_ERROR(Status)) {
72 break;
73 } else {
74 Status = FileHandleSetSize(FileHandle, NewSize);
75 if (Status == EFI_VOLUME_FULL) {
76 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle);
77 ShellStatus = SHELL_VOLUME_FULL;
78 } else if (EFI_ERROR(Status)) {
79 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, LoopVar), Status);
80 ShellStatus = SHELL_INVALID_PARAMETER;
81 }
82 ShellCloseFile(&FileHandle);
83 }
84 }
85
86 ShellCommandLineFreeVarList (Package);
87 }
88
89 return (ShellStatus);
90 }