]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / MkDir.c
1 /** @file
2 Main file for attrib shell level 2 function.
3
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
9
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.
12
13 **/
14
15 #include "UefiShellLevel2CommandsLib.h"
16
17 /**
18 Function for 'mkdir' command.
19
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
22 **/
23 SHELL_STATUS
24 EFIAPI
25 ShellCommandRunMkDir (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 {
30 EFI_STATUS Status;
31 CONST CHAR16 *NewDirName;
32 UINTN DirCreateCount;
33 LIST_ENTRY *Package;
34 CHAR16 *ProblemParam;
35 SHELL_FILE_HANDLE FileHandle;
36 SHELL_STATUS ShellStatus;
37
38 ShellStatus = SHELL_SUCCESS;
39
40 //
41 // initialize the shell lib (we must be in non-auto-init...)
42 //
43 Status = ShellInitialize();
44 ASSERT_EFI_ERROR(Status);
45
46 //
47 // parse the command line
48 //
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;
55 } else {
56 ASSERT(FALSE);
57 }
58 } else {
59 //
60 // check for "-?"
61 //
62 if (ShellCommandLineGetFlag(Package, L"-?")) {
63 ASSERT(FALSE);
64 }
65
66 //
67 // create a set of directories
68 //
69 if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
70 //
71 // we didnt get a single parameter
72 //
73 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
74 ShellStatus = SHELL_INVALID_PARAMETER;
75 } else {
76 for ( DirCreateCount = 1
77 ;
78 ; DirCreateCount++
79 ){
80 //
81 // loop through each directory specified
82 //
83
84 NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount);
85 if (NewDirName == NULL) {
86 break;
87 }
88 //
89 // check if that already exists... if yes fail
90 //
91 FileHandle = NULL;
92 Status = ShellOpenFileByName(NewDirName,
93 &FileHandle,
94 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,
95 EFI_FILE_DIRECTORY
96 );
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;
101 break;
102 } else {
103 ASSERT(FileHandle == NULL);
104 //
105 // create the directory named NewDirName
106 //
107 Status = ShellCreateDirectory(NewDirName, &FileHandle);
108 if (FileHandle != NULL) {
109 gEfiShellProtocol->CloseFile(FileHandle);
110 }
111 if (EFI_ERROR(Status)) {
112 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);
113 ShellStatus = SHELL_ACCESS_DENIED;
114 break;
115 }
116 }
117 }
118 }
119 }
120
121 //
122 // free the command line package
123 //
124 ShellCommandLineFreeVarList (Package);
125
126 return (ShellStatus);
127 }
128