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.

280 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: GetRstrLog.cxx
  7. //
  8. // Contents: Intepreting the rstrlog.dat to a more readable format
  9. //
  10. // Objects:
  11. //
  12. // Coupling:
  13. //
  14. // Notes:
  15. //
  16. // History: 03-May-2001 WeiyouC Copied from dev code and minor rewite
  17. //
  18. //----------------------------------------------------------------------------
  19. //--------------------------------------------------------------------------
  20. // includes
  21. //--------------------------------------------------------------------------
  22. #include "SrHeader.hxx"
  23. #include <srdefs.h>
  24. #include <restmap.h>
  25. #include <srshell.h>
  26. #include "mfr.h"
  27. //--------------------------------------------------------------------------
  28. // Defines
  29. //--------------------------------------------------------------------------
  30. #define COUNT_RESNAME (sizeof(s_cszResName)/sizeof(LPCWSTR)-1)
  31. //--------------------------------------------------------------------------
  32. // Global variables
  33. //--------------------------------------------------------------------------
  34. static LPCWSTR s_cszResName[] =
  35. {
  36. L"",
  37. L"Fail",
  38. L"OK",
  39. L"Lock",
  40. L"Disk R/O",
  41. L"Exists",
  42. L"Ignored",
  43. L"Not Found",
  44. L"Conflict",
  45. L"Optimized",
  46. L"Lock Alt",
  47. NULL
  48. };
  49. //+---------------------------------------------------------------------------
  50. //
  51. // Function: ParseRstrLog
  52. //
  53. // Synopsis: Parse rstrlog.dat to a readable format
  54. //
  55. // Arguments: ptszRstrLog -- restore log
  56. // ptszReadableLog -- the result log
  57. //
  58. // Returns: HRESULT
  59. //
  60. // History: 20-04-2001 weiyouc Created
  61. //
  62. // Notes:
  63. //
  64. //----------------------------------------------------------------------------
  65. HRESULT ParseRstrLog(LPTSTR ptszRstrLog,
  66. LPTSTR ptszReadableLog)
  67. {
  68. HRESULT hr = S_OK;
  69. DWORD i = 0;
  70. DWORD dwFlags = 0;
  71. FILE* fpLog = NULL;
  72. CMappedFileRead cMFR;
  73. SRstrLogHdrBase sHdr1;
  74. SRstrLogHdrV3 sHdr2;
  75. SRstrEntryHdr sEntHdr;
  76. WCHAR wszBuf1[SR_MAX_FILENAME_LENGTH];
  77. WCHAR wszBuf2[SR_MAX_FILENAME_LENGTH];
  78. WCHAR wszBuf3[SR_MAX_FILENAME_LENGTH];
  79. DH_VDATEPTRIN(ptszRstrLog, TCHAR);
  80. DH_VDATEPTRIN(ptszReadableLog, TCHAR);
  81. fpLog = _tfopen(ptszReadableLog, TEXT("w"));
  82. if (NULL == fpLog)
  83. goto ErrReturn;
  84. if (_taccess(ptszRstrLog, 0) == -1)
  85. goto ErrReturn;
  86. if (!cMFR.Open(ptszRstrLog))
  87. goto ErrReturn;
  88. if (!cMFR.Read(&sHdr1, sizeof(sHdr1)))
  89. goto ErrReturn;
  90. if ((sHdr1.dwSig1 != RSTRLOG_SIGNATURE1) ||
  91. (sHdr1.dwSig2 != RSTRLOG_SIGNATURE2))
  92. {
  93. fprintf(stderr, "Invalid restore log file signature...\n");
  94. goto ErrReturn;
  95. }
  96. if (HIWORD(sHdr1.dwVer) != RSTRLOG_VER_MAJOR)
  97. {
  98. fprintf(stderr,
  99. "Unknown restore log file version - %d (0x%08X)\n",
  100. HIWORD(sHdr1.dwVer), sHdr1.dwVer);
  101. goto ErrReturn;
  102. }
  103. if (!cMFR.Read(&sHdr2, sizeof(sHdr2)))
  104. goto ErrReturn;
  105. fprintf(fpLog, "Flags, ");
  106. if (sHdr2.dwFlags == 0)
  107. {
  108. fprintf(fpLog, "<none>");
  109. }
  110. else
  111. {
  112. if (sHdr2.dwFlags & RLHF_SILENT)
  113. fprintf(fpLog, " Silent");
  114. if (sHdr2.dwFlags & RLHF_UNDO)
  115. fprintf(fpLog, " Undo");
  116. }
  117. fprintf(fpLog, "\n");
  118. fprintf(fpLog, "Restore Point, %d\n", sHdr2.dwRPNum);
  119. fprintf(fpLog, "New Restore RP, %d\n", sHdr2.dwRPNew);
  120. fprintf(fpLog, "# of Drives, %d\n", sHdr2.dwDrives);
  121. for (i = 0; i < sHdr2.dwDrives; i++)
  122. {
  123. if (!cMFR.Read(&dwFlags))
  124. goto ErrReturn;
  125. if (!cMFR.ReadDynStrW(wszBuf1, MAX_PATH))
  126. goto ErrReturn;
  127. if (!cMFR.ReadDynStrW(wszBuf2, MAX_PATH))
  128. goto ErrReturn;
  129. if (!cMFR.ReadDynStrW(wszBuf3, MAX_PATH))
  130. goto ErrReturn;
  131. fprintf(fpLog,
  132. "%08X, %ls, %ls, %ls\n",
  133. dwFlags,
  134. wszBuf1,
  135. wszBuf2,
  136. wszBuf3);
  137. }
  138. for (i = 0; cMFR.GetAvail() > 0; i++)
  139. {
  140. LPCWSTR cszOpr;
  141. WCHAR szRes[16];
  142. if (!cMFR.Read(&sEntHdr, sizeof(sEntHdr)))
  143. goto ErrReturn;
  144. if (sEntHdr.dwID == RSTRLOGID_ENDOFMAP)
  145. {
  146. fprintf(fpLog,
  147. "%4d, , , END OF MAP\n",
  148. i);
  149. continue;
  150. }
  151. else if (sEntHdr.dwID == RSTRLOGID_STARTUNDO)
  152. {
  153. fprintf(fpLog,
  154. "%4d, , , START UNDO\n",
  155. i);
  156. continue;
  157. }
  158. else if (sEntHdr.dwID == RSTRLOGID_ENDOFUNDO)
  159. {
  160. fprintf(fpLog,
  161. "%4d, , , END OF UNDO\n",
  162. i);
  163. continue;
  164. }
  165. else if (sEntHdr.dwID == RSTRLOGID_SNAPSHOTFAIL)
  166. {
  167. fprintf(fpLog,
  168. "%4d, , , SNAPSHOT RESTORE FAILED : Error=%ld\n",
  169. i,
  170. sEntHdr.dwErr);
  171. continue;
  172. }
  173. switch (sEntHdr.dwOpr)
  174. {
  175. case OPR_DIR_CREATE :
  176. cszOpr = L"DirAdd";
  177. break;
  178. case OPR_DIR_RENAME :
  179. cszOpr = L"DirRen";
  180. break;
  181. case OPR_DIR_DELETE :
  182. cszOpr = L"DirDel";
  183. break;
  184. case OPR_FILE_ADD :
  185. cszOpr = L"Create";
  186. break;
  187. case OPR_FILE_DELETE :
  188. cszOpr = L"Delete";
  189. break;
  190. case OPR_FILE_MODIFY :
  191. cszOpr = L"Modify";
  192. break;
  193. case OPR_FILE_RENAME :
  194. cszOpr = L"Rename";
  195. break;
  196. case OPR_SETACL :
  197. cszOpr = L"SetACL";
  198. break;
  199. case OPR_SETATTRIB :
  200. cszOpr = L"Attrib";
  201. break;
  202. default :
  203. cszOpr = L"Unknown";
  204. break;
  205. }
  206. if (!cMFR.ReadDynStrW(wszBuf1, SR_MAX_FILENAME_LENGTH))
  207. goto ErrReturn;
  208. if (!cMFR.ReadDynStrW(wszBuf2, SR_MAX_FILENAME_LENGTH))
  209. goto ErrReturn;
  210. if (!cMFR.ReadDynStrW(wszBuf3, SR_MAX_FILENAME_LENGTH))
  211. goto ErrReturn;
  212. if (sEntHdr.dwID == RSTRLOGID_COLLISION)
  213. {
  214. fprintf(fpLog,
  215. "%4d, , , Collision, , , %ls, %ls, %ls\n",
  216. i,
  217. wszBuf1,
  218. wszBuf2,
  219. wszBuf3);
  220. continue;
  221. }
  222. if (sEntHdr.dwRes < COUNT_RESNAME)
  223. {
  224. ::lstrcpy(szRes, s_cszResName[sEntHdr.dwRes]);
  225. }
  226. else
  227. {
  228. ::wsprintf(szRes, L"%X", sEntHdr.dwRes);
  229. }
  230. fprintf(fpLog,
  231. "%4d,%4d,%5I64d, %ls, %ls, %d, %ls, %ls, %ls\n",
  232. i,
  233. sEntHdr.dwID,
  234. sEntHdr.llSeq,
  235. cszOpr,
  236. szRes,
  237. sEntHdr.dwErr,
  238. wszBuf1,
  239. wszBuf2,
  240. wszBuf3);
  241. }
  242. ErrReturn:
  243. cMFR.Close();
  244. if (NULL != fpLog)
  245. {
  246. fclose(fpLog);
  247. }
  248. return hr;
  249. }
  250. // end of file