]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c
Add code to check whether the pointer 'CorrectedPath' and 'FullPath' are NULL before...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / MkDir.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for attrib shell level 2 function.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellLevel2CommandsLib.h"\r
16\r
17/**\r
18 Function for 'mkdir' command.\r
19\r
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
22**/\r
23SHELL_STATUS\r
24EFIAPI\r
25ShellCommandRunMkDir (\r
26 IN EFI_HANDLE ImageHandle,\r
27 IN EFI_SYSTEM_TABLE *SystemTable\r
28 )\r
29{\r
30 EFI_STATUS Status;\r
31 CONST CHAR16 *NewDirName;\r
32 UINTN DirCreateCount;\r
33 LIST_ENTRY *Package;\r
34 CHAR16 *ProblemParam;\r
35 SHELL_FILE_HANDLE FileHandle;\r
36 SHELL_STATUS ShellStatus;\r
37\r
38 ShellStatus = SHELL_SUCCESS;\r
39\r
40 //\r
41 // initialize the shell lib (we must be in non-auto-init...)\r
42 //\r
43 Status = ShellInitialize();\r
44 ASSERT_EFI_ERROR(Status);\r
45\r
46 //\r
47 // parse the command line\r
48 //\r
49 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r
50 if (EFI_ERROR(Status)) {\r
51 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
52 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r
53 FreePool(ProblemParam);\r
54 ShellStatus = SHELL_INVALID_PARAMETER;\r
55 } else {\r
56 ASSERT(FALSE);\r
57 }\r
58 } else {\r
59 //\r
60 // check for "-?"\r
61 //\r
62 if (ShellCommandLineGetFlag(Package, L"-?")) {\r
63 ASSERT(FALSE);\r
64 }\r
65\r
66 //\r
67 // create a set of directories\r
68 //\r
69 if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r
70 //\r
71 // we didnt get a single parameter\r
72 //\r
73 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);\r
74 ShellStatus = SHELL_INVALID_PARAMETER;\r
75 } else {\r
76 for ( DirCreateCount = 1\r
77 ;\r
78 ; DirCreateCount++\r
79 ){\r
80 //\r
81 // loop through each directory specified\r
82 //\r
83\r
84 NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount);\r
85 if (NewDirName == NULL) {\r
86 break;\r
87 }\r
88 //\r
89 // check if that already exists... if yes fail\r
90 //\r
91 FileHandle = NULL;\r
92 Status = ShellOpenFileByName(NewDirName,\r
93 &FileHandle,\r
94 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,\r
95 EFI_FILE_DIRECTORY\r
96 );\r
97 if (!EFI_ERROR(Status)) {\r
98 ShellCloseFile(&FileHandle);\r
99 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName);\r
100 ShellStatus = SHELL_INVALID_PARAMETER;\r
101 break;\r
102 } else {\r
103 ASSERT(FileHandle == NULL);\r
104 //\r
105 // create the directory named NewDirName\r
106 //\r
107 Status = ShellCreateDirectory(NewDirName, &FileHandle);\r
108 if (FileHandle != NULL) {\r
109 gEfiShellProtocol->CloseFile(FileHandle);\r
110 }\r
111 if (EFI_ERROR(Status)) {\r
112 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);\r
113 ShellStatus = SHELL_ACCESS_DENIED;\r
114 break;\r
115 }\r
116 }\r
117 }\r
118 }\r
119 }\r
120\r
121 //\r
122 // free the command line package\r
123 //\r
124 ShellCommandLineFreeVarList (Package);\r
125\r
126 return (ShellStatus);\r
127}\r
128\r