2 Main file for attrib shell level 2 function.
4 Copyright (c) 2009 - 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
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"
18 Function for 'mkdir' command.
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
25 ShellCommandRunMkDir (
26 IN EFI_HANDLE ImageHandle
,
27 IN EFI_SYSTEM_TABLE
*SystemTable
31 CONST CHAR16
*NewDirName
;
35 SHELL_FILE_HANDLE FileHandle
;
36 SHELL_STATUS ShellStatus
;
38 ShellStatus
= SHELL_SUCCESS
;
41 // initialize the shell lib (we must be in non-auto-init...)
43 Status
= ShellInitialize();
44 ASSERT_EFI_ERROR(Status
);
47 // parse the command line
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
), gShellLevel2HiiHandle
, ProblemParam
);
53 FreePool(ProblemParam
);
54 ShellStatus
= SHELL_INVALID_PARAMETER
;
62 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
67 // create a set of directories
69 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
71 // we didnt get a single parameter
73 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
);
74 ShellStatus
= SHELL_INVALID_PARAMETER
;
76 for ( DirCreateCount
= 1
81 // loop through each directory specified
84 NewDirName
= ShellCommandLineGetRawValue(Package
, DirCreateCount
);
85 if (NewDirName
== NULL
) {
89 // check if that already exists... if yes fail
92 Status
= ShellOpenFileByName(NewDirName
,
94 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
,
97 if (!EFI_ERROR(Status
)) {
98 ShellCloseFile(&FileHandle
);
99 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MKDIR_ALREADY
), gShellLevel2HiiHandle
, NewDirName
);
100 ShellStatus
= SHELL_INVALID_PARAMETER
;
103 ASSERT(FileHandle
== NULL
);
105 // create the directory named NewDirName
107 Status
= ShellCreateDirectory(NewDirName
, &FileHandle
);
108 if (FileHandle
!= NULL
) {
109 gEfiShellProtocol
->CloseFile(FileHandle
);
111 if (EFI_ERROR(Status
)) {
112 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MKDIR_CREATEFAIL
), gShellLevel2HiiHandle
, NewDirName
);
113 ShellStatus
= SHELL_ACCESS_DENIED
;
122 // free the command line package
124 ShellCommandLineFreeVarList (Package
);
126 return (ShellStatus
);