VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c@ 99396

Last change on this file since 99396 was 80721, checked in by vboxsync, 6 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
1/** @file
2 Main file for attrib shell level 2 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include "UefiShellLevel2CommandsLib.h"
11
12/**
13 Function for 'mkdir' command.
14
15 @param[in] ImageHandle Handle to the Image (NULL if Internal).
16 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
17**/
18SHELL_STATUS
19EFIAPI
20ShellCommandRunMkDir (
21 IN EFI_HANDLE ImageHandle,
22 IN EFI_SYSTEM_TABLE *SystemTable
23 )
24{
25 EFI_STATUS Status;
26 CONST CHAR16 *NewDirName;
27 CHAR16 *NewDirNameCopy;
28 CHAR16 *SplitName;
29 CHAR16 SaveSplitChar;
30 UINTN DirCreateCount;
31 LIST_ENTRY *Package;
32 CHAR16 *ProblemParam;
33 SHELL_FILE_HANDLE FileHandle;
34 SHELL_STATUS ShellStatus;
35
36 ShellStatus = SHELL_SUCCESS;
37 NewDirNameCopy = NULL;
38 SplitName = NULL;
39 SaveSplitChar = CHAR_NULL;
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, L"mkdir", 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, L"mkdir");
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 } else {
102 ASSERT(FileHandle == NULL);
103 //
104 // create the nested directory from parent to child.
105 // if NewDirName = test1\test2\test3, first create "test1\" directory, then "test1\test2\", finally "test1\test2\test3".
106 //
107 NewDirNameCopy = AllocateCopyPool (StrSize(NewDirName), NewDirName);
108 NewDirNameCopy = PathCleanUpDirectories (NewDirNameCopy);
109 if(NewDirNameCopy == NULL) {
110 ShellStatus = SHELL_OUT_OF_RESOURCES;
111 break;
112 }
113 SplitName = NewDirNameCopy;
114 while (SplitName != NULL) {
115 SplitName = StrStr (SplitName + 1, L"\\");
116 if (SplitName != NULL) {
117 SaveSplitChar = *(SplitName + 1);
118 *(SplitName + 1) = '\0';
119 }
120 //
121 // check if current nested directory already exists... continue to create the child directory.
122 //
123 Status = ShellOpenFileByName (NewDirNameCopy,
124 &FileHandle,
125 EFI_FILE_MODE_READ,
126 EFI_FILE_DIRECTORY
127 );
128 if (!EFI_ERROR(Status)) {
129 ShellCloseFile (&FileHandle);
130 } else {
131 Status = ShellCreateDirectory (NewDirNameCopy, &FileHandle);
132 if (EFI_ERROR(Status)) {
133 break;
134 }
135 if (FileHandle != NULL) {
136 gEfiShellProtocol->CloseFile (FileHandle);
137 }
138 }
139 if (SplitName != NULL) {
140 *(SplitName + 1) = SaveSplitChar;
141 }
142 }
143 if (EFI_ERROR(Status)) {
144 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);
145 ShellStatus = SHELL_ACCESS_DENIED;
146 break;
147 }
148 SHELL_FREE_NON_NULL (NewDirNameCopy);
149 }
150 }
151 }
152 }
153
154 //
155 // free the command line package
156 //
157 ShellCommandLineFreeVarList (Package);
158
159 return (ShellStatus);
160}
161
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette