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.

1219 lines
27 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. vs_cmxml.cxx
  5. Abstract:
  6. Implementation of Backup Components Metadata XML wrapper classes
  7. Brian Berkowitz [brianb] 3/13/2000
  8. TBD:
  9. Add comments.
  10. Revision History:
  11. Name Date Comments
  12. brianb 03/16/2000 Created
  13. brianb 03/22/2000 Added support for PrepareForBackup and BackupComplete
  14. brianb 04/25/2000 Cleaned up Critical section stuff
  15. brianb 05/03/2000 changed for new security model
  16. ssteiner 11/10/2000 143810 Move SimulateSnapshotXxxx() calls to be hosted by VsSvc.
  17. --*/
  18. ////////////////////////////////////////////////////////////////////////
  19. // Standard foo for file name aliasing. This code block must be after
  20. // all includes of VSS header files.
  21. //
  22. #ifdef VSS_FILE_ALIAS
  23. #undef VSS_FILE_ALIAS
  24. #endif
  25. #define VSS_FILE_ALIAS "INCCXMLH"
  26. //
  27. ////////////////////////////////////////////////////////////////////////
  28. const VSS_ID idWriterBootableState = {0xf2436e37,
  29. 0x09f5,
  30. 0x41af,
  31. {0x9b, 0x2a, 0x4c, 0xa2, 0x43, 0x5d, 0xbf, 0xd5}};
  32. const VSS_ID idWriterServiceState = {0xe38c2e3c,
  33. 0xd4fb,
  34. 0x4f4d,
  35. {0x95, 0x50, 0xfc, 0xaf, 0xda, 0x8a, 0xae, 0x9a}};
  36. class IVssWriterComponentsInt :
  37. public IVssWriterComponentsExt
  38. {
  39. public:
  40. // initialize
  41. STDMETHOD(Initialize)(bool fFindToplevel) = 0;
  42. // has document been changed
  43. STDMETHOD(IsChanged)(bool *pbChanged) = 0;
  44. // save document as XML
  45. STDMETHOD(SaveAsXML)(OUT BSTR *pbstrXMLDocument) = 0;
  46. };
  47. // Writer property structure
  48. typedef struct _VSS_WRITER_PROP {
  49. VSS_ID m_InstanceId;
  50. VSS_ID m_ClassId;
  51. VSS_WRITER_STATE m_nState;
  52. VSS_PWSZ m_pwszName;
  53. HRESULT m_hrWriterFailure;
  54. } VSS_WRITER_PROP, *PVSS_WRITER_PROP;
  55. // list of writer data that is gotten from ExposeWriterMetadata and
  56. // SetContent
  57. class CInternalWriterData
  58. {
  59. public:
  60. // constructor
  61. CInternalWriterData()
  62. {
  63. m_pDataNext = NULL;
  64. m_pOwnerToken = NULL;
  65. }
  66. ~CInternalWriterData()
  67. {
  68. delete m_pOwnerToken;
  69. }
  70. // initialize an element
  71. void Initialize
  72. (
  73. IN VSS_ID idInstance,
  74. IN VSS_ID idWriter,
  75. IN BSTR bstrWriterName,
  76. IN BSTR bstrMetadata,
  77. IN TOKEN_OWNER *pOwnerToken
  78. )
  79. {
  80. m_idInstance = idInstance;
  81. m_idWriter = idWriter;
  82. m_bstrWriterName = bstrWriterName;
  83. m_bstrWriterMetadata = bstrMetadata;
  84. m_pOwnerToken = pOwnerToken;
  85. m_bstrWriterComponents.Empty();
  86. }
  87. void SetComponents(IN BSTR bstrComponents)
  88. {
  89. m_bstrWriterComponents = bstrComponents;
  90. }
  91. // instance id of writer
  92. VSS_ID m_idInstance;
  93. // class id of the writer
  94. VSS_ID m_idWriter;
  95. // name of the writer
  96. CComBSTR m_bstrWriterName;
  97. // XML writer metadata from writer
  98. CComBSTR m_bstrWriterMetadata;
  99. // XML writer component data
  100. CComBSTR m_bstrWriterComponents;
  101. // next pointer
  102. CInternalWriterData *m_pDataNext;
  103. // security id for client thread
  104. TOKEN_OWNER *m_pOwnerToken;
  105. };
  106. // class to access a component from the BACKUP_COMPONENTS document
  107. class CVssComponent :
  108. public CVssMetadataHelper,
  109. public IVssComponent
  110. {
  111. friend class CVssWriterComponents;
  112. private:
  113. // constructor (can only be called from CVssWriterComponents)
  114. CVssComponent
  115. (
  116. IXMLDOMNode *pNode,
  117. IXMLDOMDocument *pDoc,
  118. CVssWriterComponents *pWriterComponents) :
  119. CVssMetadataHelper(pNode, pDoc),
  120. m_cRef(0),
  121. m_pWriterComponents(pWriterComponents)
  122. {
  123. }
  124. // 2nd phase constructor
  125. void Initialize(CVssFunctionTracer &ft)
  126. {
  127. InitializeHelper(ft);
  128. }
  129. public:
  130. // obtain logical path of component
  131. STDMETHOD(GetLogicalPath)(OUT BSTR *pbstrPath);
  132. // obtain component type(VSS_CT_DATABASE or VSS_CT_FILEGROUP)
  133. STDMETHOD(GetComponentType)(VSS_COMPONENT_TYPE *pct);
  134. // get component name
  135. STDMETHOD(GetComponentName)(OUT BSTR *pbstrName);
  136. // determine whether the component was successfully backed up.
  137. STDMETHOD(GetBackupSucceeded)(OUT bool *pbSucceeded);
  138. // get altermative location mapping count
  139. STDMETHOD(GetAlternateLocationMappingCount)(OUT UINT *pcMappings);
  140. // get a paraticular alternative location mapping
  141. STDMETHOD(GetAlternateLocationMapping)
  142. (
  143. IN UINT iMapping,
  144. OUT IVssWMFiledesc **pFiledesc
  145. );
  146. // set the backup metadata for a component
  147. STDMETHOD(SetBackupMetadata)(IN LPCWSTR wszData);
  148. // get the backup metadata for a component
  149. STDMETHOD(GetBackupMetadata)(OUT BSTR *pbstrData);
  150. // indicate that only ranges in the file are to be backed up
  151. STDMETHOD(AddPartialFile)
  152. (
  153. IN LPCWSTR wszPath,
  154. IN LPCWSTR wszFilename,
  155. IN LPCWSTR wszRanges,
  156. IN LPCWSTR wszMetadata
  157. );
  158. // get count of partial file declarations
  159. STDMETHOD(GetPartialFileCount)
  160. (
  161. OUT UINT *pcPartialFiles
  162. );
  163. // get a partial file declaration
  164. STDMETHOD(GetPartialFile)
  165. (
  166. IN UINT iPartialFile,
  167. OUT BSTR *pbstrPath,
  168. OUT BSTR *pbstrFilename,
  169. OUT BSTR *pbstrRange,
  170. OUT BSTR *pbstrMetadata
  171. );
  172. // determine if the component is selected to be restored
  173. STDMETHOD(IsSelectedForRestore)
  174. (
  175. OUT bool *pbSelectedForRestore
  176. );
  177. STDMETHOD(GetAdditionalRestores)
  178. (
  179. OUT bool *pbAdditionalRestores
  180. );
  181. // get count of new target specifications
  182. STDMETHOD(GetNewTargetCount)
  183. (
  184. OUT UINT *pcNewTarget
  185. );
  186. STDMETHOD(GetNewTarget)
  187. (
  188. IN UINT iNewTarget,
  189. OUT IVssWMFiledesc **ppFiledesc
  190. );
  191. // add a directed target specification
  192. STDMETHOD(AddDirectedTarget)
  193. (
  194. IN LPCWSTR wszSourcePath,
  195. IN LPCWSTR wszSourceFilename,
  196. IN LPCWSTR wszSourceRangeList,
  197. IN LPCWSTR wszDestinationPath,
  198. IN LPCWSTR wszDestinationFilename,
  199. IN LPCWSTR wszDestinationRangeList
  200. );
  201. // get count of directed target specifications
  202. STDMETHOD(GetDirectedTargetCount)
  203. (
  204. OUT UINT *pcDirectedTarget
  205. );
  206. // obtain a particular directed target specification
  207. STDMETHOD(GetDirectedTarget)
  208. (
  209. IN UINT iDirectedTarget,
  210. OUT BSTR *pbstrSourcePath,
  211. OUT BSTR *pbstrSourceFileName,
  212. OUT BSTR *pbstrSourceRangeList,
  213. OUT BSTR *pbstrDestinationPath,
  214. OUT BSTR *pbstrDestinationFilename,
  215. OUT BSTR *pbstrDestinationRangeList
  216. );
  217. // set restore metadata associated with the component
  218. STDMETHOD(SetRestoreMetadata)
  219. (
  220. IN LPCWSTR wszRestoreMetadata
  221. );
  222. // obtain restore metadata associated with the component
  223. STDMETHOD(GetRestoreMetadata)
  224. (
  225. OUT BSTR *pbstrRestoreMetadata
  226. );
  227. // set the restore target
  228. STDMETHOD(SetRestoreTarget)
  229. (
  230. IN VSS_RESTORE_TARGET target
  231. );
  232. // obtain the restore target
  233. STDMETHOD(GetRestoreTarget)
  234. (
  235. OUT VSS_RESTORE_TARGET *pTarget
  236. );
  237. // set failure message during pre restore event
  238. STDMETHOD(SetPreRestoreFailureMsg)
  239. (
  240. IN LPCWSTR wszPreRestoreFailureMsg
  241. );
  242. // obtain failure message during pre restore event
  243. STDMETHOD(GetPreRestoreFailureMsg)
  244. (
  245. OUT BSTR *pbstrPreRestoreFailureMsg
  246. );
  247. // set the failure message during the post restore event
  248. STDMETHOD(SetPostRestoreFailureMsg)
  249. (
  250. IN LPCWSTR wszPostRestoreFailureMsg
  251. );
  252. // obtain the failure message set during the post restore event
  253. STDMETHOD(GetPostRestoreFailureMsg)
  254. (
  255. OUT BSTR *pbstrPostRestoreFailureMsg
  256. );
  257. // set the backup stamp of the backup
  258. STDMETHOD(SetBackupStamp)
  259. (
  260. IN LPCWSTR wszBackupStamp
  261. );
  262. // obtain the stamp of the backup
  263. STDMETHOD(GetBackupStamp)
  264. (
  265. OUT BSTR *pbstrBackupStamp
  266. );
  267. // obtain the backup stamp that the differential or incremental
  268. // backup is baed on
  269. STDMETHOD(GetPreviousBackupStamp)
  270. (
  271. OUT BSTR *pbstrBackupStamp
  272. );
  273. // obtain backup options for the writer
  274. STDMETHOD(GetBackupOptions)
  275. (
  276. OUT BSTR *pbstrBackupOptions
  277. );
  278. // obtain the restore options
  279. STDMETHOD(GetRestoreOptions)
  280. (
  281. OUT BSTR *pbstrRestoreOptions
  282. );
  283. // obtain count of subcomponents to be restored
  284. STDMETHOD(GetRestoreSubcomponentCount)
  285. (
  286. OUT UINT *pcRestoreSubcomponent
  287. );
  288. // obtain a particular subcomponent to be restored
  289. STDMETHOD(GetRestoreSubcomponent)
  290. (
  291. UINT iComponent,
  292. OUT BSTR *pbstrLogicalPath,
  293. OUT BSTR *pbstrComponentName,
  294. OUT bool *pbRepair
  295. );
  296. // obtain whether files were successfully restored
  297. STDMETHOD(GetFileRestoreStatus)
  298. (
  299. OUT VSS_FILE_RESTORE_STATUS *pStatus
  300. );
  301. // add differenced files by last modify time
  302. STDMETHOD(AddDifferencedFilesByLastModifyTime)
  303. (
  304. IN LPCWSTR wszPath,
  305. IN LPCWSTR wszFilespec,
  306. IN BOOL bRecursive,
  307. IN FILETIME ftLastModifyTime
  308. );
  309. STDMETHOD(AddDifferencedFilesByLastModifyLSN)
  310. (
  311. IN LPCWSTR wszPath,
  312. IN LPCWSTR wszFilespec,
  313. IN BOOL bRecursive,
  314. IN BSTR bstrLsnString
  315. );
  316. STDMETHOD(GetDifferencedFilesCount)
  317. (
  318. OUT UINT *pcDifferencedFiles
  319. );
  320. STDMETHOD(GetDifferencedFile)
  321. (
  322. IN UINT iDifferencedFile,
  323. OUT BSTR *pbstrPath,
  324. OUT BSTR *pbstrFilespec,
  325. OUT BOOL *pbRecursive,
  326. OUT BSTR *pbstrLsnString,
  327. OUT FILETIME *pftLastModifyTime
  328. );
  329. // IUnknown methods
  330. STDMETHOD(QueryInterface)(REFIID, void **);
  331. STDMETHOD_ (ULONG, AddRef)();
  332. STDMETHOD_ (ULONG, Release)();
  333. private:
  334. // reference count for AddRef, Release
  335. LONG m_cRef;
  336. // pointer to parent writer components document if changes are allowed
  337. CVssWriterComponents *m_pWriterComponents;
  338. };
  339. // components associated with a specific writer
  340. class CVssWriterComponents :
  341. public CVssMetadataHelper,
  342. public IVssWriterComponentsInt
  343. {
  344. public:
  345. // constructor (can only be called from CVssBackupComponents)
  346. CVssWriterComponents
  347. (
  348. IXMLDOMNode *pNode,
  349. IXMLDOMDocument *pDoc,
  350. bool bWriteable
  351. ) :
  352. CVssMetadataHelper(pNode, pDoc),
  353. m_cRef(0),
  354. m_bWriteable(bWriteable),
  355. m_bChanged(false)
  356. {
  357. }
  358. // 2nd phase construction
  359. void Initialize(CVssFunctionTracer &ft)
  360. {
  361. InitializeHelper(ft);
  362. }
  363. // get count of components
  364. STDMETHOD(GetComponentCount)(OUT UINT *pcComponents);
  365. // get information about the writer
  366. STDMETHOD(GetWriterInfo)
  367. (
  368. OUT VSS_ID *pidInstance,
  369. OUT VSS_ID *pidWriter
  370. );
  371. // obtain a specific component
  372. STDMETHOD(GetComponent)
  373. (
  374. IN UINT iComponent,
  375. OUT IVssComponent **ppComponent
  376. );
  377. STDMETHOD(IsChanged)
  378. (
  379. OUT bool *pbChanged
  380. );
  381. STDMETHOD(SaveAsXML)
  382. (
  383. OUT BSTR *pbstrXMLDocument
  384. );
  385. // initialize writer components document to point at writer components
  386. // element
  387. STDMETHOD(Initialize)(bool fFindToplevel);
  388. STDMETHODIMP QueryInterface(REFIID, void **)
  389. {
  390. return E_NOTIMPL;
  391. }
  392. STDMETHOD_ (ULONG, AddRef)();
  393. STDMETHOD_ (ULONG, Release)();
  394. // indicate that document is changed
  395. void SetChanged()
  396. {
  397. BS_ASSERT(m_bWriteable);
  398. m_bChanged = TRUE;
  399. }
  400. private:
  401. // reference count for AddRef, Release
  402. LONG m_cRef;
  403. // can components be changed
  404. bool m_bWriteable;
  405. // is document changed
  406. bool m_bChanged;
  407. };
  408. // components associated with a specific writer
  409. class CVssNULLWriterComponents :
  410. public IVssWriterComponentsInt
  411. {
  412. public:
  413. CVssNULLWriterComponents
  414. (
  415. VSS_ID idInstance,
  416. VSS_ID idWriter
  417. )
  418. {
  419. m_idInstance = idInstance;
  420. m_idWriter = idWriter;
  421. m_cRef = 0;
  422. }
  423. // initialize
  424. STDMETHOD(Initialize)(bool fFindToplevel)
  425. {
  426. UNREFERENCED_PARAMETER(fFindToplevel);
  427. return S_OK;
  428. }
  429. // get count of components
  430. STDMETHOD(GetComponentCount)(OUT UINT *pcComponents);
  431. // get information about the writer
  432. STDMETHOD(GetWriterInfo)
  433. (
  434. OUT VSS_ID *pidInstance,
  435. OUT VSS_ID *pidWriter
  436. );
  437. // obtain a specific component
  438. STDMETHOD(GetComponent)
  439. (
  440. IN UINT iComponent,
  441. OUT IVssComponent **ppComponent
  442. );
  443. STDMETHOD(IsChanged)
  444. (
  445. OUT bool *pbChanged
  446. );
  447. STDMETHOD(SaveAsXML)
  448. (
  449. OUT BSTR *pbstrXMLDocument
  450. );
  451. STDMETHODIMP QueryInterface(REFIID, void **)
  452. {
  453. return E_NOTIMPL;
  454. }
  455. STDMETHOD_ (ULONG, AddRef)();
  456. STDMETHOD_ (ULONG, Release)();
  457. private:
  458. // id of writer class
  459. VSS_ID m_idWriter;
  460. // id of writer instance
  461. VSS_ID m_idInstance;
  462. // reference count for AddRef, Release
  463. LONG m_cRef;
  464. };
  465. // state of CVssBackupComponents object
  466. enum VSS_BACKUPCALL_STATE
  467. {
  468. x_StateUndefined = 0,
  469. x_StateInitialized,
  470. x_StateSnapshotSetCreated,
  471. x_StatePrepareForBackup,
  472. x_StatePrepareForBackupSucceeded,
  473. x_StatePrepareForBackupFailed,
  474. x_StateDoSnapshot,
  475. x_StateDoSnapshotSucceeded,
  476. x_StateDoSnapshotFailed,
  477. x_StateDoSnapshotFailedWithoutSendingAbort,
  478. x_StateBackupComplete,
  479. x_StateBackupCompleteSucceeded,
  480. x_StateBackupCompleteFailed,
  481. x_StateAborting,
  482. x_StateAborted,
  483. x_StateRestore,
  484. x_StateRestoreSucceeded,
  485. x_StateRestoreFailed,
  486. x_StateGatheringWriterMetadata,
  487. x_StateGatheringWriterStatus
  488. };
  489. // class used by the backup application to interact with the writer
  490. class ATL_NO_VTABLE CVssBackupComponents :
  491. public CComObjectRoot,
  492. public IVssBackupComponents,
  493. public CVssMetadataHelper,
  494. public IDispatchImpl<IVssWriterCallback, &IID_IVssWriterCallback, &LIBID_VssEventLib, 1, 0>
  495. {
  496. public:
  497. friend class CVssAsyncBackup;
  498. friend class CVssAsyncCover;
  499. BEGIN_COM_MAP(CVssBackupComponents)
  500. COM_INTERFACE_ENTRY(IDispatch)
  501. COM_INTERFACE_ENTRY(IVssWriterCallback)
  502. END_COM_MAP()
  503. // constructor
  504. CVssBackupComponents();
  505. // destructor
  506. ~CVssBackupComponents();
  507. // get count of writer components
  508. STDMETHOD(GetWriterComponentsCount)(OUT UINT *pcComponents);
  509. // obtain a specific writer component
  510. STDMETHOD(GetWriterComponents)
  511. (
  512. IN UINT iWriter,
  513. OUT IVssWriterComponentsExt **ppWriter
  514. );
  515. // initialize for backup
  516. STDMETHOD(InitializeForBackup)(IN BSTR bstrXML = NULL);
  517. // set backup state for backup components document
  518. STDMETHOD(SetBackupState)
  519. (
  520. IN bool bSelectComponents,
  521. IN bool bBackupBootableState,
  522. IN VSS_BACKUP_TYPE backupType,
  523. IN bool bPartialFileSupport
  524. );
  525. STDMETHOD(SetRestoreState)
  526. (
  527. VSS_RESTORE_TYPE restoreType
  528. ) { UNREFERENCED_PARAMETER(restoreType); return E_NOTIMPL; }
  529. // initialize for restore
  530. STDMETHOD(InitializeForRestore)
  531. (
  532. IN BSTR bstrXML
  533. );
  534. // gather writer metadata
  535. STDMETHOD(GatherWriterMetadata)
  536. (
  537. OUT IVssAsync **ppAsync
  538. );
  539. // get count of writers
  540. STDMETHOD(GetWriterMetadataCount)
  541. (
  542. OUT UINT *pcWriters
  543. );
  544. // get writer metadata for a specific writer
  545. STDMETHOD(GetWriterMetadata)
  546. (
  547. IN UINT iWriter,
  548. OUT VSS_ID *pidInstance,
  549. OUT IVssExamineWriterMetadata **ppMetadata
  550. );
  551. // free XML data gathered from writers
  552. STDMETHOD(FreeWriterMetadata)();
  553. // Called to set the context for subsequent snapshot-related operations
  554. STDMETHOD(SetContext)
  555. (
  556. IN LONG lContext
  557. );
  558. // start a snapshot set
  559. STDMETHOD(StartSnapshotSet)
  560. (
  561. OUT VSS_ID *pSnapshotSetId
  562. );
  563. // add a volume to a snapshot set
  564. STDMETHOD(AddToSnapshotSet)
  565. (
  566. IN VSS_PWSZ pwszVolumeName,
  567. IN VSS_ID ProviderId,
  568. OUT VSS_ID *pSnapshotId
  569. );
  570. // add a component to the BACKUP_COMPONENTS document
  571. STDMETHOD(AddComponent)
  572. (
  573. IN VSS_ID instanceId,
  574. IN VSS_ID writerId,
  575. IN VSS_COMPONENT_TYPE ct,
  576. IN LPCWSTR wszLogicalPath,
  577. IN LPCWSTR wszComponentName
  578. );
  579. // dispatch PrepareForBackup event to writers
  580. STDMETHOD(PrepareForBackup)
  581. (
  582. OUT IVssAsync **ppAsync
  583. );
  584. // create the snapshot set
  585. STDMETHOD(DoSnapshotSet)
  586. (
  587. OUT IVssAsync** ppAsync
  588. );
  589. // abort the backup
  590. STDMETHOD(AbortBackup)();
  591. // dispatch the Identify event so writers can expose their metadata
  592. STDMETHOD(GatherWriterStatus)
  593. (
  594. OUT IVssAsync **ppAsync
  595. );
  596. // get count of writers with status
  597. STDMETHOD(GetWriterStatusCount)
  598. (
  599. OUT UINT *pcWriters
  600. );
  601. // obtain status information about writers
  602. STDMETHOD(GetWriterStatus)
  603. (
  604. IN UINT iWriter,
  605. OUT VSS_ID *pidInstance,
  606. OUT VSS_ID *pidWriter,
  607. OUT BSTR *pbstrWriterName,
  608. OUT VSS_WRITER_STATE *pStatus,
  609. OUT HRESULT *phrWriterFailure
  610. );
  611. // free data gathered using GetWriterStatus
  612. STDMETHOD(FreeWriterStatus)();
  613. // indicate whether backup succeeded on a component
  614. STDMETHOD(SetBackupSucceeded)
  615. (
  616. IN VSS_ID instanceId,
  617. IN VSS_ID writerId,
  618. IN VSS_COMPONENT_TYPE ct,
  619. IN LPCWSTR wszLogicalPath,
  620. IN LPCWSTR wszComponentName,
  621. IN bool bSucceded
  622. );
  623. // set backup options for the writer
  624. STDMETHOD(SetBackupOptions)
  625. (
  626. IN VSS_ID writerId,
  627. IN VSS_COMPONENT_TYPE ct,
  628. IN LPCWSTR wszLogicalPath,
  629. IN LPCWSTR wszComponentName,
  630. IN LPCWSTR wszBackupOptions
  631. );
  632. // indicate that a given component is selected to be restored
  633. STDMETHOD(SetSelectedForRestore)
  634. (
  635. IN VSS_ID writerId,
  636. IN VSS_COMPONENT_TYPE ct,
  637. IN LPCWSTR wszLogicalPath,
  638. IN LPCWSTR wszComponentName,
  639. IN bool bSelectedForRestore
  640. );
  641. // set restore options for the writer
  642. STDMETHOD(SetRestoreOptions)
  643. (
  644. IN VSS_ID writerId,
  645. IN VSS_COMPONENT_TYPE ct,
  646. IN LPCWSTR wszLogicalPath,
  647. IN LPCWSTR wszComponentName,
  648. IN LPCWSTR wszRestoreOptions
  649. );
  650. // indicate that additional restores will follow
  651. STDMETHOD(SetAdditionalRestores)
  652. (
  653. IN VSS_ID writerId,
  654. IN VSS_COMPONENT_TYPE ct,
  655. IN LPCWSTR wszLogicalPath,
  656. IN LPCWSTR wszComponentName,
  657. IN bool bAdditionalRestores
  658. );
  659. // requestor indicates whether files were successfully restored
  660. STDMETHOD(SetFileRestoreStatus)
  661. (
  662. IN VSS_ID writerId,
  663. IN VSS_COMPONENT_TYPE ct,
  664. IN LPCWSTR wszLogicalPath,
  665. IN LPCWSTR wszComponentName,
  666. IN VSS_FILE_RESTORE_STATUS status
  667. );
  668. // add a new location target for a file to be restored
  669. STDMETHOD(AddNewTarget)
  670. (
  671. IN VSS_ID writerId,
  672. IN VSS_COMPONENT_TYPE ct,
  673. IN LPCWSTR wszLogicalPath,
  674. IN LPCWSTR wszComponentName,
  675. IN LPCWSTR wszPath,
  676. IN LPCWSTR wszFileName,
  677. IN bool bRecursive,
  678. IN LPCWSTR wszAlternatePath
  679. ) ;
  680. STDMETHOD(SetRangesFilePath)
  681. (
  682. IN VSS_ID writerId,
  683. IN VSS_COMPONENT_TYPE ct,
  684. IN LPCWSTR wszLogicalPath,
  685. IN LPCWSTR wszComponentName,
  686. IN UINT iPartialFile,
  687. IN LPCWSTR wszRangesFile
  688. );
  689. // set the backup stamp that the differential or incremental
  690. // backup is based on
  691. STDMETHOD(SetPreviousBackupStamp)
  692. (
  693. IN VSS_ID writerId,
  694. IN VSS_COMPONENT_TYPE ct,
  695. IN LPCWSTR wszLogicalPath,
  696. IN LPCWSTR wszComponentName,
  697. IN LPCWSTR wszPreviousBackupStamp
  698. );
  699. // delete a set of snapshots
  700. STDMETHOD(DeleteSnapshots)
  701. (
  702. IN VSS_ID SourceObjectId,
  703. IN VSS_OBJECT_TYPE eSourceObjectType,
  704. IN BOOL bForceDelete,
  705. IN LONG* plDeletedSnapshots,
  706. IN VSS_ID* pNondeletedSnapshotID
  707. );
  708. // Break the snapshot set
  709. STDMETHOD(BreakSnapshotSet)
  710. (
  711. IN VSS_ID SnapshotSetId
  712. );
  713. STDMETHOD(ImportSnapshots)
  714. (
  715. OUT IVssAsync** ppAsync
  716. );
  717. // Get snapshot properties
  718. STDMETHOD(GetSnapshotProperties)
  719. (
  720. IN VSS_ID SnapshotId,
  721. OUT VSS_SNAPSHOT_PROP *pProp
  722. );
  723. // do a generic query using the coordinator
  724. STDMETHOD(Query)
  725. (
  726. IN VSS_ID QueriedObjectId,
  727. IN VSS_OBJECT_TYPE eQueriedObjectType,
  728. IN VSS_OBJECT_TYPE eReturnedObjectsType,
  729. IN IVssEnumObject **ppEnum
  730. );
  731. // save BACKUP_COMPONENTS document as XML string
  732. STDMETHOD(SaveAsXML)(BSTR *pbstrXML);
  733. // signal BackupComplete event to the writers
  734. STDMETHOD(BackupComplete)(OUT IVssAsync **ppAsync);
  735. // add an alternate mapping on restore
  736. STDMETHOD(AddAlternativeLocationMapping)
  737. (
  738. IN VSS_ID writerId,
  739. IN VSS_COMPONENT_TYPE componentType,
  740. IN LPCWSTR wszLogicalPath,
  741. IN LPCWSTR wszComponentName,
  742. IN LPCWSTR wszPath,
  743. IN LPCWSTR wszFilespec,
  744. IN bool bRecursive,
  745. IN LPCWSTR wszDestination
  746. );
  747. // add a subcomponent to be restored
  748. STDMETHOD(AddRestoreSubcomponent)
  749. (
  750. IN VSS_ID writerId,
  751. IN VSS_COMPONENT_TYPE componentType,
  752. IN LPCWSTR wszLogicalPath,
  753. IN LPCWSTR wszComponentName,
  754. IN LPCWSTR wszSubLogicalPath,
  755. IN LPCWSTR wszSubComponentName,
  756. IN bool bRepair
  757. );
  758. // signal PreRestore event to the writers
  759. STDMETHOD(PreRestore)(OUT IVssAsync **ppAsync);
  760. // signal PostRestore event to the writers
  761. STDMETHOD(PostRestore)(OUT IVssAsync **ppAsync);
  762. // IWriterCallback methods
  763. // called by writer to expose its WRITER_METADATA XML document
  764. STDMETHOD(ExposeWriterMetadata)
  765. (
  766. IN BSTR WriterInstanceId,
  767. IN BSTR WriterClassId,
  768. IN BSTR bstrWriterName,
  769. IN BSTR strWriterXMLMetadata
  770. );
  771. // called by the writer to obtain the WRITER_COMPONENTS document for it
  772. STDMETHOD(GetContent)
  773. (
  774. IN BSTR WriterInstanceId,
  775. OUT BSTR* pbstrXMLDOMDocContent
  776. );
  777. // called by the writer to update the WRITER_COMPONENTS document for it
  778. STDMETHOD(SetContent)
  779. (
  780. IN BSTR WriterInstanceId,
  781. IN BSTR bstrXMLDOMDocContent
  782. );
  783. // called by the writer to get information about the backup
  784. STDMETHOD(GetBackupState)
  785. (
  786. OUT BOOL *pbBootableSystemStateBackedUp,
  787. OUT BOOL *pbAreComponentsSelected,
  788. OUT VSS_BACKUP_TYPE *pBackupType,
  789. OUT BOOL *pbPartialFileSupport,
  790. OUT LONG *plContext
  791. );
  792. STDMETHOD(GetRestoreState)
  793. (
  794. OUT VSS_RESTORE_TYPE *pRestoreType
  795. ) { UNREFERENCED_PARAMETER(pRestoreType); return E_NOTIMPL; }
  796. // called by the writer to indicate its status
  797. STDMETHOD(ExposeCurrentState)
  798. (
  799. IN BSTR WriterInstanceId,
  800. IN VSS_WRITER_STATE nCurrentState,
  801. IN HRESULT hrWriterFailure
  802. );
  803. // Called by the requestor to check if a certain volume is supported.
  804. STDMETHOD(IsVolumeSupported)
  805. (
  806. IN VSS_ID ProviderId,
  807. IN VSS_PWSZ pwszVolumeName,
  808. IN BOOL * pbSupportedByThisProvider
  809. );
  810. // called to disable writer classes
  811. STDMETHOD(DisableWriterClasses)
  812. (
  813. IN const VSS_ID *rgWriterClassId,
  814. IN UINT cClassId
  815. );
  816. // called to enable specific writer classes. Note that once specific
  817. // writer classes are enabled, only enabled classes are called.
  818. STDMETHOD(EnableWriterClasses)
  819. (
  820. IN const VSS_ID *rgWriterClassId,
  821. IN UINT cClassId
  822. );
  823. // called to disable an event call to a writer instance
  824. STDMETHOD(DisableWriterInstances)
  825. (
  826. IN const VSS_ID *rgWriterInstanceId,
  827. IN UINT cInstanceId
  828. );
  829. // called to expose a snapshot
  830. STDMETHOD(ExposeSnapshot)
  831. (
  832. IN VSS_ID SnapshotId,
  833. IN VSS_PWSZ wszPathFromRoot,
  834. IN LONG lAttributes,
  835. IN VSS_PWSZ wszExpose,
  836. OUT VSS_PWSZ *pwszExposed
  837. );
  838. STDMETHOD(RevertToSnapshot)
  839. (
  840. IN VSS_ID SnapshotId,
  841. IN BOOL bForceDismount
  842. );
  843. STDMETHOD(QueryRevertStatus)
  844. (
  845. IN VSS_PWSZ pwszVolume,
  846. OUT IVssAsync **pppAsync
  847. );
  848. private:
  849. // free XML component data gathered from writers
  850. void FreeWriterComponents();
  851. // validatate that the object has been initialized
  852. void ValidateInitialized(CVssFunctionTracer &ft);
  853. // basic initialization
  854. void BasicInit(IN CVssFunctionTracer &ft);
  855. // internal PrepareForBackup call
  856. HRESULT InternalPrepareForBackup();
  857. // internal BackupComplete call
  858. HRESULT InternalBackupComplete();
  859. // internal Restore call
  860. HRESULT InternalPostRestore();
  861. // internal GatherWriterMetadata call
  862. HRESULT InternalGatherWriterMetadata();
  863. // internal GatherWriterStatus call
  864. HRESULT InternalGatherWriterStatus();
  865. // routine to complete gather writer metadata
  866. HRESULT PostGatherWriterMetadata
  867. (
  868. UINT timestamp,
  869. VSS_BACKUPCALL_STATE state
  870. );
  871. // routine to complete gather writer status
  872. void PostGatherWriterStatus
  873. (
  874. UINT timestamp,
  875. VSS_BACKUPCALL_STATE state
  876. );
  877. // routine called to complete prepare for backup
  878. void PostPrepareForBackup(UINT timestamp);
  879. // routine called to complete backup complete
  880. void PostBackupComplete(UINT timestamp);
  881. // routine called to complete post restore
  882. void PostPostRestore(UINT timestamp);
  883. // setup IVssCoordinator interface
  884. void SetupCoordinator(IN CVssFunctionTracer &ft);
  885. // position on a WRITER_COMPONENTS element
  886. CXMLNode PositionOnWriterComponents
  887. (
  888. IN CVssFunctionTracer &ft,
  889. IN VSS_ID *pinstanceId,
  890. IN VSS_ID writerId,
  891. IN bool bCreateIfNotThere,
  892. OUT bool &bCreated
  893. ) throw(HRESULT);
  894. // position on/create a specific component,
  895. CXMLNode FindComponent
  896. (
  897. IN CVssFunctionTracer &ft,
  898. IN VSS_ID *pinstanceId,
  899. IN VSS_ID writerId,
  900. IN LPCWSTR wszComponentType,
  901. IN LPCWSTR wszLogicalPath,
  902. IN LPCWSTR wszComponentName,
  903. IN bool bCreate
  904. );
  905. // rebuild component data after PrepareForBackup
  906. void RebuildComponentData(IN CVssFunctionTracer &ft);
  907. // get an IVssWriterCallback interface. Implements GetComponent
  908. void GetCallbackInterface(CVssFunctionTracer &ft, IDispatch **ppDispatch);
  909. // setup writers interface
  910. void SetupWriter(CVssFunctionTracer &ft, IVssWriter **ppWriter);
  911. // add writer data to queue
  912. HRESULT AddWriterData
  913. (
  914. BSTR WriterInstanceId,
  915. BSTR WriterClassId,
  916. BSTR WriterName,
  917. BSTR bstrWriterXMLDocument,
  918. bool bReinitializing
  919. );
  920. // find writer data with a particular instance id
  921. CInternalWriterData *FindWriterData
  922. (
  923. VSS_ID idInstance,
  924. UINT *piWriter = NULL
  925. );
  926. // find writer data and validate the sid
  927. void FindAndValidateWriterData
  928. (
  929. IN VSS_ID idInstance,
  930. OUT UINT *piWriter
  931. );
  932. // free all data about all writers
  933. void FreeAllWriters();
  934. // variable to protect m_state variable and serialize
  935. // access to state changing functions in class
  936. CVssSafeCriticalSection m_csState;
  937. // current state we are in in a callback situation
  938. // protected by m_csState
  939. VSS_BACKUPCALL_STATE m_state;
  940. // snapshot id
  941. CComBSTR m_bstrSnapshotSetId;
  942. // connection to IVssCoordinator class
  943. CComPtr<IVssCoordinator> m_pCoordinator;
  944. // synchronization protecting m_pMetadataFirt and m_cWriters
  945. CVssSafeCriticalSection m_csWriters;
  946. // count of writers,
  947. // protected by m_csWriters
  948. UINT m_cWriters;
  949. // writer data,
  950. // protected by m_csWriters
  951. CInternalWriterData *m_pDataFirst;
  952. CComPtr<IVssWriterCallback> m_pCallback;
  953. // writer properties in GatherWriterStatus, GetWriterStatus
  954. VSS_WRITER_PROP *m_rgWriterProp;
  955. // is this a restore
  956. bool m_bRestore;
  957. // has this structure been initialized
  958. bool m_bInitialized;
  959. // has gather writer metdata completed
  960. bool m_bGatherWriterMetadataComplete;
  961. // has gather writer status completed
  962. bool m_bGatherWriterStatusComplete;
  963. // current call to gather writer status
  964. UINT m_timestampOperation;
  965. // has SetBackupState been called
  966. bool m_bSetBackupStateCalled;
  967. // root node of document
  968. CComPtr<IXMLDOMNode> m_pNodeRoot;
  969. };
  970. class IVssSnapshotSetDescription : public IUnknown
  971. {
  972. };
  973. __declspec(dllexport)
  974. HRESULT STDAPICALLTYPE CreateVssSnapshotSetDescription
  975. (
  976. IN VSS_ID idSnapshotSet,
  977. IN LONG lContext,
  978. OUT IVssSnapshotSetDescription **ppSnapshotSet
  979. );
  980. __declspec(dllexport)
  981. HRESULT STDAPICALLTYPE LoadVssSnapshotSetDescription
  982. (
  983. IN LPCWSTR wszXML,
  984. OUT IVssSnapshotSetDescription **ppSnapshotSet
  985. );