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.

297 lines
7.7 KiB

  1. #include <stdafx.h>
  2. #include <esent.h>
  3. #include <comadmin.h>
  4. #include "vs_inc.hxx"
  5. #include "vs_idl.hxx"
  6. #include "comadmin.hxx"
  7. #include "vswriter.h"
  8. #include <jetwriter.h>
  9. #include <ijetwriter.h>
  10. ////////////////////////////////////////////////////////////////////////
  11. // Standard foo for file name aliasing. This code block must be after
  12. // all includes of VSS header files.
  13. //
  14. #ifdef VSS_FILE_ALIAS
  15. #undef VSS_FILE_ALIAS
  16. #endif
  17. #define VSS_FILE_ALIAS "WSHJTWRC"
  18. //
  19. ////////////////////////////////////////////////////////////////////////
  20. // destructor
  21. __declspec(dllexport) CVssJetWriter::~CVssJetWriter()
  22. {
  23. BS_ASSERT(m_pWriter == NULL);
  24. }
  25. // routine for passing arguments between threads
  26. typedef struct _JW_INIT_ARGS
  27. {
  28. VSS_ID idWriter;
  29. LPCWSTR wszWriterName;
  30. bool bSystemService;
  31. bool bBootableSystemState;
  32. LPCWSTR wszFilesToInclude;
  33. LPCWSTR wszFilesToExclude;
  34. CVssJetWriter *pobj;
  35. } JW_INIT_ARGS;
  36. // separate MTA thread for doing initialization
  37. DWORD CVssJetWriter::InitializeThreadFunc(VOID *pv)
  38. {
  39. CVssFunctionTracer ft(VSSDBG_GEN, L"InitializeThreadFunc");
  40. JW_INIT_ARGS *pargs = (JW_INIT_ARGS *) pv;
  41. bool bCoInitialized = false;
  42. try
  43. {
  44. // intialize MTA thread
  45. ft.hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  46. if (ft.HrFailed())
  47. ft.Throw
  48. (
  49. VSSDBG_GEN,
  50. E_UNEXPECTED,
  51. L"CoInitializeEx failed 0x%08lx", ft.hr
  52. );
  53. bCoInitialized = true;
  54. // call internal object to initialize
  55. ft.hr = CVssIJetWriter::Initialize
  56. (
  57. pargs->idWriter,
  58. pargs->wszWriterName,
  59. pargs->bSystemService,
  60. pargs->bBootableSystemState,
  61. pargs->wszFilesToInclude,
  62. pargs->wszFilesToExclude,
  63. pargs->pobj,
  64. &pargs->pobj->m_pWriter
  65. );
  66. if(ft.HrFailed())
  67. {
  68. //
  69. // Add more granular error code -
  70. // 752163 Application/Service might have inconsistent
  71. // backup for their data-store without any warning or other indication
  72. //
  73. switch(ft.hr)
  74. {
  75. case E_INVALIDARG:
  76. case E_OUTOFMEMORY:
  77. case E_ACCESSDENIED:
  78. ft.Throw(VSSDBG_GEN, ft.hr,
  79. L"CvssIJetWriter::Initialize failed");
  80. default:
  81. ft.Throw(VSSDBG_GEN, E_UNEXPECTED,
  82. L"CvssIJetWriter::Initialize failed [0x%08lx]", ft.hr);
  83. }
  84. }
  85. }
  86. VSS_STANDARD_CATCH(ft)
  87. // save result of initialization
  88. pargs->pobj->m_hrInitialized = ft.hr;
  89. if (bCoInitialized)
  90. CoUninitialize();
  91. return 0;
  92. }
  93. // initialize method on external thread
  94. __declspec(dllexport) HRESULT CVssJetWriter::Initialize
  95. (
  96. IN GUID idWriter,
  97. IN LPCWSTR wszWriterName,
  98. bool bSystemService,
  99. bool bBootableSystemState,
  100. LPCWSTR wszFilesToInclude,
  101. LPCWSTR wszFilesToExclude
  102. )
  103. {
  104. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::Initialize");
  105. try
  106. {
  107. DWORD tid;
  108. // setup arguments to thread
  109. JW_INIT_ARGS args;
  110. args.idWriter = idWriter;
  111. args.wszWriterName = wszWriterName;
  112. args.bSystemService = bSystemService;
  113. args.bBootableSystemState = bBootableSystemState;
  114. args.wszFilesToInclude = wszFilesToInclude;
  115. args.wszFilesToExclude = wszFilesToExclude;
  116. args.pobj = this;
  117. // create thread
  118. HANDLE hThread = CreateThread
  119. (
  120. NULL,
  121. 256*1024,
  122. CVssJetWriter::InitializeThreadFunc,
  123. &args,
  124. 0,
  125. &tid
  126. );
  127. if (hThread == NULL)
  128. ft.Throw
  129. (
  130. VSSDBG_GEN,
  131. E_UNEXPECTED,
  132. L"CreateThread failed with error %d",
  133. GetLastError()
  134. );
  135. // wait for thread to complete
  136. WaitForSingleObject(hThread, INFINITE);
  137. CloseHandle(hThread);
  138. }
  139. VSS_STANDARD_CATCH(ft)
  140. if (!ft.HrFailed())
  141. // get result of initialization
  142. ft.hr = m_hrInitialized;
  143. return ft.hr;
  144. }
  145. __declspec(dllexport) void CVssJetWriter::Uninitialize()
  146. {
  147. // call uninitialize
  148. if (m_pWriter)
  149. {
  150. CVssIJetWriter::Uninitialize((PVSSIJETWRITER) m_pWriter);
  151. m_pWriter = NULL;
  152. }
  153. }
  154. __declspec(dllexport) bool CVssJetWriter::OnIdentify(IVssCreateWriterMetadata *pIVssWriterMetadata)
  155. {
  156. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnIdentify");
  157. return true;
  158. }
  159. __declspec(dllexport) bool CVssJetWriter::OnPrepareBackupBegin(IN IVssWriterComponents *pIVssWriterComponents)
  160. {
  161. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPrepareBackupBegin");
  162. return true;
  163. }
  164. __declspec(dllexport) bool CVssJetWriter::OnPrepareBackupEnd(IN IVssWriterComponents *pIVssWriterComponents,
  165. bool fJetPrepareSucceeded)
  166. {
  167. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPrepareBackupEnd");
  168. return fJetPrepareSucceeded;
  169. }
  170. __declspec(dllexport) bool CVssJetWriter::OnPrepareSnapshotBegin()
  171. {
  172. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPrepareSnapshotBegin");
  173. return true;
  174. }
  175. __declspec(dllexport) bool CVssJetWriter::OnPrepareSnapshotEnd(bool fJetPrepareSucceeded)
  176. {
  177. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPrepareSnapshotEnd");
  178. return fJetPrepareSucceeded;
  179. }
  180. __declspec(dllexport) bool CVssJetWriter::OnFreezeBegin()
  181. {
  182. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnFreezeBegin");
  183. return true;
  184. }
  185. __declspec(dllexport) bool CVssJetWriter::OnFreezeEnd(bool fJetFreezeSucceeded)
  186. {
  187. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnFreezeEnd");
  188. return fJetFreezeSucceeded;
  189. }
  190. __declspec(dllexport) bool CVssJetWriter::OnThawBegin()
  191. {
  192. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnThawBegin");
  193. return true;
  194. }
  195. __declspec(dllexport) bool CVssJetWriter::OnThawEnd(bool fJetThawSucceeded)
  196. {
  197. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnThawEnd");
  198. return fJetThawSucceeded;
  199. }
  200. __declspec(dllexport) bool CVssJetWriter::OnPostSnapshot(IN IVssWriterComponents *pIVssWriterComponents)
  201. {
  202. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPostSnapshot");
  203. return true;
  204. }
  205. __declspec(dllexport) void CVssJetWriter::OnAbortBegin()
  206. {
  207. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnAbortBegin");
  208. }
  209. __declspec(dllexport) void CVssJetWriter::OnAbortEnd()
  210. {
  211. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnAbortEnd");
  212. }
  213. __declspec(dllexport) bool CVssJetWriter::OnBackupCompleteBegin(IN IVssWriterComponents *pComponent)
  214. {
  215. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnBackupCompleteBegin");
  216. return true;
  217. }
  218. __declspec(dllexport) bool CVssJetWriter::OnBackupCompleteEnd(IN IVssWriterComponents *pComponent,
  219. bool fJetBackupCompleteSucceeded)
  220. {
  221. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnBackupCompleteEnd");
  222. return true;
  223. }
  224. __declspec(dllexport) bool CVssJetWriter::OnPreRestoreBegin(IN IVssWriterComponents *pIVssWriterComponents)
  225. {
  226. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPreRestoreBegin");
  227. return true;
  228. }
  229. __declspec(dllexport) bool CVssJetWriter::OnPreRestoreEnd(IN IVssWriterComponents *pIVssWriterComponents,
  230. IN bool fJetRestoreSucceeded)
  231. {
  232. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPreRestoreEnd");
  233. return true;
  234. }
  235. __declspec(dllexport) bool CVssJetWriter::OnPostRestoreBegin(IN IVssWriterComponents *pIVssWriterComponents)
  236. {
  237. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPostRestoreBegin");
  238. return true;
  239. }
  240. __declspec(dllexport) bool CVssJetWriter::OnPostRestoreEnd(IN IVssWriterComponents *pIVssWriterComponents,
  241. IN bool fJetRestoreSucceeded)
  242. {
  243. CVssFunctionTracer ft(VSSDBG_GEN, L"CVssJetWriter::OnPostRestoreEnd");
  244. return true;
  245. }