Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (21 months ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
r80721 r99404 32 32 ) 33 33 { 34 CHAR16 35 CHAR16 36 UINTN 34 CHAR16 *Splitter; 35 CHAR16 *TempBuffer; 36 UINTN TotalSize; 37 37 38 38 Splitter = NULL; … … 40 40 TotalSize = 0; 41 41 42 if ( FullPath == NULL || *FullPath == NULL) {42 if ((FullPath == NULL) || (*FullPath == NULL)) { 43 43 return EFI_SUCCESS; 44 44 } 45 45 46 46 Splitter = StrStr (*FullPath, L":"); 47 ASSERT (Splitter != *FullPath);48 49 if ( Splitter != NULL && *(Splitter + 1) != L'\\' && *(Splitter + 1) != L'/') {50 TotalSize = StrSize (Cwd) + StrSize (Splitter + 1);47 ASSERT (Splitter != *FullPath); 48 49 if ((Splitter != NULL) && (*(Splitter + 1) != L'\\') && (*(Splitter + 1) != L'/')) { 50 TotalSize = StrSize (Cwd) + StrSize (Splitter + 1); 51 51 TempBuffer = AllocateZeroPool (TotalSize); 52 52 if (TempBuffer == NULL) { … … 54 54 } 55 55 56 StrCpyS (TempBuffer, TotalSize / sizeof (CHAR16), Cwd);57 StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), L"\\");58 StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), Splitter + 1);59 60 FreePool (*FullPath);56 StrCpyS (TempBuffer, TotalSize / sizeof (CHAR16), Cwd); 57 StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), L"\\"); 58 StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), Splitter + 1); 59 60 FreePool (*FullPath); 61 61 *FullPath = TempBuffer; 62 62 } … … 76 76 BOOLEAN 77 77 IsCurrentFileSystem ( 78 IN CONST CHAR16 79 IN CONST CHAR16 78 IN CONST CHAR16 *FullPath, 79 IN CONST CHAR16 *Cwd 80 80 ) 81 81 { 82 CHAR16 *Splitter1;83 CHAR16 *Splitter2;82 CHAR16 *Splitter1; 83 CHAR16 *Splitter2; 84 84 85 85 Splitter1 = NULL; 86 86 Splitter2 = NULL; 87 87 88 ASSERT (FullPath != NULL);88 ASSERT (FullPath != NULL); 89 89 90 90 Splitter1 = StrStr (FullPath, L":"); … … 95 95 Splitter2 = StrStr (Cwd, L":"); 96 96 97 if (((UINTN) Splitter1 - (UINTN) FullPath) != ((UINTN) Splitter2 - (UINTN)Cwd)) {97 if (((UINTN)Splitter1 - (UINTN)FullPath) != ((UINTN)Splitter2 - (UINTN)Cwd)) { 98 98 return FALSE; 99 99 } else { 100 if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN)FullPath) / sizeof (CHAR16)) == 0) {100 if (StrniCmp (FullPath, Cwd, ((UINTN)Splitter1 - (UINTN)FullPath) / sizeof (CHAR16)) == 0) { 101 101 return TRUE; 102 102 } else { … … 120 120 EFI_STATUS 121 121 ExtractDriveAndPath ( 122 IN CONST CHAR16 123 OUT CHAR16 124 OUT CHAR16 122 IN CONST CHAR16 *FullPath, 123 OUT CHAR16 **Drive, 124 OUT CHAR16 **Path 125 125 ) 126 126 { 127 CHAR16 *Splitter;127 CHAR16 *Splitter; 128 128 129 129 ASSERT (FullPath != NULL); … … 133 133 if (Splitter == NULL) { 134 134 *Drive = NULL; 135 *Path = AllocateCopyPool (StrSize (FullPath), FullPath);135 *Path = AllocateCopyPool (StrSize (FullPath), FullPath); 136 136 if (*Path == NULL) { 137 137 return EFI_OUT_OF_RESOURCES; … … 140 140 if (*(Splitter + 1) == CHAR_NULL) { 141 141 *Drive = AllocateCopyPool (StrSize (FullPath), FullPath); 142 *Path = NULL;142 *Path = NULL; 143 143 if (*Drive == NULL) { 144 144 return EFI_OUT_OF_RESOURCES; 145 145 } 146 146 } else { 147 *Drive = AllocateCopyPool ((Splitter - FullPath + 2) * sizeof (CHAR16), FullPath);147 *Drive = AllocateCopyPool ((Splitter - FullPath + 2) * sizeof (CHAR16), FullPath); 148 148 if (*Drive == NULL) { 149 149 return EFI_OUT_OF_RESOURCES; 150 150 } 151 151 152 (*Drive)[Splitter - FullPath + 1] = CHAR_NULL; 152 153 … … 175 176 ) 176 177 { 177 EFI_STATUS 178 LIST_ENTRY 179 CONST CHAR16 180 CHAR16 181 CHAR16 182 CHAR16 183 SHELL_STATUS 184 CONST CHAR16 185 CHAR16 186 CHAR16 187 CHAR16 188 CHAR16 189 UINTN 190 191 ProblemParam 192 ShellStatus 193 Cwd 194 Path 195 Drive 196 Splitter 197 TempBuffer 198 TotalSize 199 200 Status = CommandInit ();201 ASSERT_EFI_ERROR (Status);178 EFI_STATUS Status; 179 LIST_ENTRY *Package; 180 CONST CHAR16 *Cwd; 181 CHAR16 *Path; 182 CHAR16 *Drive; 183 CHAR16 *ProblemParam; 184 SHELL_STATUS ShellStatus; 185 CONST CHAR16 *Param1; 186 CHAR16 *Param1Copy; 187 CHAR16 *Walker; 188 CHAR16 *Splitter; 189 CHAR16 *TempBuffer; 190 UINTN TotalSize; 191 192 ProblemParam = NULL; 193 ShellStatus = SHELL_SUCCESS; 194 Cwd = NULL; 195 Path = NULL; 196 Drive = NULL; 197 Splitter = NULL; 198 TempBuffer = NULL; 199 TotalSize = 0; 200 201 Status = CommandInit (); 202 ASSERT_EFI_ERROR (Status); 202 203 203 204 // 204 205 // initialize the shell lib (we must be in non-auto-init...) 205 206 // 206 Status = ShellInitialize ();207 ASSERT_EFI_ERROR (Status);207 Status = ShellInitialize (); 208 ASSERT_EFI_ERROR (Status); 208 209 209 210 // … … 211 212 // 212 213 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); 213 if (EFI_ERROR (Status)) {214 if ( Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {215 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cd", ProblemParam);216 FreePool (ProblemParam);214 if (EFI_ERROR (Status)) { 215 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { 216 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cd", ProblemParam); 217 FreePool (ProblemParam); 217 218 ShellStatus = SHELL_INVALID_PARAMETER; 218 219 } else { 219 ASSERT (FALSE);220 ASSERT (FALSE); 220 221 } 221 222 } … … 224 225 // check for "-?" 225 226 // 226 if (ShellCommandLineGetFlag (Package, L"-?")) {227 ASSERT (FALSE);228 } else if (ShellCommandLineGetRawValue (Package, 2) != NULL) {229 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"cd");227 if (ShellCommandLineGetFlag (Package, L"-?")) { 228 ASSERT (FALSE); 229 } else if (ShellCommandLineGetRawValue (Package, 2) != NULL) { 230 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"cd"); 230 231 ShellStatus = SHELL_INVALID_PARAMETER; 231 232 } else { … … 238 239 Cwd = ShellGetCurrentDir (NULL); 239 240 if (Cwd == NULL) { 240 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cd");241 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cd"); 241 242 ShellStatus = SHELL_NOT_FOUND; 242 243 } else { … … 246 247 // display the current directory 247 248 // 248 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, Cwd);249 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, Cwd); 249 250 } else { 250 251 Param1Copy = CatSPrint (NULL, L"%s", Param1, NULL); 251 252 for (Walker = Param1Copy; Walker != NULL && *Walker != CHAR_NULL; Walker++) { 252 253 if (*Walker == L'\"') { 253 CopyMem (Walker, Walker + 1, StrSize (Walker) - sizeof(Walker[0]));254 CopyMem (Walker, Walker + 1, StrSize (Walker) - sizeof (Walker[0])); 254 255 } 255 256 } 256 257 257 if ( Param1Copy != NULL&& IsCurrentFileSystem (Param1Copy, Cwd)) {258 Status = ReplaceDriveWithCwd (&Param1Copy, Cwd);258 if ((Param1Copy != NULL) && IsCurrentFileSystem (Param1Copy, Cwd)) { 259 Status = ReplaceDriveWithCwd (&Param1Copy, Cwd); 259 260 } else { 260 261 // … … 265 266 } 266 267 267 if (!EFI_ERROR (Status) && Param1Copy != NULL) {268 if (!EFI_ERROR (Status) && (Param1Copy != NULL)) { 268 269 Splitter = StrStr (Cwd, L":"); 269 270 if (Param1Copy[0] == L'\\') { … … 271 272 // Absolute Path on current drive letter. 272 273 // 273 TotalSize = ((Splitter - Cwd + 1) * sizeof(CHAR16)) + StrSize(Param1Copy);274 TotalSize = ((Splitter - Cwd + 1) * sizeof (CHAR16)) + StrSize (Param1Copy); 274 275 TempBuffer = AllocateZeroPool (TotalSize); 275 276 if (TempBuffer == NULL) { 276 277 Status = EFI_OUT_OF_RESOURCES; 277 278 } else { 278 StrnCpyS (TempBuffer, TotalSize / sizeof (CHAR16), Cwd, (Splitter - Cwd + 1));279 StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), Param1Copy);279 StrnCpyS (TempBuffer, TotalSize / sizeof (CHAR16), Cwd, (Splitter - Cwd + 1)); 280 StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), Param1Copy); 280 281 281 282 FreePool (Param1Copy); … … 284 285 } 285 286 } else { 286 if (StrStr (Param1Copy, L":") == NULL) {287 TotalSize = StrSize (Cwd) + StrSize (Param1Copy);287 if (StrStr (Param1Copy, L":") == NULL) { 288 TotalSize = StrSize (Cwd) + StrSize (Param1Copy); 288 289 TempBuffer = AllocateZeroPool (TotalSize); 289 290 if (TempBuffer == NULL) { … … 302 303 } 303 304 304 if (!EFI_ERROR (Status)) {305 if (!EFI_ERROR (Status)) { 305 306 Param1Copy = PathCleanUpDirectories (Param1Copy); 306 Status = ExtractDriveAndPath (Param1Copy, &Drive, &Path);307 } 308 309 if (!EFI_ERROR (Status) && Drive != NULL && Path != NULL) {310 if (EFI_ERROR (ShellIsDirectory (Param1Copy))) {311 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cd", Param1Copy);307 Status = ExtractDriveAndPath (Param1Copy, &Drive, &Path); 308 } 309 310 if (!EFI_ERROR (Status) && (Drive != NULL) && (Path != NULL)) { 311 if (EFI_ERROR (ShellIsDirectory (Param1Copy))) { 312 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cd", Param1Copy); 312 313 ShellStatus = SHELL_NOT_FOUND; 313 314 } else { 314 315 Status = gEfiShellProtocol->SetCurDir (Drive, Path + 1); 315 316 if (EFI_ERROR (Status)) { 316 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cd", Param1Copy);317 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cd", Param1Copy); 317 318 ShellStatus = SHELL_NOT_FOUND; 318 319 } … … 343 344 return (ShellStatus); 344 345 } 345
Note:
See TracChangeset
for help on using the changeset viewer.