blob: 0e67e7822ce6726e2b3ae21bc21ca81d79793000 [file] [log] [blame]
Tomoki Sekiyamab39297a2013-08-07 11:40:18 -04001/*
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
Markus Armbruster121d0712016-06-29 10:12:57 +020013#ifndef VSS_COMMON_H
14#define VSS_COMMON_H
Tomoki Sekiyamab39297a2013-08-07 11:40:18 -040015
16#define __MIDL_user_allocate_free_DEFINED__
Tomoki Sekiyamab39297a2013-08-07 11:40:18 -040017#include <windows.h>
18#include <shlwapi.h>
19
20/* Reduce warnings to include vss.h */
21
22/* Ignore annotations for MS IDE */
23#define __in IN
24#define __out OUT
25#define __RPC_unique_pointer
26#define __RPC_string
27#define __RPC__deref_inout_opt
28#define __RPC__out
29#ifndef __RPC__out_ecount_part
30#define __RPC__out_ecount_part(x, y)
31#endif
32#define _declspec(x)
33#undef uuid
34#define uuid(x)
35
36/* Undef some duplicated error codes redefined in vss.h */
37#undef VSS_E_BAD_STATE
38#undef VSS_E_PROVIDER_NOT_REGISTERED
39#undef VSS_E_PROVIDER_VETO
40#undef VSS_E_OBJECT_NOT_FOUND
41#undef VSS_E_VOLUME_NOT_SUPPORTED
42#undef VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER
43#undef VSS_E_OBJECT_ALREADY_EXISTS
44#undef VSS_E_UNEXPECTED_PROVIDER_ERROR
45#undef VSS_E_INVALID_XML_DOCUMENT
46#undef VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED
47#undef VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED
48
Marc-André Lureau61fb0bd2022-01-31 23:47:37 +040049#include <vss.h>
Sameeh Jubran94d81ae2017-04-11 10:50:36 +030050#include "vss-handles.h"
Tomoki Sekiyamab39297a2013-08-07 11:40:18 -040051
52/* Macros to convert char definitions to wchar */
53#define _L(a) L##a
54#define L(a) _L(a)
55
Tomoki Sekiyamab39297a2013-08-07 11:40:18 -040056const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
57 {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
58const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
59 {0x8d, 0x5c, 0x8f, 0xfc, 0x16, 0x3f, 0x24, 0xca} };
60
61const CLSID CLSID_QGAVSSProvider = { 0x6e6a3492, 0x8d4d, 0x440c,
62 {0x96, 0x19, 0x5e, 0x5d, 0x0c, 0xc3, 0x1c, 0xa8} };
63
64const TCHAR g_szClsid[] = TEXT("{6E6A3492-8D4D-440C-9619-5E5D0CC31CA8}");
65const TCHAR g_szProgid[] = TEXT("QGAVSSProvider");
66
Marc-André Lureau872b69e2022-02-22 23:40:02 +040067#ifdef HAVE_VSS_SDK
Tomoki Sekiyamab39297a2013-08-07 11:40:18 -040068/* Enums undefined in VSS SDK 7.2 but defined in newer Windows SDK */
69enum __VSS_VOLUME_SNAPSHOT_ATTRIBUTES {
70 VSS_VOLSNAP_ATTR_NO_AUTORECOVERY = 0x00000002,
71 VSS_VOLSNAP_ATTR_TXF_RECOVERY = 0x02000000
72};
Marc-André Lureau872b69e2022-02-22 23:40:02 +040073#endif
Tomoki Sekiyamab39297a2013-08-07 11:40:18 -040074
75/* COM pointer utility; call ->Release() when it goes out of scope */
76template <class T>
77class COMPointer {
78 COMPointer(const COMPointer<T> &p) { } /* no copy */
79 T *p;
80public:
81 COMPointer &operator=(T *new_p)
82 {
83 /* Assignment of a new T* (or NULL) causes release of previous p */
84 if (p && p != new_p) {
85 p->Release();
86 }
87 p = new_p;
88 return *this;
89 }
90 /* Replace by assignment to the pointer of p */
91 T **replace(void)
92 {
93 *this = NULL;
94 return &p;
95 }
96 /* Make COMPointer be used like T* */
97 operator T*() { return p; }
98 T *operator->(void) { return p; }
99 T &operator*(void) { return *p; }
100 operator bool() { return !!p; }
101
102 COMPointer(T *p = NULL) : p(p) { }
103 ~COMPointer() { *this = NULL; } /* Automatic release */
104};
105
106/*
107 * COM initializer; this should declared before COMPointer to uninitialize COM
108 * after releasing COM objects.
109 */
110class COMInitializer {
111public:
112 COMInitializer() { CoInitialize(NULL); }
113 ~COMInitializer() { CoUninitialize(); }
114};
115
116#endif