vss-common.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * QEMU Guest Agent win32 VSS common declarations
  3. *
  4. * Copyright Hitachi Data Systems Corp. 2013
  5. *
  6. * Authors:
  7. * Tomoki Sekiyama <tomoki.sekiyama@hds.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #ifndef VSS_COMMON_H
  13. #define VSS_COMMON_H
  14. #define __MIDL_user_allocate_free_DEFINED__
  15. #include <windows.h>
  16. #include <shlwapi.h>
  17. /* Reduce warnings to include vss.h */
  18. /* Ignore annotations for MS IDE */
  19. #define __in IN
  20. #define __out OUT
  21. #define __RPC_unique_pointer
  22. #define __RPC_string
  23. #define __RPC__deref_inout_opt
  24. #define __RPC__out
  25. #ifndef __RPC__out_ecount_part
  26. #define __RPC__out_ecount_part(x, y)
  27. #endif
  28. #define _declspec(x)
  29. #undef uuid
  30. #define uuid(x)
  31. /* Undef some duplicated error codes redefined in vss.h */
  32. #undef VSS_E_BAD_STATE
  33. #undef VSS_E_PROVIDER_NOT_REGISTERED
  34. #undef VSS_E_PROVIDER_VETO
  35. #undef VSS_E_OBJECT_NOT_FOUND
  36. #undef VSS_E_VOLUME_NOT_SUPPORTED
  37. #undef VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER
  38. #undef VSS_E_OBJECT_ALREADY_EXISTS
  39. #undef VSS_E_UNEXPECTED_PROVIDER_ERROR
  40. #undef VSS_E_INVALID_XML_DOCUMENT
  41. #undef VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED
  42. #undef VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED
  43. /*
  44. * VSS headers must be installed from Microsoft VSS SDK 7.2 available at:
  45. * http://www.microsoft.com/en-us/download/details.aspx?id=23490
  46. */
  47. #include <inc/win2003/vss.h>
  48. /* Macros to convert char definitions to wchar */
  49. #define _L(a) L##a
  50. #define L(a) _L(a)
  51. /* Constants for QGA VSS Provider */
  52. #define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
  53. #define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
  54. #define QGA_PROVIDER_VERSION L(QEMU_VERSION)
  55. #define EVENT_NAME_FROZEN "Global\\QGAVSSEvent-frozen"
  56. #define EVENT_NAME_THAW "Global\\QGAVSSEvent-thaw"
  57. #define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
  58. const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
  59. {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
  60. const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
  61. {0x8d, 0x5c, 0x8f, 0xfc, 0x16, 0x3f, 0x24, 0xca} };
  62. const CLSID CLSID_QGAVSSProvider = { 0x6e6a3492, 0x8d4d, 0x440c,
  63. {0x96, 0x19, 0x5e, 0x5d, 0x0c, 0xc3, 0x1c, 0xa8} };
  64. const TCHAR g_szClsid[] = TEXT("{6E6A3492-8D4D-440C-9619-5E5D0CC31CA8}");
  65. const TCHAR g_szProgid[] = TEXT("QGAVSSProvider");
  66. /* Enums undefined in VSS SDK 7.2 but defined in newer Windows SDK */
  67. enum __VSS_VOLUME_SNAPSHOT_ATTRIBUTES {
  68. VSS_VOLSNAP_ATTR_NO_AUTORECOVERY = 0x00000002,
  69. VSS_VOLSNAP_ATTR_TXF_RECOVERY = 0x02000000
  70. };
  71. /* COM pointer utility; call ->Release() when it goes out of scope */
  72. template <class T>
  73. class COMPointer {
  74. COMPointer(const COMPointer<T> &p) { } /* no copy */
  75. T *p;
  76. public:
  77. COMPointer &operator=(T *new_p)
  78. {
  79. /* Assignment of a new T* (or NULL) causes release of previous p */
  80. if (p && p != new_p) {
  81. p->Release();
  82. }
  83. p = new_p;
  84. return *this;
  85. }
  86. /* Replace by assignment to the pointer of p */
  87. T **replace(void)
  88. {
  89. *this = NULL;
  90. return &p;
  91. }
  92. /* Make COMPointer be used like T* */
  93. operator T*() { return p; }
  94. T *operator->(void) { return p; }
  95. T &operator*(void) { return *p; }
  96. operator bool() { return !!p; }
  97. COMPointer(T *p = NULL) : p(p) { }
  98. ~COMPointer() { *this = NULL; } /* Automatic release */
  99. };
  100. /*
  101. * COM initializer; this should declared before COMPointer to uninitialize COM
  102. * after releasing COM objects.
  103. */
  104. class COMInitializer {
  105. public:
  106. COMInitializer() { CoInitialize(NULL); }
  107. ~COMInitializer() { CoUninitialize(); }
  108. };
  109. #endif