]>
Commit | Line | Data |
---|---|---|
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 'cd' 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 | |
23 | SHELL_STATUS\r | |
24 | EFIAPI\r | |
25 | ShellCommandRunCd (\r | |
26 | IN EFI_HANDLE ImageHandle,\r | |
27 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
28 | )\r | |
29 | {\r | |
30 | EFI_STATUS Status;\r | |
31 | LIST_ENTRY *Package;\r | |
32 | CONST CHAR16 *Directory;\r | |
33 | CHAR16 *Path;\r | |
34 | CHAR16 *Drive;\r | |
35 | UINTN DriveSize;\r | |
36 | CHAR16 *ProblemParam;\r | |
37 | SHELL_STATUS ShellStatus;\r | |
38 | SHELL_FILE_HANDLE Handle;\r | |
39 | CONST CHAR16 *Param1;\r | |
40 | \r | |
41 | ProblemParam = NULL;\r | |
42 | ShellStatus = SHELL_SUCCESS;\r | |
43 | Drive = NULL;\r | |
44 | DriveSize = 0;\r | |
45 | \r | |
46 | Status = CommandInit();\r | |
47 | ASSERT_EFI_ERROR(Status);\r | |
48 | \r | |
49 | //\r | |
50 | // initialize the shell lib (we must be in non-auto-init...)\r | |
51 | //\r | |
52 | Status = ShellInitialize();\r | |
53 | ASSERT_EFI_ERROR(Status);\r | |
54 | \r | |
55 | //\r | |
56 | // parse the command line\r | |
57 | //\r | |
58 | Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r | |
59 | if (EFI_ERROR(Status)) {\r | |
60 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
61 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r | |
62 | FreePool(ProblemParam);\r | |
63 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
64 | } else {\r | |
65 | ASSERT(FALSE);\r | |
66 | }\r | |
67 | }\r | |
68 | \r | |
69 | //\r | |
70 | // check for "-?"\r | |
71 | //\r | |
72 | if (ShellCommandLineGetFlag(Package, L"-?")) {\r | |
73 | ASSERT(FALSE);\r | |
74 | } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r | |
75 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r | |
76 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
77 | } else {\r | |
78 | //\r | |
79 | // remember that param 0 is the command name\r | |
80 | // If there are 0 value parameters, then print the current directory\r | |
81 | // else If there are 2 value parameters, then print the error message\r | |
82 | // else If there is 1 value paramerer , then change the directory\r | |
83 | //\r | |
84 | Param1 = ShellCommandLineGetRawValue(Package, 1);\r | |
85 | if (Param1 == NULL) {\r | |
86 | //\r | |
87 | // display the current directory\r | |
88 | //\r | |
89 | Directory = ShellGetCurrentDir(NULL);\r | |
90 | if (Directory != NULL) {\r | |
91 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, Directory);\r | |
92 | } else {\r | |
93 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r | |
94 | ShellStatus = SHELL_NOT_FOUND;\r | |
95 | }\r | |
96 | } else {\r | |
97 | if (StrCmp(Param1, L".") == 0) {\r | |
98 | //\r | |
99 | // nothing to do... change to current directory\r | |
100 | //\r | |
101 | } else if (StrCmp(Param1, L"..") == 0) {\r | |
102 | //\r | |
103 | // Change up one directory...\r | |
104 | //\r | |
105 | Directory = ShellGetCurrentDir(NULL);\r | |
106 | if (Directory == NULL) {\r | |
107 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r | |
108 | ShellStatus = SHELL_NOT_FOUND;\r | |
109 | } else {\r | |
110 | Drive = GetFullyQualifiedPath(Directory);\r | |
111 | ChopLastSlash(Drive);\r | |
112 | }\r | |
113 | if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r | |
114 | //\r | |
115 | // change directory on current drive letter\r | |
116 | //\r | |
117 | Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r | |
118 | if (Status == EFI_NOT_FOUND) {\r | |
119 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r | |
120 | ShellStatus = SHELL_NOT_FOUND;\r | |
121 | }\r | |
122 | }\r | |
123 | } else if (StrCmp(Param1, L"\\") == 0) {\r | |
124 | //\r | |
125 | // Move to root of current drive\r | |
126 | //\r | |
127 | Directory = ShellGetCurrentDir(NULL);\r | |
128 | if (Directory == NULL) {\r | |
129 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r | |
130 | ShellStatus = SHELL_NOT_FOUND;\r | |
131 | } else {\r | |
132 | Drive = GetFullyQualifiedPath(Directory);\r | |
133 | while (ChopLastSlash(Drive)) ;\r | |
134 | }\r | |
135 | if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r | |
136 | //\r | |
137 | // change directory on current drive letter\r | |
138 | //\r | |
139 | Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r | |
140 | if (Status == EFI_NOT_FOUND) {\r | |
141 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r | |
142 | ShellStatus = SHELL_NOT_FOUND;\r | |
143 | }\r | |
144 | }\r | |
145 | } else if (StrStr(Param1, L":") == NULL) {\r | |
146 | if (ShellGetCurrentDir(NULL) == NULL) {\r | |
147 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);\r | |
148 | ShellStatus = SHELL_NOT_FOUND;\r | |
149 | } else {\r | |
150 | ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));\r | |
151 | Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);\r | |
152 | if (*Param1 == L'\\') {\r | |
153 | while (ChopLastSlash(Drive)) ;\r | |
154 | Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);\r | |
155 | } else {\r | |
156 | Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);\r | |
157 | }\r | |
158 | //\r | |
159 | // Verify that this is a valid directory\r | |
160 | //\r | |
161 | Status = gEfiShellProtocol->OpenFileByName(Drive, &Handle, EFI_FILE_MODE_READ);\r | |
162 | if (EFI_ERROR(Status)) {\r | |
163 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Drive);\r | |
164 | ShellStatus = SHELL_NOT_FOUND;\r | |
165 | } else if (EFI_ERROR(FileHandleIsDirectory(Handle))) {\r | |
166 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Drive);\r | |
167 | ShellStatus = SHELL_NOT_FOUND;\r | |
168 | }\r | |
169 | if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {\r | |
170 | //\r | |
171 | // change directory on current drive letter\r | |
172 | //\r | |
173 | Status = gEfiShellProtocol->SetCurDir(NULL, Drive);\r | |
174 | if (Status == EFI_NOT_FOUND) {\r | |
175 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r | |
176 | ShellStatus = SHELL_NOT_FOUND;\r | |
177 | }\r | |
178 | }\r | |
179 | if (Handle != NULL) {\r | |
180 | gEfiShellProtocol->CloseFile(Handle);\r | |
181 | DEBUG_CODE(Handle = NULL;);\r | |
182 | }\r | |
183 | }\r | |
184 | } else {\r | |
185 | //\r | |
186 | // change directory on other drive letter\r | |
187 | //\r | |
188 | Drive = AllocateZeroPool(StrSize(Param1));\r | |
189 | Drive = StrCpy(Drive, Param1);\r | |
190 | Path = StrStr(Drive, L":");\r | |
191 | *(++Path) = CHAR_NULL;\r | |
192 | Status = gEfiShellProtocol->SetCurDir(Drive, ++Path);\r | |
193 | \r | |
194 | if (Status == EFI_NOT_FOUND) {\r | |
195 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);\r | |
196 | Status = SHELL_NOT_FOUND;\r | |
197 | } else if (EFI_ERROR(Status)) {\r | |
198 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, Param1);\r | |
199 | Status = SHELL_NOT_FOUND;\r | |
200 | }\r | |
201 | }\r | |
202 | }\r | |
203 | }\r | |
204 | \r | |
205 | if (Drive != NULL) {\r | |
206 | FreePool(Drive);\r | |
207 | }\r | |
208 | //\r | |
209 | // free the command line package\r | |
210 | //\r | |
211 | ShellCommandLineFreeVarList (Package);\r | |
212 | \r | |
213 | //\r | |
214 | // return the status\r | |
215 | //\r | |
216 | return (ShellStatus);\r | |
217 | }\r | |
218 | \r |