• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 - 2011, Intel Corporation. All rights reserved.<BR>
6   This program and the accompanying materials
7   are licensed and made available under the terms and conditions of the BSD License
8   which accompanies this distribution.  The full text of the license may be found at
9   http://opensource.org/licenses/bsd-license.php
10 
11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #include "UefiShellDebug1CommandsLib.h"
17 
18 /**
19   Function for 'setsize' command.
20 
21   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
22   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
23 **/
24 SHELL_STATUS
25 EFIAPI
ShellCommandRunSetSize(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)26 ShellCommandRunSetSize (
27   IN EFI_HANDLE        ImageHandle,
28   IN EFI_SYSTEM_TABLE  *SystemTable
29   )
30 {
31   EFI_STATUS          Status;
32   LIST_ENTRY          *Package;
33   CHAR16              *ProblemParam;
34   SHELL_STATUS        ShellStatus;
35   CONST CHAR16        *Temp1;
36   UINTN               NewSize;
37   UINTN               LoopVar;
38   SHELL_FILE_HANDLE              FileHandle;
39 
40   ShellStatus         = SHELL_SUCCESS;
41   Status              = EFI_SUCCESS;
42 
43   //
44   // initialize the shell lib (we must be in non-auto-init...)
45   //
46   Status = ShellInitialize();
47   ASSERT_EFI_ERROR(Status);
48 
49   Status = CommandInit();
50   ASSERT_EFI_ERROR(Status);
51 
52   //
53   // parse the command line
54   //
55   Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
56   if (EFI_ERROR(Status)) {
57     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
58       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam);
59       FreePool(ProblemParam);
60       ShellStatus = SHELL_INVALID_PARAMETER;
61     } else {
62       ASSERT(FALSE);
63     }
64   } else {
65     if (ShellCommandLineGetCount(Package) < 3) {
66       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize");
67       ShellStatus = SHELL_INVALID_PARAMETER;
68       NewSize = 0;
69     } else {
70       Temp1 = ShellCommandLineGetRawValue(Package, 1);
71       if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) {
72         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize");
73         ShellStatus = SHELL_INVALID_PARAMETER;
74         NewSize = 0;
75       } else {
76         NewSize = ShellStrToUintn(Temp1);
77       }
78     }
79     for (LoopVar = 2 ; LoopVar < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS ; LoopVar++) {
80       Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
81       if (EFI_ERROR(Status)) {
82         Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
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         ShellCloseFile(&FileHandle);
103       }
104     }
105 
106     ShellCommandLineFreeVarList (Package);
107   }
108 
109   return (ShellStatus);
110 }
111