/*
Bacula® - The Network Backup Solution
- Copyright (C) 2005-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2005-2010 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Bacula® is a registered trademark of John Walker.
+ Bacula® is a registered trademark of Kern Sibbald.
The licensor of Bacula is the Free Software Foundation Europe
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
#define uuid(x)
#ifdef B_VSS_XP
- #pragma message("compile VSS for Windows XP")
#define VSSClientGeneric VSSClientXP
#include "inc/WinXP/vss.h"
#endif
#ifdef B_VSS_W2K3
- #pragma message("compile VSS for Windows 2003")
#define VSSClientGeneric VSSClient2003
#include "inc/Win2003/vss.h"
#endif
#ifdef B_VSS_VISTA
- #pragma message("compile VSS for Vista")
#define VSSClientGeneric VSSClientVista
#include "inc/Win2003/vss.h"
#include "inc/Win2003/vsbackup.h"
#endif
- /* In VSSAPI.DLL */
- typedef HRESULT (STDAPICALLTYPE* t_CreateVssBackupComponents)(OUT IVssBackupComponents **);
- typedef void (APIENTRY* t_VssFreeSnapshotProperties)(IN VSS_SNAPSHOT_PROP*);
+/* In VSSAPI.DLL */
+typedef HRESULT (STDAPICALLTYPE* t_CreateVssBackupComponents)(OUT IVssBackupComponents **);
+typedef void (APIENTRY* t_VssFreeSnapshotProperties)(IN VSS_SNAPSHOT_PROP*);
- static t_CreateVssBackupComponents p_CreateVssBackupComponents = NULL;
- static t_VssFreeSnapshotProperties p_VssFreeSnapshotProperties = NULL;
+static t_CreateVssBackupComponents p_CreateVssBackupComponents = NULL;
+static t_VssFreeSnapshotProperties p_VssFreeSnapshotProperties = NULL;
- #define VSSVBACK_ENTRY "?CreateVssBackupComponents@@YGJPAPAVIVssBackupComponents@@@Z"
#include "vss.h"
// Constructor
+#ifdef HAVE_VSS64
+/* 64 bit entrypoint name */
+#define VSSVBACK_ENTRY "?CreateVssBackupComponents@@YAJPEAPEAVIVssBackupComponents@@@Z"
+#else
+/* 32 bit entrypoint name */
+#define VSSVBACK_ENTRY "?CreateVssBackupComponents@@YGJPAPAVIVssBackupComponents@@@Z"
+#endif
+
VSSClientGeneric::VSSClientGeneric()
{
m_hLib = LoadLibraryA("VSSAPI.DLL");
if (m_hLib) {
p_CreateVssBackupComponents = (t_CreateVssBackupComponents)
GetProcAddress(m_hLib, VSSVBACK_ENTRY);
-
p_VssFreeSnapshotProperties = (t_VssFreeSnapshotProperties)
GetProcAddress(m_hLib, "VssFreeSnapshotProperties");
}
}
// Initialize the COM infrastructure and the internal pointers
-BOOL VSSClientGeneric::Initialize(DWORD dwContext, BOOL bDuringRestore)
+bool VSSClientGeneric::Initialize(DWORD dwContext, bool bDuringRestore)
{
if (!(p_CreateVssBackupComponents && p_VssFreeSnapshotProperties)) {
Dmsg2(0, "VSSClientGeneric::Initialize: p_CreateVssBackupComponents = 0x%08X, p_VssFreeSnapshotProperties = 0x%08X\n", p_CreateVssBackupComponents, p_VssFreeSnapshotProperties);
errno = ENOSYS;
- return FALSE;
+ return false;
}
HRESULT hr;
if (FAILED(hr)) {
Dmsg1(0, "VSSClientGeneric::Initialize: CoInitialize returned 0x%08X\n", hr);
errno = b_errno_win32;
- return FALSE;
+ return false;
}
m_bCoInitializeCalled = true;
}
if (FAILED(hr)) {
Dmsg1(0, "VSSClientGeneric::Initialize: CoInitializeSecurity returned 0x%08X\n", hr);
errno = b_errno_win32;
- return FALSE;
+ return false;
}
m_bCoInitializeSecurityCalled = true;
}
// Create the internal backup components object
hr = p_CreateVssBackupComponents((IVssBackupComponents**) &m_pVssObject);
if (FAILED(hr)) {
- Dmsg1(0, "VSSClientGeneric::Initialize: CreateVssBackupComponents returned 0x%08X\n", hr);
+ berrno be;
+ Dmsg2(0, "VSSClientGeneric::Initialize: CreateVssBackupComponents returned 0x%08X. ERR=%s\n",
+ hr, be.bstrerror(b_errno_win32));
errno = b_errno_win32;
- return FALSE;
+ return false;
}
#if defined(B_VSS_W2K3) || defined(B_VSS_VISTA)
if (FAILED(hr)) {
Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->SetContext returned 0x%08X\n", hr);
errno = b_errno_win32;
- return FALSE;
+ return false;
}
}
#endif
if (FAILED(hr)) {
Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->InitializeForBackup returned 0x%08X\n", hr);
errno = b_errno_win32;
- return FALSE;
+ return false;
}
// 2. SetBackupState
if (FAILED(hr)) {
Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->SetBackupState returned 0x%08X\n", hr);
errno = b_errno_win32;
- return FALSE;
+ return false;
}
CComPtr<IVssAsync> pAsync1;
if (FAILED(hr)) {
Dmsg1(0, "VSSClientGeneric::Initialize: IVssBackupComponents->GatherWriterMetadata returned 0x%08X\n", hr);
errno = b_errno_win32;
- return FALSE;
+ return false;
}
// Waits for the async operation to finish and checks the result
WaitAndCheckForAsyncOperation(pAsync1.p);
// Keep the context
m_dwContext = dwContext;
- return TRUE;
+ return true;
}
-BOOL VSSClientGeneric::WaitAndCheckForAsyncOperation(IVssAsync* pAsync)
+bool VSSClientGeneric::WaitAndCheckForAsyncOperation(IVssAsync* pAsync)
{
// Wait until the async operation finishes
// unfortunately we can't use a timeout here yet.
} while ((timeout-- > 0) && (hrReturned == VSS_S_ASYNC_PENDING));
if (hrReturned == VSS_S_ASYNC_FINISHED)
- return TRUE;
+ return true;
#ifdef xDEBUG
}
#endif
- return FALSE;
+ return false;
}
-BOOL VSSClientGeneric::CreateSnapshots(char* szDriveLetters)
+bool VSSClientGeneric::CreateSnapshots(char* szDriveLetters)
{
/* szDriveLetters contains all drive letters in uppercase */
/* if a drive can not being added, it's converted to lowercase in szDriveLetters */
if (!m_pVssObject || m_bBackupIsInitialized) {
errno = ENOSYS;
- return FALSE;
+ return false;
}
m_uidCurrentSnapshotSet = GUID_NULL;
/* PrepareForBackup */
if (FAILED(pVss->PrepareForBackup(&pAsync1.p))) {
errno = b_errno_win32;
- return FALSE;
+ return false;
}
// Waits for the async operation to finish and checks the result
/* get latest info about writer status */
if (!CheckWriterStatus()) {
errno = b_errno_win32;
- return FALSE;
+ return false;
}
/* DoSnapShotSet */
if (FAILED(pVss->DoSnapshotSet(&pAsync2.p))) {
errno = b_errno_win32;
- return FALSE;
+ return false;
}
// Waits for the async operation to finish and checks the result
m_bBackupIsInitialized = true;
- return TRUE;
+ return true;
}
-BOOL VSSClientGeneric::CloseBackup()
+bool VSSClientGeneric::CloseBackup()
{
- BOOL bRet = FALSE;
+ bool bRet = false;
if (!m_pVssObject)
errno = ENOSYS;
else {
if (SUCCEEDED(pVss->BackupComplete(&pAsync.p))) {
// Waits for the async operation to finish and checks the result
WaitAndCheckForAsyncOperation(pAsync.p);
- bRet = TRUE;
+ bRet = true;
} else {
errno = b_errno_win32;
pVss->AbortBackup();
pVss->DeleteSnapshots(
m_uidCurrentSnapshotSet,
VSS_OBJECT_SNAPSHOT_SET,
- FALSE,
+ false,
&lSnapshots,
&idNonDeletedSnapshotID);
}
// Check the status for all selected writers
-BOOL VSSClientGeneric::CheckWriterStatus()
+bool VSSClientGeneric::CheckWriterStatus()
{
/*
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vss/base/ivssbackupcomponents_startsnapshotset.asp
HRESULT hr = pVss->GatherWriterStatus(&pAsync.p);
if (FAILED(hr)) {
errno = b_errno_win32;
- return FALSE;
+ return false;
}
// Waits for the async operation to finish and checks the result
hr = pVss->GetWriterStatusCount(&cWriters);
if (FAILED(hr)) {
errno = b_errno_win32;
- return FALSE;
+ return false;
}
int nState;
if (FAILED(hr)) {
errno = b_errno_win32;
- return FALSE;
+ return false;
}
errno = 0;
- return TRUE;
+ return true;
}
#endif /* WIN32_VSS */