2 Main file for attrib shell level 2 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2010, 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
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.
16 #include "UefiShellLevel2CommandsLib.h"
19 Function for 'mkdir' command.
21 @param[in] ImageHandle Handle to the Image (NULL if Internal).
22 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
26 ShellCommandRunMkDir (
27 IN EFI_HANDLE ImageHandle
,
28 IN EFI_SYSTEM_TABLE
*SystemTable
32 CONST CHAR16
*NewDirName
;
33 CHAR16
*NewDirNameCopy
;
39 SHELL_FILE_HANDLE FileHandle
;
40 SHELL_STATUS ShellStatus
;
42 ShellStatus
= SHELL_SUCCESS
;
43 NewDirNameCopy
= NULL
;
45 SaveSplitChar
= CHAR_NULL
;
47 // initialize the shell lib (we must be in non-auto-init...)
49 Status
= ShellInitialize();
50 ASSERT_EFI_ERROR(Status
);
53 // parse the command line
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
), gShellLevel2HiiHandle
, L
"mkdir", ProblemParam
);
59 FreePool(ProblemParam
);
60 ShellStatus
= SHELL_INVALID_PARAMETER
;
68 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
73 // create a set of directories
75 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
77 // we didnt get a single parameter
79 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"mkdir");
80 ShellStatus
= SHELL_INVALID_PARAMETER
;
82 for ( DirCreateCount
= 1
87 // loop through each directory specified
90 NewDirName
= ShellCommandLineGetRawValue(Package
, DirCreateCount
);
91 if (NewDirName
== NULL
) {
95 // check if that already exists... if yes fail
98 Status
= ShellOpenFileByName(NewDirName
,
100 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
,
103 if (!EFI_ERROR(Status
)) {
104 ShellCloseFile(&FileHandle
);
105 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MKDIR_ALREADY
), gShellLevel2HiiHandle
, NewDirName
);
106 ShellStatus
= SHELL_INVALID_PARAMETER
;
108 ASSERT(FileHandle
== NULL
);
110 // create the nested directory from parent to child.
111 // if NewDirName = test1\test2\test3, first create "test1\" directory, then "test1\test2\", finally "test1\test2\test3".
113 NewDirNameCopy
= AllocateCopyPool (StrSize(NewDirName
), NewDirName
);
114 NewDirNameCopy
= PathCleanUpDirectories (NewDirNameCopy
);
115 if(NewDirNameCopy
== NULL
) {
116 ShellStatus
= SHELL_OUT_OF_RESOURCES
;
119 SplitName
= NewDirNameCopy
;
120 while (SplitName
!= NULL
) {
121 SplitName
= StrStr (SplitName
+ 1, L
"\\");
122 if (SplitName
!= NULL
) {
123 SaveSplitChar
= *(SplitName
+ 1);
124 *(SplitName
+ 1) = '\0';
127 // check if current nested directory already exists... continue to create the child directory.
129 Status
= ShellOpenFileByName (NewDirNameCopy
,
134 if (!EFI_ERROR(Status
)) {
135 ShellCloseFile (&FileHandle
);
137 Status
= ShellCreateDirectory (NewDirNameCopy
, &FileHandle
);
138 if (EFI_ERROR(Status
)) {
141 if (FileHandle
!= NULL
) {
142 gEfiShellProtocol
->CloseFile (FileHandle
);
145 if (SplitName
!= NULL
) {
146 *(SplitName
+ 1) = SaveSplitChar
;
149 if (EFI_ERROR(Status
)) {
150 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_MKDIR_CREATEFAIL
), gShellLevel2HiiHandle
, NewDirName
);
151 ShellStatus
= SHELL_ACCESS_DENIED
;
154 SHELL_FREE_NON_NULL (NewDirNameCopy
);
161 // free the command line package
163 ShellCommandLineFreeVarList (Package
);
165 return (ShellStatus
);