Source code of Windows XP (NT5)
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.

719 lines
16 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Abstract:
  4. @doc
  5. @module Writer.h | Declaration of Writer
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 08/18/1999
  9. TBD:
  10. Add comments.
  11. Revision History:
  12. Name Date Comments
  13. aoltean 08/18/1999 Created
  14. brianb 03/28/2000 hid implementation details
  15. mikejohn 09/18/2000 176860: Added calling convention methods where missing
  16. --*/
  17. #ifndef __CVSS_WRITER_H_
  18. #define __CVSS_WRITER_H_
  19. // declaration of how application data is used
  20. typedef enum VSS_USAGE_TYPE
  21. {
  22. VSS_UT_UNDEFINED = 0,
  23. VSS_UT_BOOTABLESYSTEMSTATE, // formerly "system state"
  24. VSS_UT_SYSTEMSERVICE, // system service
  25. VSS_UT_USERDATA, // user data
  26. VSS_UT_OTHER // unclassified
  27. };
  28. typedef enum VSS_SOURCE_TYPE
  29. {
  30. VSS_ST_UNDEFINED = 0,
  31. VSS_ST_TRANSACTEDDB, // transacted db (e.g., SQL Server, JET Blue)
  32. VSS_ST_NONTRANSACTEDDB, // not transacted(e.g., Jet Red)
  33. VSS_ST_OTHER // unclassified
  34. };
  35. typedef enum VSS_RESTOREMETHOD_ENUM
  36. {
  37. VSS_RME_UNDEFINED = 0,
  38. VSS_RME_RESTORE_IF_NOT_THERE,
  39. VSS_RME_RESTORE_IF_CAN_REPLACE,
  40. VSS_RME_STOP_RESTORE_START,
  41. VSS_RME_RESTORE_TO_ALTERNATE_LOCATION,
  42. VSS_RME_RESTORE_AT_REBOOT,
  43. VSS_RME_CUSTOM
  44. };
  45. typedef enum VSS_WRITERRESTORE_ENUM
  46. {
  47. VSS_WRE_UNDEFINED = 0,
  48. VSS_WRE_NEVER,
  49. VSS_WRE_IF_REPLACE_FAILS,
  50. VSS_WRE_ALWAYS
  51. };
  52. typedef enum VSS_COMPONENT_TYPE
  53. {
  54. VSS_CT_UNDEFINED = 0,
  55. VSS_CT_DATABASE,
  56. VSS_CT_FILEGROUP
  57. };
  58. typedef enum VSS_ALTERNATE_WRITER_STATE
  59. {
  60. VSS_AWS_UNDEFINED = 0,
  61. VSS_AWS_NO_ALTERNATE_WRITER,
  62. VSS_AWS_ALTERNATE_WRITER_EXISTS,
  63. VSS_AWS_THIS_IS_ALTERNATE_WRITER
  64. };
  65. // Flags to specify which types of events to receive. Used in Subscribe.
  66. typedef enum VSS_SUBSCRIBE_MASK
  67. {
  68. VSS_SM_POST_SNAPSHOT_FLAG = 0x00000001,
  69. VSS_SM_BACKUP_EVENTS_FLAG = 0x00000002,
  70. VSS_SM_RESTORE_EVENTS_FLAG = 0x00000004,
  71. VSS_SM_IO_THROTTLING_FLAG = 0x00000008,
  72. VSS_SM_ALL_FLAGS = 0xffffffff
  73. };
  74. // enumeration of restore targets
  75. typedef enum VSS_RESTORE_TARGET
  76. {
  77. VSS_RT_UNDEFINED = 0,
  78. VSS_RT_ORIGINAL,
  79. VSS_RT_ALTERNATE,
  80. VSS_RT_NEW,
  81. VSS_RT_DIRECTED
  82. };
  83. // enumeration of file restore status codes
  84. typedef enum VSS_FILE_RESTORE_STATUS
  85. {
  86. VSS_RS_UNDEFINED = 0,
  87. VSS_RS_NONE,
  88. VSS_RS_ALL,
  89. VSS_RS_FAILED
  90. };
  91. // file description
  92. class IVssWMFiledesc : public IUnknown
  93. {
  94. public:
  95. // get path to toplevel directory
  96. STDMETHOD(GetPath)(OUT BSTR *pbstrPath) = 0;
  97. // get filespec (may include wildcards)
  98. STDMETHOD(GetFilespec)(OUT BSTR *pbstrFilespec) = 0;
  99. // is path a directory or root of a tree
  100. STDMETHOD(GetRecursive)(OUT bool *pbRecursive) = 0;
  101. // alternate location for files
  102. STDMETHOD(GetAlternateLocation)(OUT BSTR *pbstrAlternateLocation) = 0;
  103. };
  104. // backup components interface
  105. class IVssComponent : public IUnknown
  106. {
  107. public:
  108. // obtain logical path of component
  109. STDMETHOD(GetLogicalPath)(OUT BSTR *pbstrPath) = 0;
  110. // obtain component type(VSS_CT_DATABASE or VSS_CT_FILEGROUP)
  111. STDMETHOD(GetComponentType)(VSS_COMPONENT_TYPE *pct) = 0;
  112. // get component name
  113. STDMETHOD(GetComponentName)(OUT BSTR *pbstrName) = 0;
  114. // determine whether the component was successfully backed up.
  115. STDMETHOD(GetBackupSucceeded)(OUT bool *pbSucceeded) = 0;
  116. // get altermative location mapping count
  117. STDMETHOD(GetAlternateLocationMappingCount)
  118. (
  119. OUT UINT *pcMappings
  120. ) = 0;
  121. // get a paraticular alternative location mapping
  122. STDMETHOD(GetAlternateLocationMapping)
  123. (
  124. IN UINT iMapping,
  125. OUT IVssWMFiledesc **ppFiledesc
  126. ) = 0;
  127. // set the backup metadata for a component
  128. STDMETHOD(SetBackupMetadata)
  129. (
  130. IN LPCWSTR wszData
  131. ) = 0;
  132. // get the backup metadata for a component
  133. STDMETHOD(GetBackupMetadata)
  134. (
  135. OUT BSTR *pbstrData
  136. ) = 0;
  137. // indicate that only ranges in the file are to be backed up
  138. STDMETHOD(AddPartialFile)
  139. (
  140. IN LPCWSTR wszPath,
  141. IN LPCWSTR wszFilename,
  142. IN LPCWSTR wszRanges,
  143. IN LPCWSTR wszMetadata
  144. ) = 0;
  145. // get count of partial file declarations
  146. STDMETHOD(GetPartialFileCount)
  147. (
  148. OUT UINT *pcPartialFiles
  149. ) = 0;
  150. // get a partial file declaration
  151. STDMETHOD(GetPartialFile)
  152. (
  153. IN UINT iPartialFile,
  154. OUT BSTR *pbstrPath,
  155. OUT BSTR *pbstrFilename,
  156. OUT BSTR *pbstrRange,
  157. OUT BSTR *pbstrMetadata
  158. ) = 0;
  159. // determine if the component is selected to be restored
  160. STDMETHOD(IsSelectedForRestore)
  161. (
  162. OUT bool *pbSelectedForRestore
  163. ) = 0;
  164. STDMETHOD(GetAdditionalRestores)
  165. (
  166. OUT bool *pbAdditionalRestores
  167. ) = 0;
  168. // add a new location target for a file to be restored
  169. STDMETHOD(AddNewTarget)
  170. (
  171. IN LPCWSTR wszPath,
  172. IN LPCWSTR wszFileName,
  173. IN bool bRecursive,
  174. IN LPCWSTR wszAlternatePath
  175. ) = 0;
  176. // get count of new target specifications
  177. STDMETHOD(GetNewTargetCount)
  178. (
  179. OUT UINT *pcNewTarget
  180. ) = 0;
  181. STDMETHOD(GetNewTarget)
  182. (
  183. IN UINT iNewTarget,
  184. OUT IVssWMFiledesc **ppFiledesc
  185. ) = 0;
  186. // add a directed target specification
  187. STDMETHOD(AddDirectedTarget)
  188. (
  189. IN LPCWSTR wszSourcePath,
  190. IN LPCWSTR wszSourceFilename,
  191. IN LPCWSTR wszSourceRangeList,
  192. IN LPCWSTR wszDestinationPath,
  193. IN LPCWSTR wszDestinationFilename,
  194. IN LPCWSTR wszDestinationRangeList
  195. ) = 0;
  196. // get count of directed target specifications
  197. STDMETHOD(GetDirectedTargetCount)
  198. (
  199. OUT UINT *pcDirectedTarget
  200. ) = 0;
  201. // obtain a particular directed target specification
  202. STDMETHOD(GetDirectedTarget)
  203. (
  204. IN UINT iDirectedTarget,
  205. OUT BSTR *pbstrSourcePath,
  206. OUT BSTR *pbstrSourceFileName,
  207. OUT BSTR *pbstrSourceRangeList,
  208. OUT BSTR *pbstrDestinationPath,
  209. OUT BSTR *pbstrDestinationFilename,
  210. OUT BSTR *pbstrDestinationRangeList
  211. ) = 0;
  212. // set restore metadata associated with the component
  213. STDMETHOD(SetRestoreMetadata)
  214. (
  215. IN LPCWSTR wszRestoreMetadata
  216. ) = 0;
  217. // obtain restore metadata associated with the component
  218. STDMETHOD(GetRestoreMetadata)
  219. (
  220. OUT BSTR *pbstrRestoreMetadata
  221. ) = 0;
  222. // set the restore target
  223. STDMETHOD(SetRestoreTarget)
  224. (
  225. IN VSS_RESTORE_TARGET target
  226. ) = 0;
  227. // obtain the restore target
  228. STDMETHOD(GetRestoreTarget)
  229. (
  230. OUT VSS_RESTORE_TARGET *pTarget
  231. ) = 0;
  232. // set failure message during pre restore event
  233. STDMETHOD(SetPreRestoreFailureMsg)
  234. (
  235. IN LPCWSTR wszPreRestoreFailureMsg
  236. ) = 0;
  237. // obtain failure message during pre restore event
  238. STDMETHOD(GetPreRestoreFailureMsg)
  239. (
  240. OUT BSTR *pbstrPreRestoreFailureMsg
  241. ) = 0;
  242. // set the failure message during the post restore event
  243. STDMETHOD(SetPostRestoreFailureMsg)
  244. (
  245. IN LPCWSTR wszPostRestoreFailureMsg
  246. ) = 0;
  247. // obtain the failure message set during the post restore event
  248. STDMETHOD(GetPostRestoreFailureMsg)
  249. (
  250. OUT BSTR *pbstrPostRestoreFailureMsg
  251. ) = 0;
  252. // set the backup stamp of the backup
  253. STDMETHOD(SetBackupStamp)
  254. (
  255. IN LPCWSTR wszBackupStamp
  256. ) = 0;
  257. // obtain the stamp of the backup
  258. STDMETHOD(GetBackupStamp)
  259. (
  260. OUT BSTR *pbstrBackupStamp
  261. ) = 0;
  262. // obtain the backup stamp that the differential or incremental
  263. // backup is baed on
  264. STDMETHOD(GetPreviousBackupStamp)
  265. (
  266. OUT BSTR *pbstrBackupStamp
  267. ) = 0;
  268. // obtain backup options for the writer
  269. STDMETHOD(GetBackupOptions)
  270. (
  271. OUT BSTR *pbstrBackupOptions
  272. ) = 0;
  273. // obtain the restore options
  274. STDMETHOD(GetRestoreOptions)
  275. (
  276. OUT BSTR *pbstrRestoreOptions
  277. ) = 0;
  278. // obtain count of subcomponents to be restored
  279. STDMETHOD(GetRestoreSubcomponentCount)
  280. (
  281. OUT UINT *pcRestoreSubcomponent
  282. ) = 0;
  283. // obtain a particular subcomponent to be restored
  284. STDMETHOD(GetRestoreSubcomponent)
  285. (
  286. UINT iComponent,
  287. OUT BSTR *pbstrLogicalPath,
  288. OUT BSTR *pbstrComponentName,
  289. OUT bool *pbRepair
  290. ) = 0;
  291. // obtain whether files were successfully restored
  292. STDMETHOD(GetFileRestoreStatus)
  293. (
  294. OUT VSS_FILE_RESTORE_STATUS *pStatus
  295. ) = 0;
  296. };
  297. // backup writer components interface (i.e., all components for an
  298. // individual writer
  299. class IVssWriterComponents
  300. {
  301. public:
  302. // get count of components
  303. STDMETHOD(GetComponentCount)(OUT UINT *pcComponents) = 0;
  304. // get information about the writer
  305. STDMETHOD(GetWriterInfo)
  306. (
  307. OUT VSS_ID *pidInstance,
  308. OUT VSS_ID *pidWriter
  309. ) = 0;
  310. // obtain a specific component
  311. STDMETHOD(GetComponent)
  312. (
  313. IN UINT iComponent,
  314. OUT IVssComponent **ppComponent
  315. ) = 0;
  316. };
  317. // create backup metadata interface
  318. class IVssCreateWriterMetadata
  319. {
  320. public:
  321. // add files to include to metadata document
  322. STDMETHOD(AddIncludeFiles)
  323. (
  324. IN LPCWSTR wszPath,
  325. IN LPCWSTR wszFilespec,
  326. IN bool bRecursive,
  327. IN LPCWSTR wszAlternateLocation
  328. ) = 0;
  329. // add files to exclude to metadata document
  330. STDMETHOD(AddExcludeFiles)
  331. (
  332. IN LPCWSTR wszPath,
  333. IN LPCWSTR wszFilespec,
  334. IN bool bRecursive
  335. ) = 0;
  336. // add component to metadata document
  337. STDMETHOD(AddComponent)
  338. (
  339. IN VSS_COMPONENT_TYPE ct,
  340. IN LPCWSTR wszLogicalPath,
  341. IN LPCWSTR wszComponentName,
  342. IN LPCWSTR wszCaption,
  343. IN const BYTE *pbIcon,
  344. IN UINT cbIcon,
  345. IN bool bRestoreMetadata,
  346. IN bool bNotifyOnBackupComplete,
  347. IN bool bSelectable
  348. ) = 0;
  349. // add physical database files to a database component
  350. STDMETHOD(AddDatabaseFiles)
  351. (
  352. IN LPCWSTR wszLogicalPath,
  353. IN LPCWSTR wszDatabaseName,
  354. IN LPCWSTR wszPath,
  355. IN LPCWSTR wszFilespec
  356. ) = 0;
  357. // add log files to a database component
  358. STDMETHOD(AddDatabaseLogFiles)
  359. (
  360. IN LPCWSTR wszLogicalPath,
  361. IN LPCWSTR wszDatabaseName,
  362. IN LPCWSTR wszPath,
  363. IN LPCWSTR wszFilespec
  364. ) = 0;
  365. // add files to a FILE_GROUP component
  366. STDMETHOD(AddFilesToFileGroup)
  367. (
  368. IN LPCWSTR wszLogicalPath,
  369. IN LPCWSTR wszGroupName,
  370. IN LPCWSTR wszPath,
  371. IN LPCWSTR wszFilespec,
  372. IN bool bRecursive,
  373. IN LPCWSTR wszAlternateLocation
  374. ) = 0;
  375. // create a restore method
  376. STDMETHOD(SetRestoreMethod)
  377. (
  378. IN VSS_RESTOREMETHOD_ENUM method,
  379. IN LPCWSTR wszService,
  380. IN LPCWSTR wszUserProcedure,
  381. IN VSS_WRITERRESTORE_ENUM writerRestore,
  382. IN bool bRebootRequired
  383. ) = 0;
  384. // add alternative location mappings to the restore method
  385. STDMETHOD(AddAlternateLocationMapping)
  386. (
  387. IN LPCWSTR wszSourcePath,
  388. IN LPCWSTR wszSourceFilespec,
  389. IN bool bRecursive,
  390. IN LPCWSTR wszDestination
  391. ) = 0;
  392. // obtain reference to actual XML document
  393. STDMETHOD(GetDocument)(IXMLDOMDocument **pDoc) = 0;
  394. // save document as an XML string
  395. STDMETHOD(SaveAsXML)(BSTR *pbstrXML) = 0;
  396. };
  397. class IVssWriterImpl;
  398. /////////////////////////////////////////////////////////////////////////////
  399. // CVssWriter
  400. class CVssWriter
  401. {
  402. // Constants
  403. public:
  404. // Constructors & Destructors
  405. public:
  406. __declspec(dllexport)
  407. STDMETHODCALLTYPE CVssWriter();
  408. __declspec(dllexport)
  409. virtual STDMETHODCALLTYPE ~CVssWriter();
  410. // Exposed operations
  411. public:
  412. // initialize the writer object
  413. __declspec(dllexport)
  414. HRESULT STDMETHODCALLTYPE Initialize
  415. (
  416. IN VSS_ID WriterID,
  417. IN LPCWSTR wszWriterName,
  418. IN VSS_USAGE_TYPE ut,
  419. IN VSS_SOURCE_TYPE st,
  420. IN VSS_APPLICATION_LEVEL nLevel = VSS_APP_FRONT_END,
  421. IN DWORD dwTimeoutFreeze = 60000, // Maximum milliseconds between Freeze/Thaw
  422. IN VSS_ALTERNATE_WRITER_STATE aws = VSS_AWS_NO_ALTERNATE_WRITER,
  423. IN bool bIOThrottlingOnly = false
  424. );
  425. // cause the writer to subscribe to events.
  426. __declspec(dllexport)
  427. HRESULT STDMETHODCALLTYPE Subscribe
  428. (
  429. IN DWORD dwEventFlags = VSS_SM_BACKUP_EVENTS_FLAG | VSS_SM_RESTORE_EVENTS_FLAG
  430. );
  431. // cause the writer to unsubscribe from events
  432. __declspec(dllexport)
  433. HRESULT STDMETHODCALLTYPE Unsubscribe();
  434. // installs an alternative writer
  435. __declspec(dllexport)
  436. HRESULT STDMETHODCALLTYPE InstallAlternateWriter
  437. (
  438. IN VSS_ID writerId,
  439. IN CLSID persistentWriterClassId
  440. );
  441. // Internal properties - accessible from OnXXX methods
  442. protected:
  443. // get array of volumne names
  444. __declspec(dllexport)
  445. LPCWSTR* STDMETHODCALLTYPE GetCurrentVolumeArray() const;
  446. // get count of volume names in array
  447. __declspec(dllexport)
  448. UINT STDMETHODCALLTYPE GetCurrentVolumeCount() const;
  449. // current snapshot set GUID
  450. __declspec(dllexport)
  451. VSS_ID STDMETHODCALLTYPE GetCurrentSnapshotSetId() const;
  452. // current app level (either 1,2,3)
  453. __declspec(dllexport)
  454. VSS_APPLICATION_LEVEL STDMETHODCALLTYPE GetCurrentLevel() const;
  455. // determine if path is in set of volumes being snapshotted
  456. __declspec(dllexport)
  457. bool STDMETHODCALLTYPE IsPathAffected
  458. (
  459. IN LPCWSTR wszPath
  460. ) const;
  461. // does the backup include bootable state (formerly system state backup)
  462. __declspec(dllexport)
  463. bool STDMETHODCALLTYPE IsBootableSystemStateBackedUp() const;
  464. // is the backup application smart (i.e., selecting components) or
  465. // dump (i.e., just selecting volumes)
  466. __declspec(dllexport)
  467. bool STDMETHODCALLTYPE AreComponentsSelected() const;
  468. __declspec(dllexport)
  469. VSS_BACKUP_TYPE STDMETHODCALLTYPE GetBackupType() const;
  470. __declspec(dllexport)
  471. bool STDMETHODCALLTYPE IsPartialFileSupportEnabled() const;
  472. _declspec(dllexport)
  473. HRESULT STDMETHODCALLTYPE SetWriterFailure(HRESULT hr);
  474. // Ovverides
  475. public:
  476. // callback when request for metadata comes in
  477. __declspec(dllexport)
  478. virtual bool STDMETHODCALLTYPE OnIdentify(IN IVssCreateWriterMetadata *pMetadata);
  479. // callback for prepare backup event
  480. __declspec(dllexport)
  481. virtual bool STDMETHODCALLTYPE OnPrepareBackup(
  482. IN IVssWriterComponents *pComponent
  483. );
  484. // callback for prepare snapsot event
  485. virtual bool STDMETHODCALLTYPE OnPrepareSnapshot() = 0;
  486. // callback for freeze event
  487. virtual bool STDMETHODCALLTYPE OnFreeze() = 0;
  488. // callback for thaw event
  489. virtual bool STDMETHODCALLTYPE OnThaw() = 0;
  490. // callback if current sequence is aborted
  491. virtual bool STDMETHODCALLTYPE OnAbort() = 0;
  492. // callback on backup complete event
  493. __declspec(dllexport)
  494. virtual bool STDMETHODCALLTYPE OnBackupComplete
  495. (
  496. IN IVssWriterComponents *pComponent
  497. );
  498. // callback on pre-restore event
  499. __declspec(dllexport)
  500. virtual bool STDMETHODCALLTYPE OnPreRestore
  501. (
  502. IN IVssWriterComponents *pComponent
  503. );
  504. // callback on post-restore event
  505. __declspec(dllexport)
  506. virtual bool STDMETHODCALLTYPE OnPostRestore
  507. (
  508. IN IVssWriterComponents *pComponent
  509. );
  510. // callback on post snapshot event
  511. __declspec(dllexport)
  512. virtual bool STDMETHODCALLTYPE OnPostSnapshot
  513. (
  514. IN IVssWriterComponents *pComponent
  515. );
  516. // callback on back off I/O volume event
  517. __declspec(dllexport)
  518. virtual bool STDMETHODCALLTYPE OnBackOffIOOnVolume
  519. (
  520. IN VSS_PWSZ wszVolumeName,
  521. IN VSS_ID snapshotId,
  522. IN VSS_ID providerId
  523. );
  524. // callback on Continue I/O on volume event
  525. __declspec(dllexport)
  526. virtual bool STDMETHODCALLTYPE OnContinueIOOnVolume
  527. (
  528. IN VSS_PWSZ wszVolumeName,
  529. IN VSS_ID snapshotId,
  530. IN VSS_ID providerId
  531. );
  532. // callback to specify that the volume snaphost service is shutting down. Used
  533. // by alternative writers to signal when to shutdown.
  534. __declspec(dllexport)
  535. virtual bool STDMETHODCALLTYPE OnVSSShutdown();
  536. // callback to an alternative writer when the application writer subscribes. Used to
  537. // signal the alternative writer to shutdown.
  538. __declspec(dllexport)
  539. virtual bool STDMETHODCALLTYPE OnVSSApplicationStartup();
  540. private:
  541. IVssWriterImpl *m_pWrapper;
  542. };
  543. //
  544. // MessageId: VSS_E_WRITERERROR_INCONSISTENTSNAPSHOT
  545. //
  546. // MessageText:
  547. //
  548. // indicates that the snapshot contains only a subset of the
  549. // volumes needed to correctly backup an application component
  550. //
  551. const HRESULT VSS_E_WRITERERROR_INCONSISTENTSNAPSHOT = (0x800423f0L);
  552. //
  553. // MessageId: VSS_E_WRITERERROR_OUTOFRESOURCES
  554. //
  555. // MessageText:
  556. //
  557. // indi`cates that the writer failed due to an out of memory,
  558. // out of handles, or other resource allocation failure
  559. //
  560. const HRESULT VSS_E_WRITERERROR_OUTOFRESOURCES = (0x800423f1L);
  561. //
  562. // MessageId: VSS_E_WRITERERROR_TIMEOUT
  563. //
  564. // MessageText:
  565. //
  566. // indicates that the writer failed due to a timeout between
  567. // freeze and thaw.
  568. //
  569. const HRESULT VSS_E_WRITERERROR_TIMEOUT = (0x800423f2L);
  570. //
  571. // MessageId: VSS_E_WRITERERROR_RETRYABLE
  572. //
  573. // MessageText:
  574. //
  575. // indicates that the writer failed due to an error
  576. // that might not occur if another snapshot is created
  577. //
  578. const HRESULT VSS_E_WRITERERROR_RETRYABLE = (0x800423f3L);
  579. //
  580. // MessageId: VSS_E_WRITERERROR_NONRETRYABLE
  581. //
  582. // MessageText:
  583. //
  584. // indicates that the writer failed due to an error
  585. // that most likely would occur if another snapshot is created
  586. //
  587. const HRESULT VSS_E_WRITERERROR_NONRETRYABLE = (0x800423f4L);
  588. #endif //__CVSS_WRITER_H_