2 Main file for vol shell level 2 function.
4 Copyright (c) 2011, 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
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.
15 #include "UefiShellLevel2CommandsLib.h"
16 #include <Guid/FileSystemInfo.h>
17 #include <Guid/FileSystemVolumeLabelInfo.h>
20 Print the info or change the volume info.
22 @param[in] Path String with starting path.
23 @param[in] Delete TRUE to delete the volume label. FALSE otherwise.
24 @param[in] Name New name to set to the volume label.
26 @retval SHELL_SUCCESS The operation was sucessful.
31 IN CONST CHAR16
*Path
,
32 IN CONST BOOLEAN Delete
,
37 SHELL_STATUS ShellStatus
;
38 EFI_FILE_SYSTEM_INFO
*SysInfo
;
40 SHELL_FILE_HANDLE ShellFileHandle
;
41 EFI_FILE_PROTOCOL
*EfiFpHandle
;
45 ShellStatus
= SHELL_SUCCESS
;
48 StrStr(Name
, L
"%") != NULL
||
49 StrStr(Name
, L
"^") != NULL
||
50 StrStr(Name
, L
"*") != NULL
||
51 StrStr(Name
, L
"+") != NULL
||
52 StrStr(Name
, L
"=") != NULL
||
53 StrStr(Name
, L
"[") != NULL
||
54 StrStr(Name
, L
"]") != NULL
||
55 StrStr(Name
, L
"|") != NULL
||
56 StrStr(Name
, L
":") != NULL
||
57 StrStr(Name
, L
";") != NULL
||
58 StrStr(Name
, L
"\"") != NULL
||
59 StrStr(Name
, L
"<") != NULL
||
60 StrStr(Name
, L
">") != NULL
||
61 StrStr(Name
, L
"?") != NULL
||
62 StrStr(Name
, L
"/") != NULL
||
63 StrStr(Name
, L
" ") != NULL
65 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, Name
);
66 return (SHELL_INVALID_PARAMETER
);
69 Status
= gEfiShellProtocol
->OpenFileByName(
72 Name
!= NULL
?EFI_FILE_MODE_READ
|EFI_FILE_MODE_WRITE
:EFI_FILE_MODE_READ
);
74 if (EFI_ERROR(Status
) || ShellFileHandle
== NULL
) {
75 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL
), gShellLevel2HiiHandle
, Path
);
76 return (SHELL_ACCESS_DENIED
);
80 // Get the Volume Info from ShellFileHandle
84 EfiFpHandle
= ConvertShellHandleToEfiFileProtocol(ShellFileHandle
);
85 Status
= EfiFpHandle
->GetInfo(
87 &gEfiFileSystemInfoGuid
,
91 if (Status
== EFI_BUFFER_TOO_SMALL
) {
92 SysInfo
= AllocateZeroPool(SysInfoSize
);
93 Status
= EfiFpHandle
->GetInfo(
95 &gEfiFileSystemInfoGuid
,
100 ASSERT(SysInfo
!= NULL
);
103 StrCpy ((CHAR16
*) SysInfo
->VolumeLabel
, L
"");
104 SysInfo
->Size
= SIZE_OF_EFI_FILE_SYSTEM_INFO
+ StrSize(SysInfo
->VolumeLabel
);
105 Status
= EfiFpHandle
->SetInfo(
107 &gEfiFileSystemInfoGuid
,
108 (UINTN
)SysInfo
->Size
,
110 } else if (Name
!= NULL
) {
111 Size1
= StrSize(Name
);
112 Size2
= StrSize(SysInfo
->VolumeLabel
);
114 SysInfo
= ReallocatePool((UINTN
)SysInfo
->Size
, (UINTN
)SysInfo
->Size
+ Size1
- Size2
, SysInfo
);
116 StrCpy ((CHAR16
*) SysInfo
->VolumeLabel
, Name
);
117 SysInfo
->Size
= SIZE_OF_EFI_FILE_SYSTEM_INFO
+ Size1
;
118 Status
= EfiFpHandle
->SetInfo(
120 &gEfiFileSystemInfoGuid
,
121 (UINTN
)SysInfo
->Size
,
127 if (Delete
|| Name
!= NULL
) {
128 if (EFI_ERROR(Status
)) {
129 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_AD
), gShellLevel2HiiHandle
, Path
);
130 ShellStatus
= SHELL_ACCESS_DENIED
;
137 Status
= EfiFpHandle
->GetInfo(
139 &gEfiFileSystemInfoGuid
,
143 if (Status
== EFI_BUFFER_TOO_SMALL
) {
144 SysInfo
= AllocateZeroPool(SysInfoSize
);
145 Status
= EfiFpHandle
->GetInfo(
147 &gEfiFileSystemInfoGuid
,
152 gEfiShellProtocol
->CloseFile(ShellFileHandle
);
155 // print VolumeInfo table
159 gST
->ConOut
->Mode
->CursorRow
,
161 STRING_TOKEN (STR_VOL_VOLINFO
),
162 gShellLevel2HiiHandle
,
163 SysInfo
->VolumeLabel
,
164 SysInfo
->ReadOnly
?L
"r":L
"rw",
169 SHELL_FREE_NON_NULL(SysInfo
);
171 return (ShellStatus
);
174 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
181 Function for 'Vol' command.
183 @param[in] ImageHandle Handle to the Image (NULL if Internal).
184 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
189 IN EFI_HANDLE ImageHandle
,
190 IN EFI_SYSTEM_TABLE
*SystemTable
195 CHAR16
*ProblemParam
;
196 SHELL_STATUS ShellStatus
;
197 CONST CHAR16
*PathName
;
198 CONST CHAR16
*CurDir
;
206 ShellStatus
= SHELL_SUCCESS
;
212 // initialize the shell lib (we must be in non-auto-init...)
214 Status
= ShellInitialize();
215 ASSERT_EFI_ERROR(Status
);
218 // Fix local copies of the protocol pointers
220 Status
= CommandInit();
221 ASSERT_EFI_ERROR(Status
);
224 // parse the command line
226 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
227 if (EFI_ERROR(Status
)) {
228 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
229 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
230 FreePool(ProblemParam
);
231 ShellStatus
= SHELL_INVALID_PARAMETER
;
239 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
243 if (ShellCommandLineGetCount(Package
) > 2) {
244 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
245 ShellStatus
= SHELL_INVALID_PARAMETER
;
247 PathName
= ShellCommandLineGetRawValue(Package
, 1);
248 if (PathName
== NULL
) {
249 CurDir
= gEfiShellProtocol
->GetCurDir(NULL
);
250 if (CurDir
== NULL
) {
251 ShellStatus
= SHELL_NOT_FOUND
;
252 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_CWD
), gShellLevel2HiiHandle
);
257 if (PathName
!= NULL
) {
258 TempSpot
= StrStr(PathName
, L
":");
259 if (TempSpot
!= NULL
) {
260 *TempSpot
= CHAR_NULL
;
262 TempSpot
= StrStr(PathName
, L
"\\");
263 if (TempSpot
!= NULL
) {
264 *TempSpot
= CHAR_NULL
;
266 StrnCatGrow(&FullPath
, &Length
, PathName
, 0);
267 StrnCatGrow(&FullPath
, &Length
, L
":\\", 0);
268 DeleteMode
= ShellCommandLineGetFlag(Package
, L
"-d");
269 if (DeleteMode
&& ShellCommandLineGetFlag(Package
, L
"-n")) {
270 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CON
), gShellLevel2HiiHandle
);
271 ShellStatus
= SHELL_INVALID_PARAMETER
;
272 } else if (ShellCommandLineGetFlag(Package
, L
"-n") && ShellCommandLineGetValue(Package
, L
"-n") == NULL
) {
273 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"-n");
274 ShellStatus
= SHELL_INVALID_PARAMETER
;
275 } else if (ShellCommandLineGetValue(Package
, L
"-n") != NULL
&& StrLen(ShellCommandLineGetValue(Package
, L
"-n")) > 11) {
276 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM_VAL
), gShellLevel2HiiHandle
, L
"-n");
277 ShellStatus
= SHELL_INVALID_PARAMETER
;
278 } else if (ShellStatus
== SHELL_SUCCESS
) {
279 ShellStatus
= HandleVol(
282 ShellCommandLineGetValue(Package
, L
"-n")
289 SHELL_FREE_NON_NULL(FullPath
);
292 // free the command line package
294 ShellCommandLineFreeVarList (Package
);
296 return (ShellStatus
);