filemanager/bkupengine/src/CMMCScBkupArchiveFooter.cpp
changeset 0 6a9f87576119
equal deleted inserted replaced
-1:000000000000 0:6a9f87576119
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: CMMCScBkupArchiveFooter Implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupArchiveFooter.h"
       
    20 
       
    21 // User includes
       
    22 #include "CMMCScBkupIndexPublicDataFiles.h"
       
    23 #include "CMMCScBkupIndexDataOwners.h"
       
    24 #include "CMMCScBkupIndexJavaData.h"
       
    25 #include "CMMCScBkupIndexSystemData.h"
       
    26 #include "CMMCScBkupIndexActiveData.h"
       
    27 #include "CMMCScBkupIndexJavaData.h"
       
    28 #include "CMMCScBkupIndexPassiveData.h"
       
    29 #include "MMMCScBkupArchiveDataInterface.h"
       
    30 #include "CMMCScBkupDataOwnerInfo.h"
       
    31 #include "MMCScBkupArchiveUtils.h"
       
    32 #include "CMMCScBkupDataOwnerCollection.h"
       
    33 
       
    34 /**
       
    35 
       
    36     UNDERSTANDING ARCHIVE FOOTER
       
    37     ============================
       
    38 
       
    39     // Indicies are:
       
    40     //
       
    41     // EMMCScBkupOwnerDataTypeDataOwner
       
    42     // EMMCScBkupOwnerDataTypeJavaData
       
    43     // EMMCScBkupOwnerDataTypePublicData
       
    44     // EMMCScBkupOwnerDataTypeSystemData
       
    45     // EMMCScBkupOwnerDataTypeActiveData
       
    46     // EMMCScBkupOwnerDataTypePassiveData
       
    47     //
       
    48     //  6 (index objects) *
       
    49     //  ( 1 byte for object type + TMMCScBkupArchiveVector::ExternalizedSize() )
       
    50     //
       
    51 
       
    52     // THIS IS THE SIZE OF AN INDIVIDUAL "INDEX RECORD POINTER"
       
    53     const TInt indexDataSize = 1 // index type
       
    54         + TMMCScBkupArchiveVector::ExternalizedSize() // vector
       
    55         + 4 // spare1
       
    56         + 4 // spare2
       
    57         ;
       
    58 
       
    59     // THIS IS THE TOTAL SIZE OF ALL "INDEX RECORD POINTERS"
       
    60     const TInt sizeOfAllIndicies = 
       
    61           4 // stream format version
       
    62         + 4 // spare1
       
    63         + 4 // spare2
       
    64         + 4 // spare3
       
    65         + 4 // spare4
       
    66         + 4 // index object count
       
    67         + ( EMMCScBkupOwnerDataTypeCount * indexDataSize);
       
    68 
       
    69     // WE ALSO WRITE THE AMOUNT OF DISK SPACE REQUIRED FOR EACH DRIVE
       
    70     // IN ORDER TO RESTORE THE ARCHIVE
       
    71 
       
    72     (not included here)
       
    73 */
       
    74 
       
    75 
       
    76 // ========================= MEMBER FUNCTIONS ================================
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CMMCScBkupArchiveFooter::CMMCScBkupArchiveFooter()
       
    80 // 
       
    81 // C++ constructor.
       
    82 // ---------------------------------------------------------------------------
       
    83 CMMCScBkupArchiveFooter::CMMCScBkupArchiveFooter( MMMCScBkupArchiveDataInterface& aDataInterface, MMMCScBkupDriver& aDriver )
       
    84 :   iDataInterface( aDataInterface ), iDriver( aDriver )
       
    85     {
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CMMCScBkupArchiveFooter::~CMMCScBkupArchiveFooter()
       
    91 // 
       
    92 // Destructor.
       
    93 // ---------------------------------------------------------------------------
       
    94 CMMCScBkupArchiveFooter::~CMMCScBkupArchiveFooter()
       
    95     {
       
    96     iIndicies.Close();
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CMMCScBkupArchiveFooter::ConstructL()
       
   102 // 
       
   103 // 
       
   104 // ---------------------------------------------------------------------------
       
   105 void CMMCScBkupArchiveFooter::ConstructL()
       
   106     {
       
   107     CMMCScBkupIndexBase* index = NULL;
       
   108     //
       
   109     index = CMMCScBkupIndexDataOwners::NewLC();
       
   110     iIndicies.AppendL(index);
       
   111     CleanupStack::Pop(index);
       
   112     //
       
   113     index = CMMCScBkupIndexPublicDataFiles::NewLC();
       
   114     iIndicies.AppendL(index);
       
   115     CleanupStack::Pop(index);
       
   116     //
       
   117     index = CMMCScBkupIndexSystemData::NewLC();
       
   118     iIndicies.AppendL(index);
       
   119     CleanupStack::Pop(index);
       
   120     //
       
   121     index = CMMCScBkupIndexJavaData::NewLC();
       
   122     iIndicies.AppendL(index);
       
   123     CleanupStack::Pop(index);
       
   124     //
       
   125     index = CMMCScBkupIndexActiveData::NewLC();
       
   126     iIndicies.AppendL(index);
       
   127     CleanupStack::Pop(index);
       
   128     //
       
   129     index = CMMCScBkupIndexPassiveData::NewLC();
       
   130     iIndicies.AppendL(index);
       
   131     CleanupStack::Pop(index);
       
   132     }
       
   133 
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CMMCScBkupArchiveFooter::NewL()
       
   137 // 
       
   138 // 
       
   139 // ---------------------------------------------------------------------------
       
   140 CMMCScBkupArchiveFooter* CMMCScBkupArchiveFooter::NewL( MMMCScBkupArchiveDataInterface& aDataInterface, MMMCScBkupDriver& aDriver )
       
   141     {
       
   142     CMMCScBkupArchiveFooter* self = new(ELeave) CMMCScBkupArchiveFooter( aDataInterface, aDriver );
       
   143     CleanupStack::PushL(self);
       
   144     self->ConstructL();
       
   145     CleanupStack::Pop(self);
       
   146     return self;
       
   147     }
       
   148 
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CMMCScBkupArchiveFooter::IndexByType()
       
   152 // 
       
   153 // 
       
   154 // ---------------------------------------------------------------------------
       
   155 CMMCScBkupIndexBase& CMMCScBkupArchiveFooter::IndexByType( TMMCScBkupOwnerDataType aType )
       
   156     {
       
   157     CMMCScBkupIndexBase* ret = IndexByTypeOrNull( aType );
       
   158     __ASSERT_ALWAYS(ret != NULL, User::Invariant());
       
   159     return *ret;
       
   160     }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CMMCScBkupArchiveFooter::IndexByTypeOrNull()
       
   165 // 
       
   166 // 
       
   167 // ---------------------------------------------------------------------------
       
   168 CMMCScBkupIndexBase* CMMCScBkupArchiveFooter::IndexByTypeOrNull( TMMCScBkupOwnerDataType aType )
       
   169     {
       
   170     CMMCScBkupIndexBase* ret = NULL;
       
   171     //
       
   172     const TInt count = iIndicies.Count();
       
   173     for(TInt i=0; i<count; i++)
       
   174         {
       
   175         CMMCScBkupIndexBase* entry = iIndicies[i];
       
   176         if  (entry->Type() == aType)
       
   177             {
       
   178             ret = entry;
       
   179             break;
       
   180             }
       
   181         }
       
   182     //
       
   183     return ret;
       
   184     }
       
   185 
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CMMCScBkupArchiveFooter::StoreL()
       
   189 // 
       
   190 // 
       
   191 // ---------------------------------------------------------------------------
       
   192 void CMMCScBkupArchiveFooter::StoreL()
       
   193     {
       
   194     RWriteStream stream( iDataInterface.ADIWriteStreamUncompressedLC() );
       
   195     //    
       
   196     const TInt count = iIndicies.Count();
       
   197     __ASSERT_DEBUG( count == EMMCScBkupOwnerDataTypeCount, User::Invariant());
       
   198 
       
   199     // NEW: write index version
       
   200     stream.WriteInt32L( EStreamFormatVersion1 );
       
   201 
       
   202     // NEW: spare1, spare2, spare3, spare4
       
   203     stream.WriteInt32L( 0 );
       
   204     stream.WriteInt32L( 0 );
       
   205     stream.WriteInt32L( 0 );
       
   206     stream.WriteInt32L( 0 );
       
   207 
       
   208     // NEW: write the number of indicies...
       
   209     stream.WriteInt32L( count );
       
   210 
       
   211     // ...then write each index in turn...
       
   212     for(TInt i=0; i<count; i++)
       
   213         {
       
   214         // First write the index type...
       
   215         const CMMCScBkupIndexBase& index = *iIndicies[i];
       
   216         stream.WriteInt8L( index.Type() );
       
   217 
       
   218         // Then write its offset (and length)
       
   219         const TMMCScBkupArchiveVector& vector = index.Vector();
       
   220         stream << vector;
       
   221 
       
   222         // NEW: Then write spare bytes for each index record
       
   223         stream.WriteInt32L( 0 ); // per-index spare1
       
   224         stream.WriteInt32L( 0 ); // per-index spare2
       
   225         }
       
   226 
       
   227     // NEW: write the amount of disk space required for each drive as
       
   228     // part of the footer information
       
   229     CMMCScBkupDataOwnerCollection& dataOwners = iDriver.DrvDataOwners();
       
   230     dataOwners.CalculateDiskSpaceRequiredForRestoreL();
       
   231     stream << dataOwners;
       
   232     
       
   233     // Tidy up...
       
   234     stream.CommitL();
       
   235     CleanupStack::PopAndDestroy(); // stream
       
   236 
       
   237 #ifdef RD_FILE_MANAGER_BACKUP
       
   238     // Disable crc-calculation for header data. Header crc'd separately
       
   239     iDataInterface.ADIActivateCrcCalculation(EFalse);
       
   240 #endif
       
   241     
       
   242     // We can now update the header with the total length of the footer, validation bits and crcs
       
   243     const TMMCScBkupArchiveVector& finalWriteInfo = iDataInterface.ADICurrentArchiveVectorInfo();
       
   244     MMCScBkupArchiveUtils::SetFooterLengthL( iDataInterface.ADIRawArchiveFile(), finalWriteInfo.Length() );
       
   245     MMCScBkupArchiveUtils::SetArchiveContentAsValidL( iDataInterface.ADIRawArchiveFile() );
       
   246 #ifdef RD_FILE_MANAGER_BACKUP
       
   247     MMCScBkupArchiveUtils::SetArchiveCrcsL( iDataInterface.ADIRawArchiveFile(), iDataInterface.ADIArchiveCrc() );
       
   248 #endif
       
   249     }
       
   250 
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // CMMCScBkupArchiveFooter::RestoreL()
       
   254 // 
       
   255 // 
       
   256 // ---------------------------------------------------------------------------
       
   257 void CMMCScBkupArchiveFooter::RestoreL( TInt aCalculatedFooterOffsetWithinArchive )
       
   258     {
       
   259     RReadStream stream( iDataInterface.ADIReadStreamUncompressedLC( aCalculatedFooterOffsetWithinArchive ) );
       
   260 
       
   261     // NEW: Read stream format
       
   262     stream.ReadInt32L(); // EStreamFormatVersion1 
       
   263 
       
   264     // NEW: spare1, spare2, spare3, spare4
       
   265     stream.ReadInt32L();
       
   266     stream.ReadInt32L();
       
   267     stream.ReadInt32L();
       
   268     stream.ReadInt32L();
       
   269     
       
   270     // NEW: Read written index count
       
   271     const TInt inMemoryIndexCount = iIndicies.Count();
       
   272     const TInt archiveIndexCount = stream.ReadInt32L();
       
   273     if  ( archiveIndexCount > inMemoryIndexCount )
       
   274         {
       
   275         // Something wrong with file format version info?
       
   276         User::Leave( KErrCorrupt );
       
   277         }
       
   278 
       
   279     // Read index offsets
       
   280     for(TInt i=0; i<archiveIndexCount; i++)
       
   281         {
       
   282         // We only read the offset & length information. 
       
   283         // The actual respective index restoration is done by other
       
   284         // objects as a result of other states
       
   285         const TMMCScBkupOwnerDataType type = static_cast< TMMCScBkupOwnerDataType >( stream.ReadInt8L() );
       
   286         //
       
   287         if  ( type < 0 || type >= EMMCScBkupOwnerDataTypeCount )
       
   288             {
       
   289             User::Leave( KErrCorrupt );
       
   290             }
       
   291         else
       
   292             {
       
   293             // Always read the vector info (in order to keep the stream
       
   294             // position inline with the externalised representation)
       
   295             TMMCScBkupArchiveVector vector;
       
   296             stream >> vector;
       
   297             
       
   298             // NEW: Then read spare bytes for each index record
       
   299             stream.ReadInt32L(); // per-index spare1
       
   300             stream.ReadInt32L(); // per-index spare2
       
   301 
       
   302             // But only prepare the index if we have a similar type..
       
   303             CMMCScBkupIndexBase* index = IndexByTypeOrNull( type );
       
   304             //
       
   305             if  ( index )
       
   306                 {
       
   307                 index->SetVector( vector );
       
   308                 }
       
   309 
       
   310             }
       
   311         }
       
   312 
       
   313     // NEW: read the amount of disk space required for each drive as
       
   314     // part of the footer information
       
   315     CMMCScBkupDataOwnerCollection& dataOwners = iDriver.DrvDataOwners();
       
   316     stream >> dataOwners;
       
   317 
       
   318     //
       
   319     CleanupStack::PopAndDestroy(); // stream
       
   320     }
       
   321 
       
   322 
       
   323 
       
   324 
       
   325 
       
   326 
       
   327 
       
   328 
       
   329 
       
   330 
       
   331 
       
   332 
       
   333 
       
   334 
       
   335 
       
   336 
       
   337 
       
   338 
       
   339 
       
   340 
       
   341 
       
   342