Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.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/UefiShellDebug1CommandsLib/Comp.c
r89983 r99404 10 10 #include "UefiShellDebug1CommandsLib.h" 11 11 12 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {13 { L"-n", TypeValue},14 { L"-s", TypeValue},15 { NULL, TypeMax}16 12 STATIC CONST SHELL_PARAM_ITEM ParamList[] = { 13 { L"-n", TypeValue }, 14 { L"-s", TypeValue }, 15 { NULL, TypeMax } 16 }; 17 17 18 18 typedef enum { … … 26 26 // 27 27 typedef struct { 28 UINT8 *Data; // dynamically allocated buffer29 UINTN Allocated; // the allocated size of Data30 UINTN Next; // next position in Data to fetch a byte at31 UINTN Left; // number of bytes left in Data for fetching at Next28 UINT8 *Data; // dynamically allocated buffer 29 UINTN Allocated; // the allocated size of Data 30 UINTN Next; // next position in Data to fetch a byte at 31 UINTN Left; // number of bytes left in Data for fetching at Next 32 32 } FILE_BUFFER; 33 33 … … 44 44 **/ 45 45 VOID 46 PrintDifferentPoint (46 PrintDifferentPoint ( 47 47 CONST CHAR16 *FileName, 48 48 CHAR16 *FileTag, … … 53 53 ) 54 54 { 55 UINTN Index;55 UINTN Index; 56 56 57 57 ShellPrintEx (-1, -1, L"%s: %s\r\n %08x:", FileTag, FileName, Address); … … 74 74 // 75 75 for (Index = 0; Index < BufferSize; Index++) { 76 if ( Buffer[Index] >= 0x20 && Buffer[Index] <= 0x7E) {76 if ((Buffer[Index] >= 0x20) && (Buffer[Index] <= 0x7E)) { 77 77 ShellPrintEx (-1, -1, L"%c", Buffer[Index]); 78 78 } else { … … 98 98 VOID 99 99 FileBufferInit ( 100 OUT FILE_BUFFER *FileBuffer100 OUT FILE_BUFFER *FileBuffer 101 101 ) 102 102 { … … 117 117 VOID 118 118 FileBufferUninit ( 119 IN OUT FILE_BUFFER *FileBuffer119 IN OUT FILE_BUFFER *FileBuffer 120 120 ) 121 121 { … … 155 155 EFI_STATUS 156 156 FileBufferReadByte ( 157 IN SHELL_FILE_HANDLE FileHandle,158 IN OUT FILE_BUFFER *FileBuffer,159 OUT UINTN*BytesRead,160 OUT UINT8*Byte157 IN SHELL_FILE_HANDLE FileHandle, 158 IN OUT FILE_BUFFER *FileBuffer, 159 OUT UINTN *BytesRead, 160 OUT UINT8 *Byte 161 161 ) 162 162 { 163 UINTN ReadSize;164 EFI_STATUS Status;163 UINTN ReadSize; 164 EFI_STATUS Status; 165 165 166 166 if (FileBuffer->Left == 0) { 167 167 ReadSize = FileBuffer->Allocated; 168 Status = gEfiShellProtocol->ReadFile (FileHandle, &ReadSize, 169 FileBuffer->Data); 168 Status = gEfiShellProtocol->ReadFile ( 169 FileHandle, 170 &ReadSize, 171 FileBuffer->Data 172 ); 170 173 if (EFI_ERROR (Status)) { 171 174 return Status; 172 175 } 176 173 177 if (ReadSize == 0) { 174 178 *BytesRead = 0; 175 179 return EFI_SUCCESS; 176 180 } 181 177 182 FileBuffer->Next = 0; 178 183 FileBuffer->Left = ReadSize; … … 200 205 ) 201 206 { 202 EFI_STATUS 203 LIST_ENTRY 204 CHAR16 205 CHAR16 206 CHAR16 207 CONST CHAR16 208 SHELL_STATUS 209 SHELL_FILE_HANDLE 210 SHELL_FILE_HANDLE 211 UINT64 212 UINT64 213 UINT64 214 UINT64 215 UINT8 216 UINT8 217 UINT8 218 UINT8 219 UINT8 220 FILE_BUFFER 221 FILE_BUFFER 222 UINTN 223 UINTN 224 UINTN 225 UINTN 226 UINTN 227 UINTN 228 UINTN 229 READ_STATUS 230 231 ShellStatus 232 Status 233 FileName1 234 FileName2 235 FileHandle1 236 FileHandle2 237 DataFromFile1 238 DataFromFile2 239 ReadStatus 240 DifferentCount 241 DifferentBytes 242 DiffPointNumber 243 InsertPosition1 244 InsertPosition2 245 TempAddress 246 DiffPointAddress 207 EFI_STATUS Status; 208 LIST_ENTRY *Package; 209 CHAR16 *ProblemParam; 210 CHAR16 *FileName1; 211 CHAR16 *FileName2; 212 CONST CHAR16 *TempParam; 213 SHELL_STATUS ShellStatus; 214 SHELL_FILE_HANDLE FileHandle1; 215 SHELL_FILE_HANDLE FileHandle2; 216 UINT64 Size1; 217 UINT64 Size2; 218 UINT64 DifferentBytes; 219 UINT64 DifferentCount; 220 UINT8 DiffPointNumber; 221 UINT8 OneByteFromFile1; 222 UINT8 OneByteFromFile2; 223 UINT8 *DataFromFile1; 224 UINT8 *DataFromFile2; 225 FILE_BUFFER FileBuffer1; 226 FILE_BUFFER FileBuffer2; 227 UINTN InsertPosition1; 228 UINTN InsertPosition2; 229 UINTN DataSizeFromFile1; 230 UINTN DataSizeFromFile2; 231 UINTN TempAddress; 232 UINTN Index; 233 UINTN DiffPointAddress; 234 READ_STATUS ReadStatus; 235 236 ShellStatus = SHELL_SUCCESS; 237 Status = EFI_SUCCESS; 238 FileName1 = NULL; 239 FileName2 = NULL; 240 FileHandle1 = NULL; 241 FileHandle2 = NULL; 242 DataFromFile1 = NULL; 243 DataFromFile2 = NULL; 244 ReadStatus = OutOfDiffPoint; 245 DifferentCount = 10; 246 DifferentBytes = 4; 247 DiffPointNumber = 0; 248 InsertPosition1 = 0; 249 InsertPosition2 = 0; 250 TempAddress = 0; 251 DiffPointAddress = 0; 247 252 248 253 // 249 254 // initialize the shell lib (we must be in non-auto-init...) 250 255 // 251 Status = ShellInitialize ();252 ASSERT_EFI_ERROR (Status);253 254 Status = CommandInit ();255 ASSERT_EFI_ERROR (Status);256 Status = ShellInitialize (); 257 ASSERT_EFI_ERROR (Status); 258 259 Status = CommandInit (); 260 ASSERT_EFI_ERROR (Status); 256 261 257 262 // … … 259 264 // 260 265 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); 261 if (EFI_ERROR (Status)) {262 if ( Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {263 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam);264 FreePool (ProblemParam);266 if (EFI_ERROR (Status)) { 267 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) { 268 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam); 269 FreePool (ProblemParam); 265 270 ShellStatus = SHELL_INVALID_PARAMETER; 266 271 } else { 267 ASSERT (FALSE);272 ASSERT (FALSE); 268 273 } 269 274 } else { 270 if (ShellCommandLineGetCount (Package) > 3) {271 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp");275 if (ShellCommandLineGetCount (Package) > 3) { 276 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); 272 277 ShellStatus = SHELL_INVALID_PARAMETER; 273 } else if (ShellCommandLineGetCount (Package) < 3) {274 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp");278 } else if (ShellCommandLineGetCount (Package) < 3) { 279 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp"); 275 280 ShellStatus = SHELL_INVALID_PARAMETER; 276 281 } else { 277 TempParam = ShellCommandLineGetRawValue (Package, 1);278 ASSERT (TempParam != NULL);279 FileName1 = ShellFindFilePath (TempParam);282 TempParam = ShellCommandLineGetRawValue (Package, 1); 283 ASSERT (TempParam != NULL); 284 FileName1 = ShellFindFilePath (TempParam); 280 285 if (FileName1 == NULL) { 281 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);286 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); 282 287 ShellStatus = SHELL_NOT_FOUND; 283 288 } else { 284 Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);285 if (EFI_ERROR (Status)) {286 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);289 Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); 290 if (EFI_ERROR (Status)) { 291 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); 287 292 ShellStatus = SHELL_NOT_FOUND; 288 293 } 289 294 } 290 TempParam = ShellCommandLineGetRawValue(Package, 2); 291 ASSERT(TempParam != NULL); 292 FileName2 = ShellFindFilePath(TempParam); 295 296 TempParam = ShellCommandLineGetRawValue (Package, 2); 297 ASSERT (TempParam != NULL); 298 FileName2 = ShellFindFilePath (TempParam); 293 299 if (FileName2 == NULL) { 294 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);300 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); 295 301 ShellStatus = SHELL_NOT_FOUND; 296 302 } else { 297 Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);298 if (EFI_ERROR (Status)) {299 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);303 Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); 304 if (EFI_ERROR (Status)) { 305 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); 300 306 ShellStatus = SHELL_NOT_FOUND; 301 307 } 302 308 } 309 303 310 if (ShellStatus == SHELL_SUCCESS) { 304 Status = gEfiShellProtocol->GetFileSize (FileHandle1, &Size1);305 ASSERT_EFI_ERROR (Status);306 Status = gEfiShellProtocol->GetFileSize (FileHandle2, &Size2);307 ASSERT_EFI_ERROR (Status);311 Status = gEfiShellProtocol->GetFileSize (FileHandle1, &Size1); 312 ASSERT_EFI_ERROR (Status); 313 Status = gEfiShellProtocol->GetFileSize (FileHandle2, &Size2); 314 ASSERT_EFI_ERROR (Status); 308 315 309 316 if (ShellCommandLineGetFlag (Package, L"-n")) { … … 317 324 } else { 318 325 Status = ShellConvertStringToUint64 (TempParam, &DifferentCount, FALSE, TRUE); 319 if (EFI_ERROR (Status) || DifferentCount == 0) {326 if (EFI_ERROR (Status) || (DifferentCount == 0)) { 320 327 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-n"); 321 328 ShellStatus = SHELL_INVALID_PARAMETER; … … 332 339 } else { 333 340 Status = ShellConvertStringToUint64 (TempParam, &DifferentBytes, FALSE, TRUE); 334 if (EFI_ERROR (Status) || DifferentBytes == 0) {341 if (EFI_ERROR (Status) || (DifferentBytes == 0)) { 335 342 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-s"); 336 343 ShellStatus = SHELL_INVALID_PARAMETER; … … 349 356 FileBufferInit (&FileBuffer1); 350 357 FileBufferInit (&FileBuffer2); 351 if (DataFromFile1 == NULL || DataFromFile2 == NULL || 352 FileBuffer1.Data == NULL || FileBuffer2.Data == NULL) { 358 if ((DataFromFile1 == NULL) || (DataFromFile2 == NULL) || 359 (FileBuffer1.Data == NULL) || (FileBuffer2.Data == NULL)) 360 { 353 361 ShellStatus = SHELL_OUT_OF_RESOURCES; 354 362 SHELL_FREE_NON_NULL (DataFromFile1); … … 363 371 DataSizeFromFile1 = 1; 364 372 DataSizeFromFile2 = 1; 365 OneByteFromFile1 = 0; 366 OneByteFromFile2 = 0; 367 Status = FileBufferReadByte (FileHandle1, &FileBuffer1, 368 &DataSizeFromFile1, &OneByteFromFile1); 373 OneByteFromFile1 = 0; 374 OneByteFromFile2 = 0; 375 Status = FileBufferReadByte ( 376 FileHandle1, 377 &FileBuffer1, 378 &DataSizeFromFile1, 379 &OneByteFromFile1 380 ); 369 381 ASSERT_EFI_ERROR (Status); 370 Status = FileBufferReadByte (FileHandle2, &FileBuffer2, 371 &DataSizeFromFile2, &OneByteFromFile2); 382 Status = FileBufferReadByte ( 383 FileHandle2, 384 &FileBuffer2, 385 &DataSizeFromFile2, 386 &OneByteFromFile2 387 ); 372 388 ASSERT_EFI_ERROR (Status); 373 389 … … 379 395 // So the previous different point is the last one, then break the while block. 380 396 // 381 if ( (DataSizeFromFile1 == 0 && InsertPosition1 == 0 && DataSizeFromFile2 == 0 && InsertPosition2 == 0) || 382 (ReadStatus == InPrevDiffPoint && (DataSizeFromFile1 == 0 || DataSizeFromFile2 == 0)) 383 ) { 397 if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) || 398 ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0))) 399 ) 400 { 384 401 break; 385 402 } … … 387 404 if (ReadStatus == OutOfDiffPoint) { 388 405 if (OneByteFromFile1 != OneByteFromFile2) { 389 ReadStatus = InDiffPoint;406 ReadStatus = InDiffPoint; 390 407 DiffPointAddress = TempAddress; 391 408 if (DataSizeFromFile1 == 1) { 392 409 DataFromFile1[InsertPosition1++] = OneByteFromFile1; 393 410 } 411 394 412 if (DataSizeFromFile2 == 1) { 395 413 DataFromFile2[InsertPosition2++] = OneByteFromFile2; … … 400 418 DataFromFile1[InsertPosition1++] = OneByteFromFile1; 401 419 } 420 402 421 if (DataSizeFromFile2 == 1) { 403 422 DataFromFile2[InsertPosition2++] = OneByteFromFile2; … … 412 431 // ReadStatus should be always equal InDiffPoint. 413 432 // 414 if ( InsertPosition1 == DifferentBytes||415 InsertPosition2 == DifferentBytes||416 (DataSizeFromFile1 == 0 && DataSizeFromFile2 == 0)417 ) {418 433 if ((InsertPosition1 == DifferentBytes) || 434 (InsertPosition2 == DifferentBytes) || 435 ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0)) 436 ) 437 { 419 438 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber); 420 439 PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); … … 424 443 // One of two buffuers is empty, it means this is the last different point. 425 444 // 426 if ( InsertPosition1 == 0 || InsertPosition2 == 0) {445 if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) { 427 446 break; 428 447 } … … 439 458 // Try to find a new different point in the rest of DataFromFile. 440 459 // 441 for ( ; Index < MAX (InsertPosition1,InsertPosition2); Index++) {460 for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) { 442 461 if (DataFromFile1[Index] != DataFromFile2[Index]) { 443 ReadStatus = InDiffPoint;462 ReadStatus = InDiffPoint; 444 463 DiffPointAddress += Index; 445 464 break; … … 470 489 471 490 if (DiffPointNumber == 0) { 472 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);491 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); 473 492 } else { 474 493 ShellStatus = SHELL_NOT_EQUAL; 475 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);494 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); 476 495 } 477 496 } … … 480 499 ShellCommandLineFreeVarList (Package); 481 500 } 482 SHELL_FREE_NON_NULL(FileName1); 483 SHELL_FREE_NON_NULL(FileName2); 501 502 SHELL_FREE_NON_NULL (FileName1); 503 SHELL_FREE_NON_NULL (FileName2); 484 504 485 505 if (FileHandle1 != NULL) { 486 gEfiShellProtocol->CloseFile(FileHandle1); 487 } 506 gEfiShellProtocol->CloseFile (FileHandle1); 507 } 508 488 509 if (FileHandle2 != NULL) { 489 gEfiShellProtocol->CloseFile (FileHandle2);510 gEfiShellProtocol->CloseFile (FileHandle2); 490 511 } 491 512
Note:
See TracChangeset
for help on using the changeset viewer.