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.

299 lines
8.9 KiB

  1. #include "stdafx.hxx"
  2. #include "vss.h"
  3. #include "vswriter.h"
  4. #include "vsbackup.h"
  5. #include <debug.h>
  6. #include <cwriter.h>
  7. #include <lmshare.h>
  8. #include <lmaccess.h>
  9. LPCWSTR GetStringFromFailureType(HRESULT hrStatus)
  10. {
  11. LPCWSTR pwszFailureType = L"";
  12. switch (hrStatus)
  13. {
  14. case VSS_E_WRITERERROR_INCONSISTENTSNAPSHOT: pwszFailureType = L"VSS_E_WRITERERROR_INCONSISTENTSNAPSHOT"; break;
  15. case VSS_E_WRITERERROR_OUTOFRESOURCES: pwszFailureType = L"VSS_E_WRITERERROR_OUTOFRESOURCES"; break;
  16. case VSS_E_WRITERERROR_TIMEOUT: pwszFailureType = L"VSS_E_WRITERERROR_TIMEOUT"; break;
  17. case VSS_E_WRITERERROR_NONRETRYABLE: pwszFailureType = L"VSS_E_WRITERERROR_NONRETRYABLE"; break;
  18. case VSS_E_WRITERERROR_RETRYABLE: pwszFailureType = L"VSS_E_WRITERERROR_RETRYABLE"; break;
  19. case VSS_E_BAD_STATE: pwszFailureType = L"VSS_E_BAD_STATE"; break;
  20. case VSS_E_PROVIDER_ALREADY_REGISTERED: pwszFailureType = L"VSS_E_PROVIDER_ALREADY_REGISTERED"; break;
  21. case VSS_E_PROVIDER_NOT_REGISTERED: pwszFailureType = L"VSS_E_PROVIDER_NOT_REGISTERED"; break;
  22. case VSS_E_PROVIDER_VETO: pwszFailureType = L"VSS_E_PROVIDER_VETO"; break;
  23. case VSS_E_PROVIDER_IN_USE: pwszFailureType = L"VSS_E_PROVIDER_IN_USE"; break;
  24. case VSS_E_OBJECT_NOT_FOUND: pwszFailureType = L"VSS_E_OBJECT_NOT_FOUND"; break;
  25. case VSS_S_ASYNC_PENDING: pwszFailureType = L"VSS_S_ASYNC_PENDING"; break;
  26. case VSS_S_ASYNC_FINISHED: pwszFailureType = L"VSS_S_ASYNC_FINISHED"; break;
  27. case VSS_S_ASYNC_CANCELLED: pwszFailureType = L"VSS_S_ASYNC_CANCELLED"; break;
  28. case VSS_E_VOLUME_NOT_SUPPORTED: pwszFailureType = L"VSS_E_VOLUME_NOT_SUPPORTED"; break;
  29. case VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER: pwszFailureType = L"VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER"; break;
  30. case VSS_E_OBJECT_ALREADY_EXISTS: pwszFailureType = L"VSS_E_OBJECT_ALREADY_EXISTS"; break;
  31. case VSS_E_UNEXPECTED_PROVIDER_ERROR: pwszFailureType = L"VSS_E_UNEXPECTED_PROVIDER_ERROR"; break;
  32. case VSS_E_CORRUPT_XML_DOCUMENT: pwszFailureType = L"VSS_E_CORRUPT_XML_DOCUMENT"; break;
  33. case VSS_E_INVALID_XML_DOCUMENT: pwszFailureType = L"VSS_E_INVALID_XML_DOCUMENT"; break;
  34. case VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED: pwszFailureType = L"VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED"; break;
  35. case VSS_E_FLUSH_WRITES_TIMEOUT: pwszFailureType = L"VSS_E_FLUSH_WRITES_TIMEOUT"; break;
  36. case VSS_E_HOLD_WRITES_TIMEOUT: pwszFailureType = L"VSS_E_HOLD_WRITES_TIMEOUT"; break;
  37. case VSS_E_UNEXPECTED_WRITER_ERROR: pwszFailureType = L"VSS_E_UNEXPECTED_WRITER_ERROR"; break;
  38. case VSS_E_SNAPSHOT_SET_IN_PROGRESS: pwszFailureType = L"VSS_E_SNAPSHOT_SET_IN_PROGRESS"; break;
  39. case VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED: pwszFailureType = L"VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED"; break;
  40. case VSS_E_WRITER_INFRASTRUCTURE: pwszFailureType = L"VSS_E_WRITER_INFRASTRUCTURE"; break;
  41. case VSS_E_WRITER_NOT_RESPONDING: pwszFailureType = L"VSS_E_WRITER_NOT_RESPONDING"; break;
  42. case VSS_E_WRITER_ALREADY_SUBSCRIBED: pwszFailureType = L"VSS_E_WRITER_ALREADY_SUBSCRIBED"; break;
  43. case NOERROR:
  44. default:
  45. break;
  46. }
  47. return (pwszFailureType);
  48. }
  49. // This function displays the formatted message at the console and throws
  50. // The passed return code will be returned by vsreq.exe
  51. void Error(
  52. IN INT nReturnCode,
  53. IN const WCHAR* pwszMsgFormat,
  54. IN ...
  55. )
  56. {
  57. va_list marker;
  58. va_start( marker, pwszMsgFormat );
  59. vwprintf( pwszMsgFormat, marker );
  60. va_end( marker );
  61. BS_ASSERT(FALSE);
  62. // throw that return code.
  63. throw(nReturnCode);
  64. }
  65. // convert VSS_RESTORE_TARGET to string
  66. LPCWSTR WszFromRestoreTarget
  67. (
  68. IN VSS_RESTORE_TARGET rt
  69. )
  70. {
  71. switch(rt)
  72. {
  73. default:
  74. return L"Undefined";
  75. case VSS_RT_ORIGINAL:
  76. return L"Original";
  77. case VSS_RT_ALTERNATE:
  78. return L"Alternate";
  79. case VSS_RT_DIRECTED:
  80. return L"Directed";
  81. }
  82. }
  83. // convert VSS_FILE_RESTORE_STATUS to string
  84. LPCWSTR WszFromFileRestoreStatus
  85. (
  86. IN VSS_FILE_RESTORE_STATUS rs
  87. )
  88. {
  89. switch(rs)
  90. {
  91. default:
  92. return L"Undefined";
  93. case VSS_RS_NONE:
  94. return L"None";
  95. case VSS_RS_ALL:
  96. return L"All";
  97. case VSS_RS_FAILED:
  98. return L"Failed";
  99. }
  100. }
  101. void PrintPartialFiles(IVssComponent *pComponent)
  102. {
  103. UINT cPartialFiles;
  104. HRESULT hr;
  105. CHECK_SUCCESS(pComponent->GetPartialFileCount(&cPartialFiles));
  106. if (cPartialFiles > 0)
  107. wprintf(L"\n%d Partial Files:\n\n", cPartialFiles);
  108. for(UINT iFile = 0; iFile < cPartialFiles; iFile++)
  109. {
  110. CComBSTR bstrPath;
  111. CComBSTR bstrFilename;
  112. CComBSTR bstrRanges;
  113. CComBSTR bstrMetadata;
  114. CHECK_SUCCESS(pComponent->GetPartialFile
  115. (
  116. iFile,
  117. &bstrPath,
  118. &bstrFilename,
  119. &bstrRanges,
  120. &bstrMetadata
  121. ));
  122. wprintf(L"Path=%s, Name=%s\nRanges=%s\nMetadata=%s\n\n",
  123. bstrPath, bstrFilename, bstrRanges, bstrMetadata);
  124. }
  125. }
  126. void PrintDifferencedFiles(IVssComponent* pComponent)
  127. {
  128. UINT cDifferencedFiles;
  129. HRESULT hr;
  130. CHECK_SUCCESS(pComponent->GetDifferencedFilesCount(&cDifferencedFiles));
  131. if (cDifferencedFiles > 0)
  132. wprintf(L"\n%d Differenced Files:\n\n", cDifferencedFiles);
  133. for(UINT iDiff = 0; iDiff < cDifferencedFiles; iDiff++)
  134. {
  135. CComBSTR bstrPath;
  136. CComBSTR bstrFilename;
  137. BOOL bRecursive;
  138. CComBSTR bstrLSN;
  139. FILETIME ftLastModify;
  140. CHECK_SUCCESS(pComponent->GetDifferencedFile
  141. (
  142. iDiff,
  143. &bstrPath,
  144. &bstrFilename,
  145. &bRecursive,
  146. &bstrLSN,
  147. &ftLastModify
  148. ));
  149. wprintf(L"Path=%s, Name=%s\nRecursive=%s,LSN=%s\nLastModifyHigh=%x\nLastModifyLow=%x\n\n",
  150. bstrPath,
  151. bstrFilename,
  152. (bRecursive) ? L"yes" : L"no",
  153. bstrLSN,
  154. ftLastModify.dwHighDateTime,
  155. ftLastModify.dwLowDateTime);
  156. }
  157. }
  158. void PrintNewTargets(IVssComponent *pComponent)
  159. {
  160. UINT cTarget;
  161. HRESULT hr;
  162. CHECK_SUCCESS(pComponent->GetNewTargetCount(&cTarget));
  163. if (cTarget > 0)
  164. wprintf(L"\n%d New Targets:\n\n", cTarget);
  165. for(UINT iTarget = 0; iTarget < cTarget; iTarget++)
  166. {
  167. CComPtr<IVssWMFiledesc> pFiledesc;
  168. CHECK_SUCCESS(pComponent->GetNewTarget
  169. (
  170. iTarget,
  171. &pFiledesc
  172. ));
  173. CComBSTR bstrSourcePath;
  174. CComBSTR bstrFilespec;
  175. CComBSTR bstrAlt;
  176. bool bRecursive = false;
  177. CHECK_SUCCESS(pFiledesc->GetPath(&bstrSourcePath));
  178. CHECK_SUCCESS(pFiledesc->GetFilespec(&bstrFilespec));
  179. CHECK_SUCCESS(pFiledesc->GetRecursive(&bRecursive));
  180. CHECK_SUCCESS(pFiledesc->GetAlternateLocation(&bstrAlt));
  181. wprintf(L"path = %s\nfilespec = %s\nrecursive = %s\nalternateLocation=%s\n",
  182. bstrSourcePath,
  183. bstrFilespec,
  184. (bRecursive) ? L"yes" : L"no",
  185. bstrAlt
  186. );
  187. }
  188. }
  189. void PrintDirectedTargets(IVssComponent *pComponent)
  190. {
  191. UINT cTarget;
  192. HRESULT hr;
  193. CHECK_SUCCESS(pComponent->GetDirectedTargetCount(&cTarget));
  194. if (cTarget > 0)
  195. wprintf(L"\n%d Directed Targets:\n\n", cTarget);
  196. for(UINT iTarget = 0; iTarget < cTarget; iTarget++)
  197. {
  198. CComBSTR bstrSourcePath;
  199. CComBSTR bstrSourceFilespec;
  200. CComBSTR bstrSourceRanges;
  201. CComBSTR bstrTargetPath;
  202. CComBSTR bstrTargetFilespec;
  203. CComBSTR bstrTargetRanges;
  204. CHECK_SUCCESS(pComponent->GetDirectedTarget
  205. (
  206. iTarget,
  207. &bstrSourcePath,
  208. &bstrSourceFilespec,
  209. &bstrSourceRanges,
  210. &bstrTargetPath,
  211. &bstrTargetFilespec,
  212. &bstrTargetRanges
  213. ));
  214. wprintf(L"Source Path=%s, Name=%s\nRanges=%s\nTarget Path=%s, Name=%s\nRanges=%s\n",
  215. bstrSourcePath,
  216. bstrSourceFilespec,
  217. bstrSourceRanges,
  218. bstrTargetPath,
  219. bstrTargetFilespec,
  220. bstrTargetRanges);
  221. }
  222. }
  223. void PrintRestoreSubcomponents(IVssComponent *pComponent)
  224. {
  225. UINT cSub;
  226. HRESULT hr;
  227. CHECK_SUCCESS(pComponent->GetRestoreSubcomponentCount(&cSub));
  228. if (cSub > 0)
  229. wprintf(L"\n%d Restore Subcomponents:\n\n", cSub);
  230. for(UINT iSub = 0; iSub < cSub; iSub++)
  231. {
  232. CComBSTR bstrLogicalPath;
  233. CComBSTR bstrComponentName;
  234. bool bRepair;
  235. CHECK_SUCCESS(pComponent->GetRestoreSubcomponent
  236. (
  237. iSub,
  238. &bstrLogicalPath,
  239. &bstrComponentName,
  240. &bRepair
  241. ));
  242. wprintf(L"Logical Path=%s, Name=%s, Repair=%s\n",
  243. bstrLogicalPath,
  244. bstrComponentName,
  245. bRepair ? L"Yes" : L"No");
  246. }
  247. }