Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
5.2 KiB

  1. #include "stdwin.h"
  2. #include "mfr.h"
  3. /////////////////////////////////////////////////////////////////////////////
  4. //
  5. // ReadAndFormatLogFileV3
  6. //
  7. /////////////////////////////////////////////////////////////////////////////
  8. static LPCWSTR s_cszResName[] =
  9. {
  10. L"",
  11. L"Fail",
  12. L"OK",
  13. L"Lock",
  14. L"Disk R/O",
  15. L"Exists",
  16. L"Ignored",
  17. L"Not Found",
  18. L"Conflict",
  19. L"Optimized",
  20. L"Lock Alt",
  21. NULL
  22. };
  23. #define COUNT_RESNAME (sizeof(s_cszResName)/sizeof(LPCWSTR)-1)
  24. BOOL ReadAndFormatLogFileV3( LPCWSTR cszFile )
  25. {
  26. BOOL fRet;
  27. CMappedFileRead cMFR;
  28. SRstrLogHdrBase sHdr1;
  29. SRstrLogHdrV3 sHdr2;
  30. //SRstrLogHdrV3Ex sHdr3;
  31. SRstrEntryHdr sEntHdr;
  32. DWORD i;
  33. DWORD dwFlags;
  34. WCHAR wszBuf1[SR_MAX_FILENAME_LENGTH];
  35. WCHAR wszBuf2[SR_MAX_FILENAME_LENGTH];
  36. WCHAR wszBuf3[SR_MAX_FILENAME_LENGTH];
  37. if ( !cMFR.Open( cszFile ) )
  38. goto Exit;
  39. if ( !cMFR.Read( &sHdr1, sizeof(sHdr1) ) )
  40. goto Exit;
  41. if ( ( sHdr1.dwSig1 != RSTRLOG_SIGNATURE1 ) ||
  42. ( sHdr1.dwSig2 != RSTRLOG_SIGNATURE2 ) )
  43. {
  44. fputs("Invalid restore log file signature...\n", stderr);
  45. goto Exit;
  46. }
  47. if ( HIWORD(sHdr1.dwVer) != RSTRLOG_VER_MAJOR )
  48. {
  49. fprintf(stderr, "Unknown restore log file version - %d (0x%08X)\n", HIWORD(sHdr1.dwVer), sHdr1.dwVer);
  50. goto Exit;
  51. }
  52. if ( !cMFR.Read( &sHdr2, sizeof(sHdr2) ) )
  53. goto Exit;
  54. printf( "Flags, " );
  55. if ( sHdr2.dwFlags == 0 )
  56. printf( "<none>" );
  57. else
  58. {
  59. if ( sHdr2.dwFlags & RLHF_SILENT )
  60. printf( " Silent" );
  61. if ( sHdr2.dwFlags & RLHF_UNDO )
  62. printf( " Undo" );
  63. }
  64. puts("");
  65. printf( "Restore Point, %d\n", sHdr2.dwRPNum );
  66. printf( "New Restore RP, %d\n", sHdr2.dwRPNew );
  67. printf( "# of Drives, %d\n", sHdr2.dwDrives );
  68. for ( i = 0; i < sHdr2.dwDrives; i++ )
  69. {
  70. if ( !cMFR.Read( &dwFlags ) )
  71. goto Exit;
  72. if ( !cMFR.ReadDynStrW( wszBuf1, MAX_PATH ) )
  73. goto Exit;
  74. if ( !cMFR.ReadDynStrW( wszBuf2, MAX_PATH ) )
  75. goto Exit;
  76. if ( !cMFR.ReadDynStrW( wszBuf3, MAX_PATH ) )
  77. goto Exit;
  78. printf( "%08X, %ls, %ls, %ls\n", dwFlags, wszBuf1, wszBuf2, wszBuf3 );
  79. }
  80. /*
  81. if ( !cMFR.Read( &sHdr3, sizeof(sHdr3) ) )
  82. goto Exit;
  83. printf( "New RP (Restore), %d\n", sHdr3.dwRPNew );
  84. printf( "# of Entries, %d\n", sHdr3.dwCount );
  85. */
  86. for ( i = 0; cMFR.GetAvail() > 0; i++ )
  87. {
  88. LPCWSTR cszOpr;
  89. WCHAR szRes[16];
  90. if ( !cMFR.Read( &sEntHdr, sizeof(sEntHdr) ) )
  91. goto Exit;
  92. if ( sEntHdr.dwID == RSTRLOGID_ENDOFMAP )
  93. {
  94. printf( "%4d, , , END OF MAP\n", i );
  95. continue;
  96. }
  97. else if ( sEntHdr.dwID == RSTRLOGID_STARTUNDO )
  98. {
  99. printf( "%4d, , , START UNDO\n", i );
  100. continue;
  101. }
  102. else if ( sEntHdr.dwID == RSTRLOGID_ENDOFUNDO )
  103. {
  104. printf( "%4d, , , END OF UNDO\n", i );
  105. continue;
  106. }
  107. else if ( sEntHdr.dwID == RSTRLOGID_SNAPSHOTFAIL )
  108. {
  109. printf( "%4d, , , SNAPSHOT RESTORE FAILED : Error=%ld\n", i, sEntHdr.dwErr );
  110. continue;
  111. }
  112. switch ( sEntHdr.dwOpr )
  113. {
  114. case OPR_DIR_CREATE :
  115. cszOpr = L"DirAdd";
  116. break;
  117. case OPR_DIR_RENAME :
  118. cszOpr = L"DirRen";
  119. break;
  120. case OPR_DIR_DELETE :
  121. cszOpr = L"DirDel";
  122. break;
  123. case OPR_FILE_ADD :
  124. cszOpr = L"Create";
  125. break;
  126. case OPR_FILE_DELETE :
  127. cszOpr = L"Delete";
  128. break;
  129. case OPR_FILE_MODIFY :
  130. cszOpr = L"Modify";
  131. break;
  132. case OPR_FILE_RENAME :
  133. cszOpr = L"Rename";
  134. break;
  135. case OPR_SETACL :
  136. cszOpr = L"SetACL";
  137. break;
  138. case OPR_SETATTRIB :
  139. cszOpr = L"Attrib";
  140. break;
  141. default :
  142. cszOpr = L"Unknown";
  143. break;
  144. }
  145. if ( !cMFR.ReadDynStrW( wszBuf1, SR_MAX_FILENAME_LENGTH ) )
  146. goto Exit;
  147. if ( !cMFR.ReadDynStrW( wszBuf2, SR_MAX_FILENAME_LENGTH ) )
  148. goto Exit;
  149. if ( !cMFR.ReadDynStrW( wszBuf3, SR_MAX_FILENAME_LENGTH ) )
  150. goto Exit;
  151. if ( sEntHdr.dwID == RSTRLOGID_COLLISION )
  152. {
  153. printf( "%4d, , , Collision, , , %ls, %ls, %ls\n", i, wszBuf1, wszBuf2, wszBuf3 );
  154. continue;
  155. }
  156. if ( sEntHdr.dwRes < COUNT_RESNAME )
  157. ::lstrcpy( szRes, s_cszResName[sEntHdr.dwRes] );
  158. else
  159. ::wsprintf( szRes, L"%X", sEntHdr.dwRes );
  160. printf( "%4d,%4d,%5I64d, %ls, %ls, %d, %ls, %ls, %ls\n", i, sEntHdr.dwID, sEntHdr.llSeq, cszOpr, szRes, sEntHdr.dwErr, wszBuf1, wszBuf2, wszBuf3 );
  161. }
  162. fRet = TRUE;
  163. Exit:
  164. cMFR.Close();
  165. return( TRUE );
  166. }
  167. // end of file