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.

2225 lines
53 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. #include "vs_sec.hxx"
  19. #include "vs_reg.hxx"
  20. ////////////////////////////////////////////////////////////////////////
  21. // Standard foo for file name aliasing. This code block must be after
  22. // all includes of VSS header files.
  23. //
  24. #ifdef VSS_FILE_ALIAS
  25. #undef VSS_FILE_ALIAS
  26. #endif
  27. #define VSS_FILE_ALIAS "INCCXMLH"
  28. //
  29. ////////////////////////////////////////////////////////////////////////
  30. const VSS_ID x_idWriterRegistry =
  31. {
  32. 0xAFBAB4A2,
  33. 0x367D,
  34. 0x4D15,
  35. {0xA5, 0x86, 0x71, 0xDB, 0xB1, 0x8F, 0x84, 0x85}
  36. };
  37. const VSS_ID x_idWriterEventLog =
  38. {
  39. 0xeee8c692,
  40. 0x67ed,
  41. 0x4250,
  42. {0x8d, 0x86, 0x39, 0x6, 0x3, 0x7, 0xd, 0x00}
  43. };
  44. const VSS_ID x_idWriterComREGDB =
  45. {
  46. 0x542da469,
  47. 0xd3e1,
  48. 0x473c,
  49. {0x9f, 0x4f, 0x78, 0x47, 0xf0, 0x1f, 0xc6, 0x4f}
  50. };
  51. // guid used to identify the snapshot service itself when recording
  52. // the snapshot set description XML stuff.
  53. const VSS_ID idVolumeSnapshotService =
  54. {
  55. 0xe68b51c0,
  56. 0xa080,
  57. 0x4078,
  58. {0xa2, 0x79, 0x77, 0xfd, 0x4b, 0x6a, 0x41, 0xf7}
  59. };
  60. class IVssWriterComponentsInt :
  61. public IVssWriterComponentsExt
  62. {
  63. public:
  64. // initialize
  65. STDMETHOD(Initialize)(bool fFindToplevel) = 0;
  66. // has document been changed
  67. STDMETHOD(IsChanged)(bool *pbChanged) = 0;
  68. // save document as XML
  69. STDMETHOD(SaveAsXML)(OUT BSTR *pbstrXMLDocument) = 0;
  70. };
  71. // Writer property structure
  72. typedef struct _VSS_WRITER_PROP {
  73. VSS_ID m_InstanceId;
  74. VSS_ID m_ClassId;
  75. VSS_WRITER_STATE m_nState;
  76. VSS_PWSZ m_pwszName;
  77. HRESULT m_hrWriterFailure;
  78. bool m_bResponseReceived;
  79. } VSS_WRITER_PROP, *PVSS_WRITER_PROP;
  80. // list of writer data that is gotten from ExposeWriterMetadata and
  81. // SetContent
  82. class CInternalWriterData
  83. {
  84. public:
  85. // constructor
  86. CInternalWriterData()
  87. {
  88. m_pDataNext = NULL;
  89. m_pOwnerToken = NULL;
  90. }
  91. ~CInternalWriterData()
  92. {
  93. delete m_pOwnerToken;
  94. }
  95. // initialize an element
  96. void Initialize
  97. (
  98. IN VSS_ID idInstance,
  99. IN VSS_ID idWriter,
  100. IN BSTR bstrWriterName,
  101. IN BSTR bstrMetadata,
  102. IN TOKEN_OWNER *pOwnerToken
  103. )
  104. {
  105. m_idInstance = idInstance;
  106. m_idWriter = idWriter;
  107. m_bstrWriterName = bstrWriterName;
  108. m_bstrWriterMetadata = bstrMetadata;
  109. m_pOwnerToken = pOwnerToken;
  110. m_bstrWriterComponents.Empty();
  111. m_nState = VSS_WS_STABLE;
  112. m_hrWriterFailure = S_OK;
  113. }
  114. void SetComponents(IN BSTR bstrComponents)
  115. {
  116. m_bstrWriterComponents = bstrComponents;
  117. }
  118. // instance id of writer
  119. VSS_ID m_idInstance;
  120. // class id of the writer
  121. VSS_ID m_idWriter;
  122. // name of the writer
  123. CComBSTR m_bstrWriterName;
  124. // XML writer metadata from writer
  125. CComBSTR m_bstrWriterMetadata;
  126. // last writer failure
  127. // maintained in case writer is disabled
  128. HRESULT m_hrWriterFailure;
  129. // last writer state
  130. // maintained in case writer is disabled
  131. VSS_WRITER_STATE m_nState;
  132. // XML writer component data
  133. CComBSTR m_bstrWriterComponents;
  134. // next pointer
  135. CInternalWriterData *m_pDataNext;
  136. // security id for client thread
  137. TOKEN_OWNER *m_pOwnerToken;
  138. };
  139. // class to access a component from the BACKUP_COMPONENTS document
  140. class CVssComponent :
  141. public CVssMetadataHelper,
  142. public IVssComponent
  143. {
  144. friend class CVssWriterComponents;
  145. private:
  146. // constructor (can only be called from CVssWriterComponents)
  147. CVssComponent
  148. (
  149. IXMLDOMNode *pNode,
  150. IXMLDOMDocument *pDoc,
  151. CVssWriterComponents *pWriterComponents,
  152. bool bInRequestor,
  153. bool bRestore
  154. ) :
  155. CVssMetadataHelper(pNode, pDoc),
  156. m_cRef(0),
  157. m_pWriterComponents(pWriterComponents),
  158. m_bInRequestor(bInRequestor),
  159. m_bRestore(bRestore)
  160. {
  161. }
  162. // 2nd phase constructor
  163. void Initialize(CVssFunctionTracer &ft)
  164. {
  165. InitializeHelper(ft);
  166. }
  167. public:
  168. // obtain logical path of component
  169. STDMETHOD(GetLogicalPath)(OUT BSTR *pbstrPath);
  170. // obtain component type(VSS_CT_DATABASE or VSS_CT_FILEGROUP)
  171. STDMETHOD(GetComponentType)(VSS_COMPONENT_TYPE *pct);
  172. // get component name
  173. STDMETHOD(GetComponentName)(OUT BSTR *pbstrName);
  174. // determine whether the component was successfully backed up.
  175. STDMETHOD(GetBackupSucceeded)(OUT bool *pbSucceeded);
  176. // get altermative location mapping count
  177. STDMETHOD(GetAlternateLocationMappingCount)(OUT UINT *pcMappings);
  178. // get a paraticular alternative location mapping
  179. STDMETHOD(GetAlternateLocationMapping)
  180. (
  181. IN UINT iMapping,
  182. OUT IVssWMFiledesc **pFiledesc
  183. );
  184. // set the backup metadata for a component
  185. STDMETHOD(SetBackupMetadata)(IN LPCWSTR wszData);
  186. // get the backup metadata for a component
  187. STDMETHOD(GetBackupMetadata)(OUT BSTR *pbstrData);
  188. // indicate that only ranges in the file are to be backed up
  189. STDMETHOD(AddPartialFile)
  190. (
  191. IN LPCWSTR wszPath,
  192. IN LPCWSTR wszFilename,
  193. IN LPCWSTR wszRanges,
  194. IN LPCWSTR wszMetadata
  195. );
  196. // get count of partial file declarations
  197. STDMETHOD(GetPartialFileCount)
  198. (
  199. OUT UINT *pcPartialFiles
  200. );
  201. // get a partial file declaration
  202. STDMETHOD(GetPartialFile)
  203. (
  204. IN UINT iPartialFile,
  205. OUT BSTR *pbstrPath,
  206. OUT BSTR *pbstrFilename,
  207. OUT BSTR *pbstrRange,
  208. OUT BSTR *pbstrMetadata
  209. );
  210. // determine if the component is selected to be restored
  211. STDMETHOD(IsSelectedForRestore)
  212. (
  213. IN bool *pbSelectedForRestore
  214. );
  215. STDMETHOD(GetAdditionalRestores)
  216. (
  217. OUT bool *pbAdditionalRestores
  218. );
  219. // get count of new target specifications
  220. STDMETHOD(GetNewTargetCount)
  221. (
  222. OUT UINT *pcNewTarget
  223. );
  224. STDMETHOD(GetNewTarget)
  225. (
  226. IN UINT iNewTarget,
  227. OUT IVssWMFiledesc **ppFiledesc
  228. );
  229. // add a directed target specification
  230. STDMETHOD(AddDirectedTarget)
  231. (
  232. IN LPCWSTR wszSourcePath,
  233. IN LPCWSTR wszSourceFilename,
  234. IN LPCWSTR wszSourceRangeList,
  235. IN LPCWSTR wszDestinationPath,
  236. IN LPCWSTR wszDestinationFilename,
  237. IN LPCWSTR wszDestinationRangeList
  238. );
  239. // get count of directed target specifications
  240. STDMETHOD(GetDirectedTargetCount)
  241. (
  242. OUT UINT *pcDirectedTarget
  243. );
  244. // obtain a particular directed target specification
  245. STDMETHOD(GetDirectedTarget)
  246. (
  247. IN UINT iDirectedTarget,
  248. OUT BSTR *pbstrSourcePath,
  249. OUT BSTR *pbstrSourceFileName,
  250. OUT BSTR *pbstrSourceRangeList,
  251. OUT BSTR *pbstrDestinationPath,
  252. OUT BSTR *pbstrDestinationFilename,
  253. OUT BSTR *pbstrDestinationRangeList
  254. );
  255. // set restore metadata associated with the component
  256. STDMETHOD(SetRestoreMetadata)
  257. (
  258. IN LPCWSTR wszRestoreMetadata
  259. );
  260. // obtain restore metadata associated with the component
  261. STDMETHOD(GetRestoreMetadata)
  262. (
  263. OUT BSTR *pbstrRestoreMetadata
  264. );
  265. // set the restore target
  266. STDMETHOD(SetRestoreTarget)
  267. (
  268. IN VSS_RESTORE_TARGET target
  269. );
  270. // obtain the restore target
  271. STDMETHOD(GetRestoreTarget)
  272. (
  273. OUT VSS_RESTORE_TARGET *pTarget
  274. );
  275. // set failure message during pre restore event
  276. STDMETHOD(SetPreRestoreFailureMsg)
  277. (
  278. IN LPCWSTR wszPreRestoreFailureMsg
  279. );
  280. // obtain failure message during pre restore event
  281. STDMETHOD(GetPreRestoreFailureMsg)
  282. (
  283. OUT BSTR *pbstrPreRestoreFailureMsg
  284. );
  285. // set the failure message during the post restore event
  286. STDMETHOD(SetPostRestoreFailureMsg)
  287. (
  288. IN LPCWSTR wszPostRestoreFailureMsg
  289. );
  290. // obtain the failure message set during the post restore event
  291. STDMETHOD(GetPostRestoreFailureMsg)
  292. (
  293. OUT BSTR *pbstrPostRestoreFailureMsg
  294. );
  295. // set the backup stamp of the backup
  296. STDMETHOD(SetBackupStamp)
  297. (
  298. IN LPCWSTR wszBackupStamp
  299. );
  300. // obtain the stamp of the backup
  301. STDMETHOD(GetBackupStamp)
  302. (
  303. OUT BSTR *pbstrBackupStamp
  304. );
  305. // obtain the backup stamp that the differential or incremental
  306. // backup is baed on
  307. STDMETHOD(GetPreviousBackupStamp)
  308. (
  309. OUT BSTR *pbstrBackupStamp
  310. );
  311. // obtain backup options for the writer
  312. STDMETHOD(GetBackupOptions)
  313. (
  314. OUT BSTR *pbstrBackupOptions
  315. );
  316. // obtain the restore options
  317. STDMETHOD(GetRestoreOptions)
  318. (
  319. IN BSTR *pbstrRestoreOptions
  320. );
  321. // obtain count of subcomponents to be restored
  322. STDMETHOD(GetRestoreSubcomponentCount)
  323. (
  324. OUT UINT *pcRestoreSubcomponent
  325. );
  326. // obtain a particular subcomponent to be restored
  327. STDMETHOD(GetRestoreSubcomponent)
  328. (
  329. UINT iComponent,
  330. OUT BSTR *pbstrLogicalPath,
  331. OUT BSTR *pbstrComponentName,
  332. OUT bool *pbRepair
  333. );
  334. // obtain whether files were successfully restored
  335. STDMETHOD(GetFileRestoreStatus)
  336. (
  337. OUT VSS_FILE_RESTORE_STATUS *pStatus
  338. );
  339. // add differenced files by last modify time
  340. STDMETHOD(AddDifferencedFilesByLastModifyTime)
  341. (
  342. IN LPCWSTR wszPath,
  343. IN LPCWSTR wszFilespec,
  344. IN BOOL bRecursive,
  345. IN FILETIME ftLastModifyTime
  346. );
  347. STDMETHOD(AddDifferencedFilesByLastModifyLSN)
  348. (
  349. IN LPCWSTR wszPath,
  350. IN LPCWSTR wszFilespec,
  351. IN BOOL bRecursive,
  352. IN BSTR bstrLsnString
  353. );
  354. STDMETHOD(GetDifferencedFilesCount)
  355. (
  356. OUT UINT *pcDifferencedFiles
  357. );
  358. STDMETHOD(GetDifferencedFile)
  359. (
  360. IN UINT iDifferencedFile,
  361. OUT BSTR *pbstrPath,
  362. OUT BSTR *pbstrFilespec,
  363. OUT BOOL *pbRecursive,
  364. OUT BSTR *pbstrLsnString,
  365. OUT FILETIME *pftLastModifyTime
  366. );
  367. // IUnknown methods
  368. STDMETHOD(QueryInterface)(REFIID, void **);
  369. STDMETHOD_ (ULONG, AddRef)();
  370. STDMETHOD_ (ULONG, Release)();
  371. private:
  372. // common routine for setting backup and restore metadata
  373. HRESULT SetMetadata(IN bool bRestoreMetadata, IN LPCWSTR bstrMetadata);
  374. // common routine for adding differenced files
  375. void AddDifferencedFiles
  376. (
  377. IN CVssFunctionTracer& ft,
  378. IN LPCWSTR wszPath,
  379. IN LPCWSTR wszFilespec,
  380. IN BOOL bRecursive,
  381. IN FILETIME ftLastModifyTime,
  382. IN BSTR bstrLsnString
  383. );
  384. // common routine for retrieving backup and restore metadata
  385. HRESULT GetMetadata(IN bool bRestoreMetadata, OUT BSTR *pbstrMetadata);
  386. // get a particular element of a specific type as a file descriptor
  387. HRESULT CVssComponent::GetFiledescElement
  388. (
  389. IN LPCWSTR wszElement,
  390. IN UINT iMapping, // which mapping to select
  391. OUT IVssWMFiledesc **ppFiledesc // output file descriptor
  392. );
  393. // reference count for AddRef, Release
  394. LONG m_cRef;
  395. // pointer to parent writer components document if changes are allowed
  396. CVssWriterComponents *m_pWriterComponents;
  397. // are we in the requestor
  398. bool m_bInRequestor;
  399. // are we in restore
  400. bool m_bRestore;
  401. };
  402. // components associated with a specific writer
  403. class CVssWriterComponents :
  404. public CVssMetadataHelper,
  405. public IVssWriterComponentsInt
  406. {
  407. public:
  408. // constructor (can only be called from CVssBackupComponents)
  409. CVssWriterComponents
  410. (
  411. IXMLDOMNode *pNode,
  412. IXMLDOMDocument *pDoc,
  413. bool bWriteable,
  414. bool bRequestor,
  415. bool bRestore
  416. ) :
  417. CVssMetadataHelper(pNode, pDoc),
  418. m_cRef(0),
  419. m_bWriteable(bWriteable),
  420. m_bChanged(false),
  421. m_bInRequestor(bRequestor),
  422. m_bRestore(bRestore)
  423. {
  424. }
  425. // 2nd phase construction
  426. void Initialize(CVssFunctionTracer &ft)
  427. {
  428. InitializeHelper(ft);
  429. }
  430. // get count of components
  431. STDMETHOD(GetComponentCount)(OUT UINT *pcComponents);
  432. // get information about the writer
  433. STDMETHOD(GetWriterInfo)
  434. (
  435. OUT VSS_ID *pidInstance,
  436. OUT VSS_ID *pidWriter
  437. );
  438. // obtain a specific component
  439. STDMETHOD(GetComponent)
  440. (
  441. IN UINT iComponent,
  442. OUT IVssComponent **ppComponent
  443. );
  444. STDMETHOD(IsChanged)
  445. (
  446. OUT bool *pbChanged
  447. );
  448. STDMETHOD(SaveAsXML)
  449. (
  450. OUT BSTR *pbstrXMLDocument
  451. );
  452. // initialize writer components document to point at writer components
  453. // element
  454. STDMETHOD(Initialize)(bool fFindToplevel);
  455. STDMETHODIMP QueryInterface(REFIID, void **)
  456. {
  457. return E_NOTIMPL;
  458. }
  459. STDMETHOD_ (ULONG, AddRef)();
  460. STDMETHOD_ (ULONG, Release)();
  461. // indicate that document is changed
  462. void SetChanged()
  463. {
  464. BS_ASSERT(m_bWriteable);
  465. m_bChanged = TRUE;
  466. }
  467. private:
  468. // reference count for AddRef, Release
  469. LONG m_cRef;
  470. // can components be changed
  471. bool m_bWriteable;
  472. // is document changed
  473. bool m_bChanged;
  474. // are we in the requestor
  475. bool m_bInRequestor;
  476. // are we in restore
  477. bool m_bRestore;
  478. };
  479. // components associated with a specific writer
  480. class CVssNULLWriterComponents :
  481. public IVssWriterComponentsInt
  482. {
  483. public:
  484. CVssNULLWriterComponents
  485. (
  486. VSS_ID idInstance,
  487. VSS_ID idWriter
  488. )
  489. {
  490. m_cRef = 0;
  491. m_idInstance = idInstance;
  492. m_idWriter = idWriter;
  493. }
  494. // initialize
  495. STDMETHOD(Initialize)(bool fFindToplevel)
  496. {
  497. UNREFERENCED_PARAMETER(fFindToplevel);
  498. return S_OK;
  499. }
  500. // get count of components
  501. STDMETHOD(GetComponentCount)(OUT UINT *pcComponents);
  502. // get information about the writer
  503. STDMETHOD(GetWriterInfo)
  504. (
  505. OUT VSS_ID *pidInstance,
  506. OUT VSS_ID *pidWriter
  507. );
  508. // obtain a specific component
  509. STDMETHOD(GetComponent)
  510. (
  511. IN UINT iComponent,
  512. OUT IVssComponent **ppComponent
  513. );
  514. STDMETHOD(IsChanged)
  515. (
  516. OUT bool *pbChanged
  517. );
  518. STDMETHOD(SaveAsXML)
  519. (
  520. OUT BSTR *pbstrXMLDocument
  521. );
  522. STDMETHODIMP QueryInterface(REFIID, void **)
  523. {
  524. return E_NOTIMPL;
  525. }
  526. STDMETHOD_ (ULONG, AddRef)();
  527. STDMETHOD_ (ULONG, Release)();
  528. private:
  529. // id of writer class
  530. VSS_ID m_idWriter;
  531. // id of writer instance
  532. VSS_ID m_idInstance;
  533. // reference count for AddRef, Release
  534. LONG m_cRef;
  535. };
  536. // state of CVssBackupComponents object
  537. enum VSS_BACKUPCALL_STATE
  538. {
  539. x_StateUndefined = 0,
  540. x_StateInitialized,
  541. x_StateSnapshotSetCreated,
  542. x_StatePrepareForBackup,
  543. x_StatePrepareForBackupSucceeded,
  544. x_StatePrepareForBackupFailed,
  545. x_StateDoSnapshot,
  546. x_StateDoSnapshotSucceeded,
  547. x_StateDoSnapshotFailed,
  548. x_StateBackupComplete,
  549. x_StateBackupCompleteSucceeded,
  550. x_StateBackupCompleteFailed,
  551. x_StateAborting,
  552. x_StateAborted,
  553. x_StatePreRestore,
  554. x_StatePreRestoreSucceeded,
  555. x_StatePreRestoreFailed,
  556. x_StatePostRestore,
  557. x_StatePostRestoreSucceeded,
  558. x_StatePostRestoreFailed,
  559. x_StateGatheringWriterMetadata,
  560. x_StateGatheringWriterStatus
  561. };
  562. // class used by the backup application to interact with the writer
  563. class ATL_NO_VTABLE CVssBackupComponents :
  564. public CComObjectRoot,
  565. public IVssBackupComponents,
  566. public CVssMetadataHelper,
  567. public IDispatchImpl<IVssWriterCallback, &IID_IVssWriterCallback, &LIBID_VssEventLib, 1, 0>,
  568. public IVssCoordinatorCallback
  569. {
  570. public:
  571. friend class CVssAsyncBackup;
  572. friend class CVssAsyncCover;
  573. BEGIN_COM_MAP(CVssBackupComponents)
  574. COM_INTERFACE_ENTRY(IDispatch)
  575. COM_INTERFACE_ENTRY(IVssWriterCallback)
  576. COM_INTERFACE_ENTRY(IVssCoordinatorCallback)
  577. END_COM_MAP()
  578. // constructor
  579. CVssBackupComponents();
  580. // destructor
  581. ~CVssBackupComponents();
  582. // get count of writer components
  583. STDMETHOD(GetWriterComponentsCount)(OUT UINT *pcComponents);
  584. // obtain a specific writer component
  585. STDMETHOD(GetWriterComponents)
  586. (
  587. IN UINT iWriter,
  588. OUT IVssWriterComponentsExt **ppWriter
  589. );
  590. // initialize for backup
  591. STDMETHOD(InitializeForBackup)(IN BSTR bstrXML = NULL);
  592. // set backup state for backup components document
  593. STDMETHOD(SetBackupState)
  594. (
  595. IN bool bSelectComponents,
  596. IN bool bBackupBootableState,
  597. IN VSS_BACKUP_TYPE backupType,
  598. IN bool bPartialFileSupport
  599. );
  600. STDMETHOD(SetRestoreState)
  601. (
  602. IN VSS_RESTORE_TYPE restoreType
  603. );
  604. // initialize for restore
  605. STDMETHOD(InitializeForRestore)
  606. (
  607. IN BSTR bstrXML
  608. );
  609. // gather writer metadata
  610. STDMETHOD(GatherWriterMetadata)
  611. (
  612. OUT IVssAsync **ppAsync
  613. );
  614. // get count of writers
  615. STDMETHOD(GetWriterMetadataCount)
  616. (
  617. OUT UINT *pcWriters
  618. );
  619. // get writer metadata for a specific writer
  620. STDMETHOD(GetWriterMetadata)
  621. (
  622. IN UINT iWriter,
  623. OUT VSS_ID *pidInstance,
  624. OUT IVssExamineWriterMetadata **ppMetadata
  625. );
  626. // free XML data gathered from writers
  627. STDMETHOD(FreeWriterMetadata)();
  628. // Called to set the context for subsequent snapshot-related operations
  629. STDMETHOD(SetContext)
  630. (
  631. IN LONG lContext
  632. );
  633. // start a snapshot set
  634. STDMETHOD(StartSnapshotSet)
  635. (
  636. OUT VSS_ID *pSnapshotSetId
  637. );
  638. // add a volume to a snapshot set
  639. STDMETHOD(AddToSnapshotSet)
  640. (
  641. IN VSS_PWSZ pwszVolumeName,
  642. IN VSS_ID ProviderId,
  643. OUT VSS_ID *pSnapshotId
  644. );
  645. // add a component to the BACKUP_COMPONENTS document
  646. STDMETHOD(AddComponent)
  647. (
  648. IN VSS_ID instanceId,
  649. IN VSS_ID writerId,
  650. IN VSS_COMPONENT_TYPE ct,
  651. IN LPCWSTR wszLogicalPath,
  652. IN LPCWSTR wszComponentName
  653. );
  654. // dispatch PrepareForBackup event to writers
  655. STDMETHOD(PrepareForBackup)
  656. (
  657. OUT IVssAsync **ppAsync
  658. );
  659. // create the snapshot set
  660. STDMETHOD(DoSnapshotSet)
  661. (
  662. OUT IVssAsync** ppAsync
  663. );
  664. // abort the backup
  665. STDMETHOD(AbortBackup)();
  666. // dispatch the Identify event so writers can expose their metadata
  667. STDMETHOD(GatherWriterStatus)
  668. (
  669. OUT IVssAsync **ppAsync
  670. );
  671. // get count of writers with status
  672. STDMETHOD(GetWriterStatusCount)
  673. (
  674. OUT UINT *pcWriters
  675. );
  676. // obtain status information about writers
  677. STDMETHOD(GetWriterStatus)
  678. (
  679. IN UINT iWriter,
  680. OUT VSS_ID *pidInstance,
  681. OUT VSS_ID *pidWriter,
  682. OUT BSTR *pbstrWriterName,
  683. OUT VSS_WRITER_STATE *pStatus,
  684. OUT HRESULT *phrWriterFailure
  685. );
  686. // free data gathered using GetWriterStatus
  687. STDMETHOD(FreeWriterStatus)();
  688. // indicate whether backup succeeded on a component
  689. STDMETHOD(SetBackupSucceeded)
  690. (
  691. IN VSS_ID instanceId,
  692. IN VSS_ID writerId,
  693. IN VSS_COMPONENT_TYPE ct,
  694. IN LPCWSTR wszLogicalPath,
  695. IN LPCWSTR wszComponentName,
  696. IN bool bSucceded
  697. );
  698. // set backup options for the writer
  699. STDMETHOD(SetBackupOptions)
  700. (
  701. IN VSS_ID writerId,
  702. IN VSS_COMPONENT_TYPE ct,
  703. IN LPCWSTR wszLogicalPath,
  704. IN LPCWSTR wszComponentName,
  705. IN LPCWSTR wszBackupOptions
  706. );
  707. // indicate that a given component is selected to be restored
  708. STDMETHOD(SetSelectedForRestore)
  709. (
  710. IN VSS_ID writerId,
  711. IN VSS_COMPONENT_TYPE ct,
  712. IN LPCWSTR wszLogicalPath,
  713. IN LPCWSTR wszComponentName,
  714. IN bool bSelectedForRestore
  715. );
  716. // set restore options for the writer
  717. STDMETHOD(SetRestoreOptions)
  718. (
  719. IN VSS_ID writerId,
  720. IN VSS_COMPONENT_TYPE ct,
  721. IN LPCWSTR wszLogicalPath,
  722. IN LPCWSTR wszComponentName,
  723. IN LPCWSTR wszRestoreOptions
  724. );
  725. // indicate that additional restores will follow
  726. STDMETHOD(SetAdditionalRestores)
  727. (
  728. IN VSS_ID writerId,
  729. IN VSS_COMPONENT_TYPE ct,
  730. IN LPCWSTR wszLogicalPath,
  731. IN LPCWSTR wszComponentName,
  732. IN bool bAdditionalRestores
  733. );
  734. // requestor indicates whether files were successfully restored
  735. STDMETHOD(SetFileRestoreStatus)
  736. (
  737. IN VSS_ID writerId,
  738. IN VSS_COMPONENT_TYPE ct,
  739. IN LPCWSTR wszLogicalPath,
  740. IN LPCWSTR wszComponentName,
  741. IN VSS_FILE_RESTORE_STATUS status
  742. );
  743. // add a new location target for a file to be restored
  744. STDMETHOD(AddNewTarget)
  745. (
  746. IN VSS_ID writerId,
  747. IN VSS_COMPONENT_TYPE ct,
  748. IN LPCWSTR wszLogicalPath,
  749. IN LPCWSTR wszComponentName,
  750. IN LPCWSTR wszPath,
  751. IN LPCWSTR wszFileName,
  752. IN bool bRecursive,
  753. IN LPCWSTR wszAlternatePath
  754. ) ;
  755. // add a new location for the ranges file in case it was restored to
  756. // a different location
  757. STDMETHOD(SetRangesFilePath)
  758. (
  759. IN VSS_ID writerId,
  760. IN VSS_COMPONENT_TYPE ct,
  761. IN LPCWSTR wszLogicalPath,
  762. IN LPCWSTR wszComponentName,
  763. IN UINT iPartialFile,
  764. IN LPCWSTR wszRangesFile
  765. );
  766. // set the backup stamp that the differential or incremental
  767. // backup is based on
  768. STDMETHOD(SetPreviousBackupStamp)
  769. (
  770. IN VSS_ID writerId,
  771. IN VSS_COMPONENT_TYPE ct,
  772. IN LPCWSTR wszLogicalPath,
  773. IN LPCWSTR wszComponentName,
  774. IN LPCWSTR wszPreviousBackupStamp
  775. );
  776. // delete a set of snapshots
  777. STDMETHOD(DeleteSnapshots)
  778. (
  779. IN VSS_ID SourceObjectId,
  780. IN VSS_OBJECT_TYPE eSourceObjectType,
  781. IN BOOL bForceDelete,
  782. IN LONG* plDeletedSnapshots,
  783. IN VSS_ID* pNondeletedSnapshotID
  784. );
  785. // Break the snapshot set
  786. STDMETHOD(BreakSnapshotSet)
  787. (
  788. IN VSS_ID SnapshotSetId
  789. );
  790. STDMETHOD(ImportSnapshots)
  791. (
  792. OUT IVssAsync** ppAsync
  793. );
  794. // Get snapshot properties
  795. STDMETHOD(GetSnapshotProperties)
  796. (
  797. IN VSS_ID SnapshotId,
  798. OUT VSS_SNAPSHOT_PROP *pProp
  799. );
  800. // do a generic query using the coordinator
  801. STDMETHOD(Query)
  802. (
  803. IN VSS_ID QueriedObjectId,
  804. IN VSS_OBJECT_TYPE eQueriedObjectType,
  805. IN VSS_OBJECT_TYPE eReturnedObjectsType,
  806. IN IVssEnumObject **ppEnum
  807. );
  808. // save BACKUP_COMPONENTS document as XML string
  809. STDMETHOD(SaveAsXML)(BSTR *pbstrXML);
  810. // signal BackupComplete event to the writers
  811. STDMETHOD(BackupComplete)(OUT IVssAsync **ppAsync);
  812. // add an alternate mapping on restore
  813. STDMETHOD(AddAlternativeLocationMapping)
  814. (
  815. IN VSS_ID writerId,
  816. IN VSS_COMPONENT_TYPE componentType,
  817. IN LPCWSTR wszLogicalPath,
  818. IN LPCWSTR wszComponentName,
  819. IN LPCWSTR wszPath,
  820. IN LPCWSTR wszFilespec,
  821. IN bool bRecursive,
  822. IN LPCWSTR wszDestination
  823. );
  824. // add a subcomponent to be restored
  825. STDMETHOD(AddRestoreSubcomponent)
  826. (
  827. IN VSS_ID writerId,
  828. IN VSS_COMPONENT_TYPE componentType,
  829. IN LPCWSTR wszLogicalPath,
  830. IN LPCWSTR wszComponentName,
  831. IN LPCWSTR wszSubLogicalPath,
  832. IN LPCWSTR wszSubComponentName,
  833. IN bool bRepair
  834. );
  835. // signal PreRestore event to the writers
  836. STDMETHOD(PreRestore)(OUT IVssAsync **ppAsync);
  837. // signal PostRestore event to the writers
  838. STDMETHOD(PostRestore)(OUT IVssAsync **ppAsync);
  839. // IWriterCallback methods
  840. // called by writer to expose its WRITER_METADATA XML document
  841. STDMETHOD(ExposeWriterMetadata)
  842. (
  843. IN BSTR WriterInstanceId,
  844. IN BSTR WriterClassId,
  845. IN BSTR bstrWriterName,
  846. IN BSTR strWriterXMLMetadata
  847. );
  848. // called by the writer to obtain the WRITER_COMPONENTS document for it
  849. STDMETHOD(GetContent)
  850. (
  851. IN BSTR WriterInstanceId,
  852. OUT BSTR* pbstrXMLDOMDocContent
  853. );
  854. // called by the writer to obtain the WRITER_COMPONENTS document for it
  855. STDMETHOD(CoordGetContent)
  856. (
  857. IN BSTR WriterInstanceId,
  858. IN ULONG cbSid,
  859. IN BYTE *pbSid,
  860. OUT BSTR* pbstrXMLDOMDocContent
  861. );
  862. // called by the writer to update the WRITER_COMPONENTS document for it
  863. STDMETHOD(SetContent)
  864. (
  865. IN BSTR WriterInstanceId,
  866. IN BSTR bstrXMLDOMDocContent
  867. );
  868. // called by the writer to update the WRITER_COMPONENTS document for it
  869. STDMETHOD(CoordSetContent)
  870. (
  871. IN BSTR WriterInstanceId,
  872. IN ULONG cbSid,
  873. IN BYTE *pbSid,
  874. IN BSTR bstrXMLDOMDocContent
  875. );
  876. // called by the writer to get information about the backup
  877. STDMETHOD(GetBackupState)
  878. (
  879. OUT BOOL *pbBootableSystemStateBackedUp,
  880. OUT BOOL *pbAreComponentsSelected,
  881. OUT VSS_BACKUP_TYPE *pBackupType,
  882. OUT BOOL *pbPartialFileSupport,
  883. OUT LONG *plContext
  884. );
  885. // called by the writer to get information about the backup
  886. STDMETHOD(CoordGetBackupState)
  887. (
  888. OUT BOOL *pbBootableSystemStateBackedUp,
  889. OUT BOOL *pbAreComponentsSelected,
  890. OUT VSS_BACKUP_TYPE *pBackupType,
  891. OUT BOOL *pbPartialFileSupport,
  892. OUT LONG *plContext
  893. );
  894. STDMETHOD(GetRestoreState)
  895. (
  896. OUT VSS_RESTORE_TYPE *pRestoreType
  897. );
  898. STDMETHOD(CoordGetRestoreState)
  899. (
  900. OUT VSS_RESTORE_TYPE *pRestoreType
  901. );
  902. // called by the writer to indicate its status
  903. STDMETHOD(ExposeCurrentState)
  904. (
  905. IN BSTR WriterInstanceId,
  906. IN VSS_WRITER_STATE nCurrentState,
  907. IN HRESULT hrWriterFailure
  908. );
  909. // Called by the requestor to check if a certain volume is supported.
  910. STDMETHOD(IsVolumeSupported)
  911. (
  912. IN VSS_ID ProviderId,
  913. IN VSS_PWSZ pwszVolumeName,
  914. IN BOOL * pbSupportedByThisProvider
  915. );
  916. // called to disable writer classes
  917. STDMETHOD(DisableWriterClasses)
  918. (
  919. IN const VSS_ID *rgWriterClassId,
  920. IN UINT cClassId
  921. );
  922. // called to enable specific writer classes. Note that once specific
  923. // writer classes are enabled, only enabled classes are called.
  924. STDMETHOD(EnableWriterClasses)
  925. (
  926. IN const VSS_ID *rgWriterClassId,
  927. IN UINT cClassId
  928. );
  929. // called to disable an event call to a writer instance
  930. STDMETHOD(DisableWriterInstances)
  931. (
  932. IN const VSS_ID *rgWriterInstanceId,
  933. IN UINT cInstanceId
  934. );
  935. // called to expose a snapshot
  936. STDMETHOD(ExposeSnapshot)
  937. (
  938. IN VSS_ID SnapshotId,
  939. IN VSS_PWSZ wszPathFromRoot,
  940. IN LONG lAttributes,
  941. IN VSS_PWSZ wszExpose,
  942. OUT VSS_PWSZ *pwszExposed
  943. );
  944. STDMETHOD(RevertToSnapshot)
  945. (
  946. IN VSS_ID SnapshotId,
  947. IN BOOL bForceDismount
  948. );
  949. STDMETHOD(QueryRevertStatus)
  950. (
  951. IN VSS_PWSZ pwszVolume,
  952. OUT IVssAsync **ppAsync
  953. );
  954. private:
  955. // replace writer instance ids during restore to correspond
  956. // to those found in writer metadata
  957. void EnableWritersForRestore();
  958. // determine if a writer component has components selected for
  959. // restore
  960. bool IsComponentSelectedForRestore();
  961. // free XML component data gathered from writers
  962. void FreeWriterComponents();
  963. // validatate that the object has been initialized
  964. void ValidateInitialized(CVssFunctionTracer &ft);
  965. // basic initialization
  966. void BasicInit(IN CVssFunctionTracer &ft);
  967. // internal PrepareForBackup call
  968. HRESULT InternalPrepareForBackup(volatile LONG& finishing);
  969. // internal BackupComplete call
  970. HRESULT InternalBackupComplete(volatile LONG& finishing);
  971. // internal PreRestore call
  972. HRESULT InternalPreRestore(volatile LONG& finishing);
  973. // internal PostRestore call
  974. HRESULT InternalPostRestore(volatile LONG& finishing);
  975. // internal GatherWriterMetadata call
  976. HRESULT InternalGatherWriterMetadata(volatile LONG& finishing);
  977. // internal GatherWriterStatus call
  978. HRESULT InternalGatherWriterStatus(volatile LONG& finishing);
  979. // operation called at completion of GatherWriterMetadata
  980. // both by InternalGatherWriterMetadata and IVssAsync::Cancel
  981. HRESULT PostGatherWriterMetadata(volatile LONG& finishing, VSS_BACKUPCALL_STATE stateSaved, HRESULT hrSuccess,
  982. bool bCheckRequiredWriters);
  983. // called by IVssAsync::Cancel and InternalGatherWriterStatus
  984. // at completion of GatherWriterStatus
  985. HRESULT PostGatherWriterStatus(volatile LONG& finishing, VSS_BACKUPCALL_STATE stateSaved, HRESULT hrSuccess,
  986. bool bCheckResponses);
  987. // called by IVssAsync::Cancel and InternalPrepareForBackup
  988. // at completion of PrepareForBackup
  989. HRESULT PostPrepareForBackup(volatile LONG& finishing, HRESULT hrSuccess);
  990. // called by IVssAsync::Cancel and InternalBackupComplete
  991. // at completion of BackupComplete
  992. HRESULT PostBackupComplete(volatile LONG& finishing, HRESULT hrSuccess);
  993. // called by IVssAsync::Cancel and InternalPreRestore
  994. // at completion of PostPreRestore
  995. HRESULT PostPreRestore(volatile LONG& finishing, HRESULT hrSuccess);
  996. // called by IVssAsync::Cancel and InternalPostRestore
  997. // at completion of PostRestore
  998. HRESULT PostPostRestore(volatile LONG& finishing, HRESULT hrSuccess);
  999. // called by IVssAsync::Cancel and IVssAsync::QueryStatus
  1000. // at completion of DoSnapshotSet
  1001. HRESULT PostDoSnapshotSet(volatile LONG& finishing, bool bRebuild,
  1002. bool bFree, bool bSucceeded);
  1003. // Get an IVssCoordinator proxy for the current thread
  1004. // This performs internally an AddRef. It is caller responsibility to do a Release
  1005. void GetCoordinatorInterface(
  1006. IN CVssFunctionTracer &ft,
  1007. OUT CComPtr<IVssCoordinator> & ptrCoord // pass it by reference
  1008. );
  1009. // position on a WRITER_COMPONENTS element
  1010. CXMLNode PositionOnWriterComponents
  1011. (
  1012. IN CVssFunctionTracer &ft,
  1013. IN VSS_ID *pinstanceId,
  1014. IN VSS_ID writerId,
  1015. IN bool bCreateIfNotThere,
  1016. OUT bool &bCreated,
  1017. IN UINT uStartFromIndex = 0
  1018. ) throw(HRESULT);
  1019. // position on/create a specific component,
  1020. CXMLNode FindComponent
  1021. (
  1022. IN CVssFunctionTracer &ft,
  1023. IN VSS_ID *pinstanceId,
  1024. IN VSS_ID writerId,
  1025. IN LPCWSTR wszComponentType,
  1026. IN LPCWSTR wszLogicalPath,
  1027. IN LPCWSTR wszComponentName,
  1028. IN bool bCreate
  1029. );
  1030. // rebuild component data after PrepareForBackup
  1031. void RebuildComponentData(IN CVssFunctionTracer &ft);
  1032. // get an IVssWriterCallback interface. Implements GetComponent
  1033. void GetCallbackInterface(CVssFunctionTracer &ft, IDispatch **ppDispatch);
  1034. // setup writers interface
  1035. void SetupWriter
  1036. (
  1037. CVssFunctionTracer &ft,
  1038. IVssWriter **ppWriter,
  1039. bool bMetadataFire
  1040. );
  1041. // add writer data to queue
  1042. HRESULT AddWriterData
  1043. (
  1044. BSTR WriterInstanceId,
  1045. BSTR WriterClassId,
  1046. BSTR WriterName,
  1047. BSTR bstrWriterXMLDocument,
  1048. bool bReinitializing
  1049. );
  1050. // add writer data to queue and validate using supplied sid
  1051. HRESULT AddWriterDataWithSid
  1052. (
  1053. BSTR WriterInstanceId,
  1054. PSID WriterSid,
  1055. BSTR bstrWriterXMLDocument
  1056. );
  1057. // get actual content for the instance
  1058. HRESULT DoGetContent
  1059. (
  1060. VSS_ID idInstance,
  1061. BSTR *pbstrXMLDocContent
  1062. );
  1063. // find writer data with a particular instance id
  1064. CInternalWriterData *FindWriterData
  1065. (
  1066. VSS_ID idInstance,
  1067. bool bIsWriterId,
  1068. UINT *piWriter = NULL
  1069. );
  1070. // find writer data and validate the sid
  1071. void FindAndValidateWriterData
  1072. (
  1073. IN VSS_ID idInstance,
  1074. bool bIsWriterId,
  1075. OUT UINT *piWriter
  1076. );
  1077. // find writer data and validate using supplied sid
  1078. void FindAndValidateWriterDataWithSid
  1079. (
  1080. IN VSS_ID idInstance,
  1081. IN PSID psid,
  1082. OUT UINT *piWriter
  1083. );
  1084. // free all data about all writers
  1085. void FreeAllWriters();
  1086. // trim writers that are not in the backup components document
  1087. void TrimWriters();
  1088. // add a writer class to the writer class array
  1089. void AddWriterClass(const VSS_ID &id);
  1090. // remove a writer class from the writer class array
  1091. void RemoveWriterClass(const VSS_ID &id);
  1092. // is a writer class disabled
  1093. bool IsWriterClassDisabled(const VSS_ID &id);
  1094. // is a writer instance disabled
  1095. bool IsWriterInstanceDisabled(const VSS_ID &id);
  1096. // load the components XML document
  1097. void LoadComponentsDocument(BSTR bstr);
  1098. // set snapshot set description (by coordinator)
  1099. HRESULT SetSnapshotSetDescription(LPCWSTR wszXML);
  1100. // semaphore to serialize access to state-changing operations in class
  1101. HANDLE m_hOperation;
  1102. // used to indicate when an operation can be canceled
  1103. HANDLE m_hCancelEvent;
  1104. // current state we are in in a callback situation
  1105. // protected by m_hOperation
  1106. VSS_BACKUPCALL_STATE m_state;
  1107. // snapshot id
  1108. CComBSTR m_bstrSnapshotSetId;
  1109. // GUID form of the snapshot set ID
  1110. VSS_ID m_guidSnapshotSetId;
  1111. // Global pointer to IGlobalInterfaceTable
  1112. CVssSafeComPtr<IVssCoordinator> m_spCoordinator;
  1113. // synchronization protecting m_pMetadataFirst and m_cWriters
  1114. CVssSafeCriticalSection m_csWriters;
  1115. // count of writers,
  1116. // protected by m_csWriters
  1117. UINT m_cWriters;
  1118. // # of writer instances
  1119. UINT m_cWriterInstances;
  1120. // array of writer instances participating in the backup
  1121. VSS_ID *m_rgWriterInstances;
  1122. // count of writer classes to exclude
  1123. UINT m_cWriterClasses;
  1124. // writer classes to exclude
  1125. VSS_ID *m_rgWriterClasses;
  1126. // writer data,
  1127. // protected by m_csWriters
  1128. CInternalWriterData *m_pDataFirst;
  1129. CComPtr<IVssWriterCallback> m_pCallback;
  1130. // writer properties in GatherWriterStatus, GetWriterStatus
  1131. VSS_WRITER_PROP *m_rgWriterProp;
  1132. // is this a restore
  1133. bool m_bRestore;
  1134. // has this structure been initialized
  1135. bool m_bInitialized;
  1136. // has gather writer metdata completed
  1137. bool m_bGatherWriterMetadataComplete;
  1138. // has gather writer status completed
  1139. bool m_bGatherWriterStatusComplete;
  1140. // has SetBackupState been called
  1141. bool m_bSetBackupStateCalled;
  1142. // are writer classes excluded or included
  1143. bool m_bIncludeWriterClasses;
  1144. bool m_bWritersInSequence;
  1145. // root node of document
  1146. CComPtr<IXMLDOMNode> m_pNodeRoot;
  1147. // context used
  1148. LONG m_lContext;
  1149. // encapsulates the list of writer sids that are allowed to call back into the class
  1150. CVssSidCollection m_SidCollection;
  1151. // Used to keep track the last writer-related events
  1152. CVssDiag m_diagnose;
  1153. // has gather writer metdata been called? Do not call it twice on the same instance (BUG# 650274)
  1154. bool m_bGatherWriterMetadataCalled;
  1155. };
  1156. class IVssLunInformation : public IUnknown
  1157. {
  1158. public:
  1159. STDMETHOD(SetLunBasicType)
  1160. (
  1161. IN UCHAR DeviceType,
  1162. IN UCHAR DeviceTypeModifier,
  1163. IN BOOL bCommandQueueing,
  1164. IN LPCSTR wszVendorId,
  1165. IN LPCSTR wszProductId,
  1166. IN LPCSTR wszProductRevision,
  1167. IN LPCSTR wszSerialNumber,
  1168. IN VDS_STORAGE_BUS_TYPE busType
  1169. ) = 0;
  1170. STDMETHOD(GetLunBasicType)
  1171. (
  1172. OUT UCHAR *pDeviceType,
  1173. OUT UCHAR *pDeviceTypeModifier,
  1174. OUT BOOL *pbCommandQueueing,
  1175. OUT LPSTR *pstrVendorId,
  1176. OUT LPSTR *pstrProductId,
  1177. OUT LPSTR *pstrProductRevision,
  1178. OUT LPSTR *pstrSerialNumber,
  1179. OUT VDS_STORAGE_BUS_TYPE *pBusType
  1180. ) = 0;
  1181. STDMETHOD(GetDiskSignature)
  1182. (
  1183. OUT VSS_ID *pidSignature
  1184. ) = 0;
  1185. STDMETHOD(SetDiskSignature)
  1186. (
  1187. IN VSS_ID idSignature
  1188. ) = 0;
  1189. STDMETHOD(AddInterconnectAddress)
  1190. (
  1191. IN VDS_INTERCONNECT_ADDRESS_TYPE type,
  1192. ULONG cbPort,
  1193. const BYTE *pbPort,
  1194. ULONG cbAddress,
  1195. const BYTE *pbAddress
  1196. ) = 0;
  1197. STDMETHOD(GetInterconnectAddressCount)
  1198. (
  1199. OUT UINT *pcAddresses
  1200. ) = 0;
  1201. STDMETHOD(GetInterconnectAddress)
  1202. (
  1203. IN UINT iAddress,
  1204. OUT VDS_INTERCONNECT_ADDRESS_TYPE *pType,
  1205. OUT ULONG *pcbPort,
  1206. OUT LPBYTE *ppbPort,
  1207. OUT ULONG *pcbAddress,
  1208. OUT LPBYTE *ppbAddress
  1209. ) = 0;
  1210. STDMETHOD(SetStorageDeviceIdDescriptor)
  1211. (
  1212. IN STORAGE_DEVICE_ID_DESCRIPTOR *pDescriptor
  1213. ) = 0;
  1214. STDMETHOD(GetStorageDeviceIdDescriptor)
  1215. (
  1216. OUT STORAGE_DEVICE_ID_DESCRIPTOR **ppDescriptor
  1217. ) = 0;
  1218. };
  1219. class IVssLunMapping : public IUnknown
  1220. {
  1221. public:
  1222. STDMETHOD(AddDiskExtent)
  1223. (
  1224. IN ULONGLONG startingOffset,
  1225. IN ULONGLONG length
  1226. ) = 0;
  1227. STDMETHOD(GetDiskExtentCount)
  1228. (
  1229. OUT UINT *pcExtents
  1230. ) = 0;
  1231. STDMETHOD(GetDiskExtent)
  1232. (
  1233. IN UINT iExtent,
  1234. OUT ULONGLONG *pllStartingOffset,
  1235. OUT ULONGLONG *pllLength
  1236. ) = 0;
  1237. STDMETHOD(GetSourceDevice)
  1238. (
  1239. OUT BSTR *pbstrSourceDevice
  1240. ) = 0;
  1241. STDMETHOD(SetSourceDevice)
  1242. (
  1243. IN LPCWSTR wszSourceDevice
  1244. ) = 0;
  1245. STDMETHOD(GetSourceLun)
  1246. (
  1247. OUT IVssLunInformation **ppLun
  1248. ) = 0;
  1249. STDMETHOD(GetDestinationLun)
  1250. (
  1251. OUT IVssLunInformation **ppLun
  1252. ) = 0;
  1253. };
  1254. class IVssSnapshotDescription : public IUnknown
  1255. {
  1256. public:
  1257. STDMETHOD(GetSnapshotId)
  1258. (
  1259. OUT VSS_ID *pidSnapshot
  1260. ) = 0;
  1261. STDMETHOD(GetProviderId)
  1262. (
  1263. OUT VSS_ID *pidProvider
  1264. ) = 0;
  1265. STDMETHOD(GetTimestamp)
  1266. (
  1267. OUT VSS_TIMESTAMP *pTimestamp
  1268. ) = 0;
  1269. STDMETHOD(SetTimestamp)
  1270. (
  1271. IN VSS_TIMESTAMP timestamp
  1272. ) = 0;
  1273. STDMETHOD(GetAttributes)
  1274. (
  1275. OUT LONG *plAttributes
  1276. ) = 0;
  1277. STDMETHOD(SetAttributes)
  1278. (
  1279. IN LONG lAttributes
  1280. ) = 0;
  1281. STDMETHOD(GetOrigin)
  1282. (
  1283. OUT BSTR *pbstrOriginatingMachine,
  1284. OUT BSTR *pbstrOriginalVolume
  1285. ) = 0;
  1286. STDMETHOD(SetOrigin)
  1287. (
  1288. IN LPCWSTR wszOriginatingMachine,
  1289. IN LPCWSTR wszOriginalVolume
  1290. ) = 0;
  1291. STDMETHOD(IsDynamicVolume)
  1292. (
  1293. OUT bool *pbIsDynamic
  1294. ) = 0;
  1295. STDMETHOD(SetIsDynamicVolume)
  1296. (
  1297. IN bool bIsDynamic
  1298. ) = 0;
  1299. STDMETHOD(GetServiceMachine)
  1300. (
  1301. OUT BSTR *pbstrServiceMachine
  1302. ) = 0;
  1303. STDMETHOD(SetServiceMachine)
  1304. (
  1305. IN LPCWSTR wszServiceMachine
  1306. ) = 0;
  1307. STDMETHOD(GetDeviceName)
  1308. (
  1309. OUT BSTR *pbstrDeviceName
  1310. ) = 0;
  1311. STDMETHOD(SetDeviceName)
  1312. (
  1313. IN LPCWSTR wszDeviceName
  1314. ) = 0;
  1315. STDMETHOD(GetExposure)
  1316. (
  1317. OUT BSTR *pbstrExposedName,
  1318. OUT BSTR *pbstrExposedPath
  1319. ) = 0;
  1320. STDMETHOD(SetExposure)
  1321. (
  1322. IN LPCWSTR wszExposedName,
  1323. IN LPCWSTR wszExposedPath
  1324. ) = 0;
  1325. STDMETHOD(GetLunCount)
  1326. (
  1327. OUT UINT *pcLuns
  1328. ) = 0;
  1329. STDMETHOD(AddLunMapping)
  1330. (
  1331. ) = 0;
  1332. STDMETHOD(GetLunMapping)
  1333. (
  1334. UINT iMapping,
  1335. IVssLunMapping **pLunMapping
  1336. ) = 0;
  1337. };
  1338. // description of a snapshot set
  1339. class IVssSnapshotSetDescription : public IUnknown
  1340. {
  1341. public:
  1342. STDMETHOD(SaveAsXML)
  1343. (
  1344. OUT BSTR *pbstrXML
  1345. ) = 0;
  1346. STDMETHOD(GetToplevelNode)
  1347. (
  1348. OUT IXMLDOMNode **pNode,
  1349. OUT IXMLDOMDocument **ppDoc
  1350. ) = 0;
  1351. STDMETHOD(GetSnapshotSetId)
  1352. (
  1353. OUT VSS_ID *pidSnapshotSet
  1354. ) = 0;
  1355. STDMETHOD(GetDescription)
  1356. (
  1357. OUT BSTR *pbstrDescription
  1358. ) = 0;
  1359. STDMETHOD(SetDescription)
  1360. (
  1361. IN LPCWSTR wszDescription
  1362. ) = 0;
  1363. STDMETHOD(GetMetadata)
  1364. (
  1365. OUT BSTR *pbstrMetadata
  1366. ) = 0;
  1367. STDMETHOD(SetMetadata)
  1368. (
  1369. IN LPCWSTR wszMetadata
  1370. ) = 0;
  1371. STDMETHOD(GetContext)
  1372. (
  1373. OUT LONG *plContext
  1374. ) = 0;
  1375. STDMETHOD(GetSnapshotCount)
  1376. (
  1377. OUT UINT *pcSnapshots
  1378. ) = 0;
  1379. STDMETHOD(GetOriginalSnapshotCount)
  1380. (
  1381. OUT LONG *plSnapshotsCount
  1382. ) = 0;
  1383. STDMETHOD(SetOriginalSnapshotCount)
  1384. (
  1385. IN LONG lSnapshotsCount
  1386. ) = 0;
  1387. STDMETHOD(GetSnapshotDescription)
  1388. (
  1389. IN UINT iSnapshot,
  1390. OUT IVssSnapshotDescription **pSnapshot
  1391. ) = 0;
  1392. STDMETHOD(FindSnapshotDescription)
  1393. (
  1394. IN VSS_ID SnapshotId,
  1395. OUT IVssSnapshotDescription **pSnapshot
  1396. ) = 0;
  1397. STDMETHOD(AddSnapshotDescription)
  1398. (
  1399. IN VSS_ID idSnapshot,
  1400. IN VSS_ID idProvider
  1401. ) = 0;
  1402. STDMETHOD(DeleteSnapshotDescription)
  1403. (
  1404. IN VSS_ID idSnapshot
  1405. ) = 0;
  1406. };
  1407. class CVssSnapshotSetDescription :
  1408. public CVssMetadataHelper,
  1409. public IVssSnapshotSetDescription
  1410. {
  1411. public:
  1412. // constructor
  1413. CVssSnapshotSetDescription() :
  1414. m_cRef(0)
  1415. {
  1416. }
  1417. CVssSnapshotSetDescription
  1418. (
  1419. IXMLDOMNode *pNode,
  1420. IXMLDOMDocument *pDoc
  1421. ) :
  1422. CVssMetadataHelper(pNode, pDoc),
  1423. m_cRef(0)
  1424. {
  1425. }
  1426. // 2nd phase of initialization
  1427. void Initialize(CVssFunctionTracer &ft)
  1428. {
  1429. InitializeHelper(ft);
  1430. }
  1431. void LoadFromXML(LPCWSTR wszXML);
  1432. STDMETHOD(SaveAsXML)
  1433. (
  1434. OUT BSTR *pbstrXML
  1435. );
  1436. STDMETHOD(GetToplevelNode)
  1437. (
  1438. IXMLDOMNode **ppNode,
  1439. IXMLDOMDocument **ppDoc
  1440. );
  1441. STDMETHOD(GetSnapshotSetId)
  1442. (
  1443. OUT VSS_ID *pidSnapshotSet
  1444. );
  1445. STDMETHOD(GetDescription)
  1446. (
  1447. OUT BSTR *pbstrDescription
  1448. );
  1449. STDMETHOD(SetDescription)
  1450. (
  1451. IN LPCWSTR wszDescription
  1452. );
  1453. STDMETHOD(GetMetadata)
  1454. (
  1455. OUT BSTR *pbstrMetadata
  1456. );
  1457. STDMETHOD(SetMetadata)
  1458. (
  1459. IN LPCWSTR wszMetadata
  1460. );
  1461. STDMETHOD(GetContext)
  1462. (
  1463. OUT LONG *plContext
  1464. );
  1465. STDMETHOD(GetSnapshotCount)
  1466. (
  1467. OUT UINT *pcSnapshots
  1468. );
  1469. STDMETHOD(GetOriginalSnapshotCount)
  1470. (
  1471. OUT LONG *pcSnapshots
  1472. );
  1473. STDMETHOD(SetOriginalSnapshotCount)
  1474. (
  1475. IN LONG cSnapshots
  1476. );
  1477. STDMETHOD(GetSnapshotDescription)
  1478. (
  1479. IN UINT iSnapshot,
  1480. OUT IVssSnapshotDescription **pSnapshot
  1481. );
  1482. STDMETHOD(FindSnapshotDescription)
  1483. (
  1484. IN VSS_ID SnapshotId,
  1485. OUT IVssSnapshotDescription **pSnapshot
  1486. );
  1487. STDMETHOD(AddSnapshotDescription)
  1488. (
  1489. IN VSS_ID idSnapshot,
  1490. IN VSS_ID idProvider
  1491. );
  1492. STDMETHOD(DeleteSnapshotDescription)
  1493. (
  1494. IN VSS_ID idSnapshot
  1495. );
  1496. // IUnknown methods
  1497. STDMETHOD(QueryInterface)(REFIID, void **);
  1498. STDMETHOD_ (ULONG, AddRef)();
  1499. STDMETHOD_ (ULONG, Release)();
  1500. private:
  1501. LONG m_cRef;
  1502. };
  1503. class CVssSnapshotDescription :
  1504. public CVssMetadataHelper,
  1505. public IVssSnapshotDescription
  1506. {
  1507. friend class CVssSnapshotSetDescription;
  1508. private:
  1509. // can only be called by CVssSnapshotSetDescription
  1510. CVssSnapshotDescription
  1511. (
  1512. IXMLDOMNode *pNode,
  1513. IXMLDOMDocument *pDoc
  1514. ) :
  1515. CVssMetadataHelper(pNode, pDoc),
  1516. m_cRef(0)
  1517. {
  1518. }
  1519. // 2nd phase of initialization
  1520. void Initialize(CVssFunctionTracer &ft)
  1521. {
  1522. InitializeHelper(ft);
  1523. }
  1524. public:
  1525. STDMETHOD(GetSnapshotId)
  1526. (
  1527. OUT VSS_ID *pidSnapshot
  1528. );
  1529. STDMETHOD(GetProviderId)
  1530. (
  1531. OUT VSS_ID *pidProvider
  1532. );
  1533. STDMETHOD(GetTimestamp)
  1534. (
  1535. OUT VSS_TIMESTAMP *pTimestamp
  1536. );
  1537. STDMETHOD(SetTimestamp)
  1538. (
  1539. IN VSS_TIMESTAMP timestamp
  1540. );
  1541. STDMETHOD(GetAttributes)
  1542. (
  1543. OUT LONG *plAttributes
  1544. );
  1545. STDMETHOD(SetAttributes)
  1546. (
  1547. IN LONG lAttributes
  1548. );
  1549. STDMETHOD(GetOrigin)
  1550. (
  1551. OUT BSTR *pbstrOriginatingMachine,
  1552. OUT BSTR *pbstrOriginalVolume
  1553. );
  1554. STDMETHOD(SetOrigin)
  1555. (
  1556. IN LPCWSTR wszOriginatingMachine,
  1557. IN LPCWSTR wszOriginalVolume
  1558. );
  1559. STDMETHOD(IsDynamicVolume)
  1560. (
  1561. OUT bool *pbIsDynamic
  1562. );
  1563. STDMETHOD(SetIsDynamicVolume)
  1564. (
  1565. IN bool bIsDynamic
  1566. );
  1567. STDMETHOD(GetServiceMachine)
  1568. (
  1569. OUT BSTR *pbstrServiceMachine
  1570. );
  1571. STDMETHOD(SetServiceMachine)
  1572. (
  1573. IN LPCWSTR wszServiceMachine
  1574. );
  1575. STDMETHOD(GetDeviceName)
  1576. (
  1577. OUT BSTR *pbstrDeviceName
  1578. );
  1579. STDMETHOD(SetDeviceName)
  1580. (
  1581. IN LPCWSTR wszDeviceName
  1582. );
  1583. STDMETHOD(GetExposure)
  1584. (
  1585. OUT BSTR *pbstrExposedName,
  1586. OUT BSTR *pbstrExposedPath
  1587. );
  1588. STDMETHOD(SetExposure)
  1589. (
  1590. IN LPCWSTR wszExposedName,
  1591. IN LPCWSTR wszExposedPath
  1592. );
  1593. STDMETHOD(GetLunCount)
  1594. (
  1595. OUT UINT *pcLuns
  1596. );
  1597. STDMETHOD(AddLunMapping)
  1598. (
  1599. );
  1600. STDMETHOD(GetLunMapping)
  1601. (
  1602. UINT iMapping,
  1603. IVssLunMapping **ppLunMapping
  1604. );
  1605. // IUnknown methods
  1606. STDMETHOD(QueryInterface)(REFIID, void **);
  1607. STDMETHOD_ (ULONG, AddRef)();
  1608. STDMETHOD_ (ULONG, Release)();
  1609. private:
  1610. LONG m_cRef;
  1611. };
  1612. class CVssLunMapping :
  1613. public CVssMetadataHelper,
  1614. public IVssLunMapping
  1615. {
  1616. friend class CVssSnapshotDescription;
  1617. private:
  1618. // can only be called by CVssSnapshotDescription
  1619. CVssLunMapping
  1620. (
  1621. IXMLDOMNode *pNode,
  1622. IXMLDOMDocument *pDoc
  1623. ) :
  1624. CVssMetadataHelper(pNode, pDoc),
  1625. m_cRef(0)
  1626. {
  1627. }
  1628. // 2nd phase of initialization
  1629. void Initialize(CVssFunctionTracer &ft)
  1630. {
  1631. InitializeHelper(ft);
  1632. }
  1633. public:
  1634. STDMETHOD(AddDiskExtent)
  1635. (
  1636. IN ULONGLONG startingOffset,
  1637. IN ULONGLONG length
  1638. );
  1639. STDMETHOD(GetDiskExtentCount)
  1640. (
  1641. OUT UINT *pcExtents
  1642. );
  1643. STDMETHOD(GetDiskExtent)
  1644. (
  1645. IN UINT iExtent,
  1646. OUT ULONGLONG *pllStartingOffset,
  1647. OUT ULONGLONG *pllLength
  1648. );
  1649. STDMETHOD(GetSourceDevice)
  1650. (
  1651. OUT BSTR *pbstrSourceDevice
  1652. );
  1653. STDMETHOD(SetSourceDevice)
  1654. (
  1655. IN LPCWSTR wszSourceDevice
  1656. );
  1657. STDMETHOD(GetSourceLun)
  1658. (
  1659. OUT IVssLunInformation **ppLun
  1660. );
  1661. STDMETHOD(GetDestinationLun)
  1662. (
  1663. OUT IVssLunInformation **ppLun
  1664. );
  1665. // IUnknown methods
  1666. STDMETHOD(QueryInterface)(REFIID, void **);
  1667. STDMETHOD_ (ULONG, AddRef)();
  1668. STDMETHOD_ (ULONG, Release)();
  1669. private:
  1670. HRESULT GetLunInformation
  1671. (
  1672. IN LPCWSTR wszElement,
  1673. OUT IVssLunInformation **ppLun
  1674. );
  1675. LONG m_cRef;
  1676. };
  1677. class CVssLunInformation :
  1678. public CVssMetadataHelper,
  1679. public IVssLunInformation
  1680. {
  1681. friend class CVssLunMapping;
  1682. private:
  1683. // can only be called by CVssLunMapping
  1684. CVssLunInformation
  1685. (
  1686. IXMLDOMNode *pNode,
  1687. IXMLDOMDocument *pDoc
  1688. ) :
  1689. CVssMetadataHelper(pNode, pDoc),
  1690. m_cRef(0)
  1691. {
  1692. }
  1693. // 2nd phase of initialization
  1694. void Initialize(CVssFunctionTracer &ft)
  1695. {
  1696. InitializeHelper(ft);
  1697. }
  1698. public:
  1699. STDMETHOD(SetLunBasicType)
  1700. (
  1701. IN UCHAR DeviceType,
  1702. IN UCHAR DeviceTypeModifier,
  1703. IN BOOL bCommandQueueing,
  1704. IN LPCSTR szVendorId,
  1705. IN LPCSTR szProductId,
  1706. IN LPCSTR szProductRevision,
  1707. IN LPCSTR szSerialNumber,
  1708. IN VDS_STORAGE_BUS_TYPE busType
  1709. );
  1710. STDMETHOD(GetLunBasicType)
  1711. (
  1712. OUT UCHAR *pDeviceType,
  1713. OUT UCHAR *pDeviceTypeModifier,
  1714. OUT BOOL *pbCommandQueueing,
  1715. OUT LPSTR *pstrVendorId,
  1716. OUT LPSTR *pstrProductId,
  1717. OUT LPSTR *pstrProductRevision,
  1718. OUT LPSTR *pstrSerialNumber,
  1719. OUT VDS_STORAGE_BUS_TYPE *pBusType
  1720. );
  1721. STDMETHOD(GetDiskSignature)
  1722. (
  1723. OUT VSS_ID *pidSignature
  1724. );
  1725. STDMETHOD(SetDiskSignature)
  1726. (
  1727. IN VSS_ID idSignature
  1728. );
  1729. STDMETHOD(AddInterconnectAddress)
  1730. (
  1731. IN VDS_INTERCONNECT_ADDRESS_TYPE type,
  1732. IN ULONG cbPort,
  1733. IN const BYTE *pbPort,
  1734. IN ULONG cbAddress,
  1735. IN const BYTE *pbAddress
  1736. );
  1737. STDMETHOD(GetInterconnectAddressCount)
  1738. (
  1739. OUT UINT *pcAddresses
  1740. );
  1741. STDMETHOD(GetInterconnectAddress)
  1742. (
  1743. IN UINT iAddress,
  1744. OUT VDS_INTERCONNECT_ADDRESS_TYPE *pType,
  1745. OUT ULONG *pcbPort,
  1746. OUT LPBYTE *ppbPort,
  1747. OUT ULONG *pcbAddress,
  1748. OUT LPBYTE *ppbInterconnectAddress
  1749. );
  1750. STDMETHOD(SetStorageDeviceIdDescriptor)
  1751. (
  1752. IN STORAGE_DEVICE_ID_DESCRIPTOR *pDescriptor
  1753. );
  1754. STDMETHOD(GetStorageDeviceIdDescriptor)
  1755. (
  1756. OUT STORAGE_DEVICE_ID_DESCRIPTOR **ppDescriptor
  1757. );
  1758. // IUnknown methods
  1759. STDMETHOD(QueryInterface)(REFIID, void **);
  1760. STDMETHOD_ (ULONG, AddRef)();
  1761. STDMETHOD_ (ULONG, Release)();
  1762. private:
  1763. LONG m_cRef;
  1764. };
  1765. __declspec(dllexport)
  1766. HRESULT STDAPICALLTYPE CreateVssSnapshotSetDescription
  1767. (
  1768. IN VSS_ID idSnapshotSet,
  1769. IN LONG lContext,
  1770. OUT IVssSnapshotSetDescription **ppSnapshotSet
  1771. );
  1772. __declspec(dllexport)
  1773. HRESULT STDAPICALLTYPE LoadVssSnapshotSetDescription
  1774. (
  1775. IN LPCWSTR wszXML,
  1776. OUT IVssSnapshotSetDescription **ppSnapshotSet
  1777. );