Changeset 2701 for box/trunk/lib/backupstore/BackupStoreCheck.cpp
- Timestamp:
- 27/08/2010 10:12:27 (21 months ago)
- File:
-
- 1 edited
-
box/trunk/lib/backupstore/BackupStoreCheck.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
box/trunk/lib/backupstore/BackupStoreCheck.cpp
r2127 r2701 48 48 mLostAndFoundDirectoryID(0), 49 49 mBlocksUsed(0), 50 mBlocksInCurrentFiles(0), 50 51 mBlocksInOldFiles(0), 51 52 mBlocksInDeletedFiles(0), 52 mBlocksInDirectories(0) 53 mBlocksInDirectories(0), 54 mNumFiles(0), 55 mNumOldFiles(0), 56 mNumDeletedFiles(0), 57 mNumDirectories(0) 53 58 { 54 59 } … … 336 341 // Function 337 342 // Name: BackupStoreCheck::CheckObjectsDir(int64_t) 338 // Purpose: Check all the files within this directory which has the given starting ID. 343 // Purpose: Check all the files within this directory which has 344 // the given starting ID. 339 345 // Created: 22/4/04 340 346 // … … 384 390 idsPresent[n] = true; 385 391 } 392 // No other files should be present in subdirectories 393 else if(StartID != 0) 394 { 395 fileOK = false; 396 } 397 // info and refcount databases are OK in the root directory 398 else if(*i == "info" || *i == "refcount.db") 399 { 400 fileOK = true; 401 } 386 402 else 387 403 { 388 // info file in root dir is OK! 389 if(StartID != 0 || ::strcmp("info", (*i).c_str()) != 0) 390 { 391 fileOK = false; 392 } 404 fileOK = false; 393 405 } 394 406 … … 437 449 // 438 450 // Function 439 // Name: BackupStoreCheck::CheckAndAddObject(int64_t, const std::string &) 440 // Purpose: Check a specific object and add it to the list if it's OK -- if 441 // there are any errors with the reading, return false and it'll be deleted. 451 // Name: BackupStoreCheck::CheckAndAddObject(int64_t, 452 // const std::string &) 453 // Purpose: Check a specific object and add it to the list 454 // if it's OK. If there are any errors with the 455 // reading, return false and it'll be deleted. 442 456 // Created: 21/4/04 443 457 // 444 458 // -------------------------------------------------------------------------- 445 bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, const std::string &rFilename) 459 bool BackupStoreCheck::CheckAndAddObject(int64_t ObjectID, 460 const std::string &rFilename) 446 461 { 447 462 // Info on object... … … 453 468 { 454 469 // Open file 455 std::auto_ptr<RaidFileRead> file(RaidFileRead::Open(mDiscSetNumber, rFilename)); 470 std::auto_ptr<RaidFileRead> file( 471 RaidFileRead::Open(mDiscSetNumber, rFilename)); 456 472 size = file->GetDiscUsageInBlocks(); 457 473 458 // Read in first four bytes -- don't have to worry about retrying if not all bytes read as is RaidFile 474 // Read in first four bytes -- don't have to worry about 475 // retrying if not all bytes read as is RaidFile 459 476 uint32_t signature; 460 477 if(file->Read(&signature, sizeof(signature)) != sizeof(signature)) … … 519 536 // Function 520 537 // Name: BackupStoreCheck::CheckFile(int64_t, IOStream &) 521 // Purpose: Do check on file, return original container ID if OK, or -1 on error 538 // Purpose: Do check on file, return original container ID 539 // if OK, or -1 on error 522 540 // Created: 22/4/04 523 541 // … … 525 543 int64_t BackupStoreCheck::CheckFile(int64_t ObjectID, IOStream &rStream) 526 544 { 527 // Check that it's not the root directory ID. Having a file as the root directory would be bad. 545 // Check that it's not the root directory ID. Having a file as 546 // the root directory would be bad. 528 547 if(ObjectID == BACKUPSTORE_ROOT_DIRECTORY_ID) 529 548 { … … 535 554 // Check the format of the file, and obtain the container ID 536 555 int64_t originalContainerID = -1; 537 if(!BackupStoreFile::VerifyEncodedFileFormat(rStream, 0 /* don't want diffing from ID */, 556 if(!BackupStoreFile::VerifyEncodedFileFormat(rStream, 557 0 /* don't want diffing from ID */, 538 558 &originalContainerID)) 539 559 { … … 550 570 // Function 551 571 // Name: BackupStoreCheck::CheckDirInitial(int64_t, IOStream &) 552 // Purpose: Do initial check on directory, return container ID if OK, or -1 on error 572 // Purpose: Do initial check on directory, return container ID 573 // if OK, or -1 on error 553 574 // Created: 22/4/04 554 575 // … … 589 610 // a note of all directories which are missing, and do initial fixing. 590 611 591 // Scan all objects 612 // The root directory is not contained inside another directory, so 613 // it has no directory entry to scan, but we have to count it 614 // somewhere, so we'll count it here. 615 mNumDirectories++; 616 617 // Scan all objects. 592 618 for(Info_t::const_iterator i(mInfo.begin()); i != mInfo.end(); ++i) 593 619 { … … 636 662 if(piBlock != 0) 637 663 { 638 // Found. Get flags 639 uint8_t iflags = GetFlags(piBlock, iIndex); 640 641 // Is the type the same? 642 if(((iflags & Flags_IsDir) == Flags_IsDir) 643 != ((en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir) == BackupStoreDirectory::Entry::Flags_Dir)) 644 { 645 // Entry is of wrong type 646 BOX_WARNING("Directory ID " << 647 BOX_FORMAT_OBJECTID(pblock->mID[e]) << 648 " references object " << 649 BOX_FORMAT_OBJECTID(en->GetObjectID()) << 650 " which has a different type than expected."); 651 badEntry = true; 652 } 653 else 654 { 655 // Check that the entry is not already contained. 656 if(iflags & Flags_IsContained) 657 { 658 BOX_WARNING("Directory ID " << 659 BOX_FORMAT_OBJECTID(pblock->mID[e]) << 660 " references object " << 661 BOX_FORMAT_OBJECTID(en->GetObjectID()) << 662 " which is already contained."); 663 badEntry = true; 664 } 665 else 666 { 667 // Not already contained -- mark as contained 668 SetFlags(piBlock, iIndex, iflags | Flags_IsContained); 669 670 // Check that the container ID of the object is correct 671 if(piBlock->mContainer[iIndex] != pblock->mID[e]) 672 { 673 // Needs fixing... 674 if(iflags & Flags_IsDir) 675 { 676 // Add to will fix later list 677 BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " has wrong container ID."); 678 mDirsWithWrongContainerID.push_back(en->GetObjectID()); 679 } 680 else 681 { 682 // This is OK for files, they might move 683 BOX_WARNING("File ID " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " has different container ID, probably moved"); 684 } 685 686 // Fix entry for now 687 piBlock->mContainer[iIndex] = pblock->mID[e]; 688 } 689 } 690 } 691 692 // Check the object size, if it's OK and a file 693 if(!badEntry && !((iflags & Flags_IsDir) == Flags_IsDir)) 694 { 695 if(en->GetSizeInBlocks() != piBlock->mObjectSizeInBlocks[iIndex]) 696 { 697 // Correct 698 en->SetSizeInBlocks(piBlock->mObjectSizeInBlocks[iIndex]); 699 // Mark as changed 700 isModified = true; 701 // Tell user 702 BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(pblock->mID[e]) << " has wrong size for object " << BOX_FORMAT_OBJECTID(en->GetObjectID())); 703 } 704 } 664 badEntry = !CheckDirectoryEntry( 665 *en, pblock->mID[e], 666 iIndex, isModified); 705 667 } 706 668 else 707 669 { 708 670 // Item can't be found. Is it a directory? 709 if(en-> GetFlags() & BackupStoreDirectory::Entry::Flags_Dir)671 if(en->IsDir()) 710 672 { 711 673 // Store the directory for later attention … … 725 687 toDelete.push_back(en->GetObjectID()); 726 688 } 727 else 689 else if (en->IsFile()) 728 690 { 729 691 // Add to sizes? 730 if(en-> GetFlags() & BackupStoreDirectory::Entry::Flags_OldVersion)692 if(en->IsOld()) 731 693 { 732 694 mBlocksInOldFiles += en->GetSizeInBlocks(); 733 695 } 734 if(en-> GetFlags() & BackupStoreDirectory::Entry::Flags_Deleted)696 if(en->IsDeleted()) 735 697 { 736 698 mBlocksInDeletedFiles += en->GetSizeInBlocks(); 699 } 700 if(!en->IsOld() && 701 !en->IsDeleted()) 702 { 703 mBlocksInCurrentFiles += en->GetSizeInBlocks(); 737 704 } 738 705 } … … 774 741 } 775 742 776 743 bool BackupStoreCheck::CheckDirectoryEntry(BackupStoreDirectory::Entry& rEntry, 744 int64_t DirectoryID, int32_t IndexInDirBlock, bool& rIsModified) 745 { 746 IDBlock *piBlock = LookupID(rEntry.GetObjectID(), IndexInDirBlock); 747 ASSERT(piBlock != 0); 748 749 uint8_t iflags = GetFlags(piBlock, IndexInDirBlock); 750 bool badEntry = false; 751 752 // Is the type the same? 753 if(((iflags & Flags_IsDir) == Flags_IsDir) != rEntry.IsDir()) 754 { 755 // Entry is of wrong type 756 BOX_WARNING("Directory ID " << 757 BOX_FORMAT_OBJECTID(DirectoryID) << 758 " references object " << 759 BOX_FORMAT_OBJECTID(rEntry.GetObjectID()) << 760 " which has a different type than expected."); 761 badEntry = true; 762 } 763 // Check that the entry is not already contained. 764 else if(iflags & Flags_IsContained) 765 { 766 BOX_WARNING("Directory ID " << 767 BOX_FORMAT_OBJECTID(DirectoryID) << 768 " references object " << 769 BOX_FORMAT_OBJECTID(rEntry.GetObjectID()) << 770 " which is already contained."); 771 badEntry = true; 772 } 773 else 774 { 775 // Not already contained -- mark as contained 776 SetFlags(piBlock, IndexInDirBlock, iflags | Flags_IsContained); 777 778 // Check that the container ID of the object is correct 779 if(piBlock->mContainer[IndexInDirBlock] != DirectoryID) 780 { 781 // Needs fixing... 782 if(iflags & Flags_IsDir) 783 { 784 // Add to will fix later list 785 BOX_WARNING("Directory ID " << 786 BOX_FORMAT_OBJECTID(rEntry.GetObjectID()) 787 << " has wrong container ID."); 788 mDirsWithWrongContainerID.push_back(rEntry.GetObjectID()); 789 } 790 else 791 { 792 // This is OK for files, they might move 793 BOX_WARNING("File ID " << 794 BOX_FORMAT_OBJECTID(rEntry.GetObjectID()) 795 << " has different container ID, " 796 "probably moved"); 797 } 798 799 // Fix entry for now 800 piBlock->mContainer[IndexInDirBlock] = DirectoryID; 801 } 802 } 803 804 // Check the object size, if it's OK and a file 805 if(!badEntry && !rEntry.IsDir()) 806 { 807 if(rEntry.GetSizeInBlocks() != piBlock->mObjectSizeInBlocks[IndexInDirBlock]) 808 { 809 // Wrong size, correct it. 810 rEntry.SetSizeInBlocks(piBlock->mObjectSizeInBlocks[IndexInDirBlock]); 811 812 // Mark as changed 813 rIsModified = true; 814 815 // Tell user 816 BOX_WARNING("Directory ID " << 817 BOX_FORMAT_OBJECTID(DirectoryID) << 818 " has wrong size for object " << 819 BOX_FORMAT_OBJECTID(rEntry.GetObjectID())); 820 } 821 } 822 823 if (!badEntry) 824 { 825 if(rEntry.IsDir()) 826 { 827 mNumDirectories++; 828 } 829 else 830 { 831 mNumFiles++; 832 833 if(rEntry.IsDeleted()) 834 { 835 mNumDeletedFiles++; 836 } 837 838 if(rEntry.IsOld()) 839 { 840 mNumOldFiles++; 841 } 842 } 843 } 844 845 return !badEntry; 846 } 847
Note: See TracChangeset
for help on using the changeset viewer.
