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
;
36 SHELL_FILE_HANDLE FileHandle
;
37 SHELL_STATUS ShellStatus
;
39 ShellStatus
= SHELL_SUCCESS
;
42 // initialize the shell lib (we must be in non-auto-init...)
44 Status
= ShellInitialize();
45 ASSERT_EFI_ERROR(Status
);
48 // parse the command line
50 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
51 if (EFI_ERROR(Status
)) {
52 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
53 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"mkdir", ProblemParam
);
54 FreePool(ProblemParam
);
55 ShellStatus
= SHELL_INVALID_PARAMETER
;
63 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
68 // create a set of directories
70 if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
72 // we didnt get a single parameter
74 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"mkdir");
75 ShellStatus
= SHELL_INVALID_PARAMETER
;
77 for ( DirCreateCount
= 1
82 // loop through each directory specified
85 NewDirName
= ShellCommandLineGetRawValue(Package
, DirCreateCount
);
86 if (NewDirName
== NULL
) {
90 // check if that already exists... if yes fail
93 Status
= ShellOpenFileByName(NewDirName
,
95 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
,
98 if (!EFI_ERROR(Status
)) {
99 ShellCloseFile(&FileHandle
);
100 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MKDIR_ALREADY
), gShellLevel2HiiHandle
, NewDirName
);
101 ShellStatus
= SHELL_INVALID_PARAMETER
;
104 ASSERT(FileHandle
== NULL
);
106 // create the directory named NewDirName
108 Status
= ShellCreateDirectory(NewDirName
, &FileHandle
);
109 if (FileHandle
!= NULL
) {
110 gEfiShellProtocol
->CloseFile(FileHandle
);
112 if (EFI_ERROR(Status
)) {
113 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_MKDIR_CREATEFAIL
), gShellLevel2HiiHandle
, NewDirName
);
114 ShellStatus
= SHELL_ACCESS_DENIED
;
123 // free the command line package
125 ShellCommandLineFreeVarList (Package
);
127 return (ShellStatus
);