#if defined(WIN32_VSS)
/* START VSS ON WIN32 */
if (jcr->VSS) {
- if (g_pVSSClient->InitializeForBackup()) {
+ if (g_pVSSClient->InitializeForBackup(jcr)) {
/* tell vss which drives to snapshot */
char szWinDriveLetters[27];
if (get_win32_driveletters(jcr->ff, szWinDriveLetters)) {
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2005-2008 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.
return;
}
/* Vista or Longhorn or later */
-// } else if (g_MajorVersion == 6 && g_MinorVersion == 0) {
} else if (g_MajorVersion >= 6) {
g_pVSSClient = new VSSClientVista();
atexit(VSSCleanup);
}
DestroyWriterInfo();
- delete (alist*)m_pAlistWriterState;
- delete (alist*)m_pAlistWriterInfoText;
+ delete m_pAlistWriterState;
+ delete m_pAlistWriterInfoText;
// Call CoUninitialize if the CoInitialize was performed successfully
if (m_bCoInitializeCalled)
CoUninitialize();
}
-BOOL VSSClient::InitializeForBackup()
+bool VSSClient::InitializeForBackup(JCR *jcr)
{
//return Initialize (VSS_CTX_BACKUP);
+ m_jcr = jcr;
return Initialize(0);
}
-BOOL VSSClient::GetShadowPath(const char *szFilePath, char *szShadowPath, int nBuflen)
+bool VSSClient::GetShadowPath(const char *szFilePath, char *szShadowPath, int nBuflen)
{
if (!m_bBackupIsInitialized)
- return FALSE;
+ return false;
/* check for valid pathname */
- BOOL bIsValidName;
+ bool bIsValidName;
bIsValidName = strlen(szFilePath) > 3;
if (bIsValidName)
if (WideCharToMultiByte(CP_UTF8,0,m_szShadowCopyName[nDriveIndex],-1,szShadowPath,nBuflen-1,NULL,NULL)) {
nBuflen -= (int)strlen(szShadowPath);
bstrncat(szShadowPath, szFilePath+2, nBuflen);
- return TRUE;
+ return true;
}
}
}
bstrncpy(szShadowPath, szFilePath, nBuflen);
errno = EINVAL;
- return FALSE;
+ return false;
}
-BOOL VSSClient::GetShadowPathW(const wchar_t *szFilePath, wchar_t *szShadowPath, int nBuflen)
+bool VSSClient::GetShadowPathW(const wchar_t *szFilePath, wchar_t *szShadowPath, int nBuflen)
{
if (!m_bBackupIsInitialized)
- return FALSE;
+ return false;
/* check for valid pathname */
- BOOL bIsValidName;
+ bool bIsValidName;
bIsValidName = wcslen(szFilePath) > 3;
if (bIsValidName)
wcsncpy(szShadowPath, m_szShadowCopyName[nDriveIndex], nBuflen);
nBuflen -= (int)wcslen(m_szShadowCopyName[nDriveIndex]);
wcsncat(szShadowPath, szFilePath+2, nBuflen);
- return TRUE;
+ return true;
}
}
wcsncpy(szShadowPath, szFilePath, nBuflen);
errno = EINVAL;
- return FALSE;
+ return false;
}
const size_t VSSClient::GetWriterCount()
{
- alist* pV = (alist*)m_pAlistWriterInfoText;
+ alist* pV = m_pAlistWriterInfoText;
return pV->size();
}
const char* VSSClient::GetWriterInfo(int nIndex)
{
- alist* pV = (alist*)m_pAlistWriterInfoText;
+ alist* pV = m_pAlistWriterInfoText;
return (char*)pV->get(nIndex);
}
const int VSSClient::GetWriterState(int nIndex)
{
- alist* pV = (alist*)m_pAlistWriterState;
- return (intptr_t)pV->get(nIndex);
+ alist* pV = m_pAlistWriterState;
+ return (int64_t)pV->get(nIndex);
}
void VSSClient::AppendWriterInfo(int nState, const char* pszInfo)
{
- alist* pT = (alist*) m_pAlistWriterInfoText;
- alist* pS = (alist*) m_pAlistWriterState;
+ alist* pT = m_pAlistWriterInfoText;
+ alist* pS = m_pAlistWriterState;
pT->push(bstrdup(pszInfo));
pS->push((void*)nState);
void VSSClient::DestroyWriterInfo()
{
- alist* pT = (alist*)m_pAlistWriterInfoText;
- alist* pS = (alist*)m_pAlistWriterState;
+ alist* pT = m_pAlistWriterInfoText;
+ alist* pS = m_pAlistWriterState;
while (!pT->empty())
free(pT->pop());
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2006-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2006-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.
virtual ~VSSClient();
// Backup Process
- BOOL InitializeForBackup();
- virtual BOOL CreateSnapshots(char* szDriveLetters) = 0;
- virtual BOOL CloseBackup() = 0;
+ bool InitializeForBackup(JCR *jcr);
+ virtual bool CreateSnapshots(char* szDriveLetters) = 0;
+ virtual bool CloseBackup() = 0;
virtual const char* GetDriverName() = 0;
- BOOL GetShadowPath (const char* szFilePath, char* szShadowPath, int nBuflen);
- BOOL GetShadowPathW (const wchar_t* szFilePath, wchar_t* szShadowPath, int nBuflen); /* nBuflen in characters */
+ bool GetShadowPath (const char* szFilePath, char* szShadowPath, int nBuflen);
+ bool GetShadowPathW (const wchar_t* szFilePath, wchar_t* szShadowPath, int nBuflen); /* nBuflen in characters */
const size_t GetWriterCount();
const char* GetWriterInfo(int nIndex);
const int GetWriterState(int nIndex);
void DestroyWriterInfo();
void AppendWriterInfo(int nState, const char* pszInfo);
- const BOOL IsInitialized() { return m_bBackupIsInitialized; };
+ const bool IsInitialized() { return m_bBackupIsInitialized; };
private:
- virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore = FALSE) = 0;
- virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync) = 0;
+ virtual bool Initialize(DWORD dwContext, bool bDuringRestore = FALSE) = 0;
+ virtual bool WaitAndCheckForAsyncOperation(IVssAsync* pAsync) = 0;
virtual void QuerySnapshotSet(GUID snapshotSetID) = 0;
protected:
- HMODULE m_hLib;
+ HMODULE m_hLib;
+ JCR *m_jcr;
- BOOL m_bCoInitializeCalled;
- BOOL m_bCoInitializeSecurityCalled;
- DWORD m_dwContext;
+ DWORD m_dwContext;
- IUnknown* m_pVssObject;
- GUID m_uidCurrentSnapshotSet;
- // TRUE if we are during restore
- BOOL m_bDuringRestore;
- BOOL m_bBackupIsInitialized;
+ IUnknown* m_pVssObject;
+ GUID m_uidCurrentSnapshotSet;
// drive A will be stored on position 0,Z on pos. 25
- wchar_t m_wszUniqueVolumeName[26][MAX_PATH]; // approx. 7 KB
- wchar_t m_szShadowCopyName[26][MAX_PATH]; // approx. 7 KB
+ wchar_t m_wszUniqueVolumeName[26][MAX_PATH]; // approx. 7 KB
+ wchar_t m_szShadowCopyName[26][MAX_PATH]; // approx. 7 KB
- void* m_pAlistWriterState;
- void* m_pAlistWriterInfoText;
+ alist *m_pAlistWriterState;
+ alist *m_pAlistWriterInfoText;
+
+ bool m_bCoInitializeCalled;
+ bool m_bCoInitializeSecurityCalled;
+ bool m_bDuringRestore; /* true if we are doing a restore */
+ bool m_bBackupIsInitialized;
};
class VSSClientXP:public VSSClient
public:
VSSClientXP();
virtual ~VSSClientXP();
- virtual BOOL CreateSnapshots(char* szDriveLetters);
- virtual BOOL CloseBackup();
+ virtual bool CreateSnapshots(char* szDriveLetters);
+ virtual bool CloseBackup();
virtual const char* GetDriverName() { return "VSS WinXP"; };
private:
- virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore);
- virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
+ virtual bool Initialize(DWORD dwContext, bool bDuringRestore);
+ virtual bool WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
virtual void QuerySnapshotSet(GUID snapshotSetID);
- BOOL CheckWriterStatus();
+ bool CheckWriterStatus();
};
class VSSClient2003:public VSSClient
public:
VSSClient2003();
virtual ~VSSClient2003();
- virtual BOOL CreateSnapshots(char* szDriveLetters);
- virtual BOOL CloseBackup();
+ virtual bool CreateSnapshots(char* szDriveLetters);
+ virtual bool CloseBackup();
virtual const char* GetDriverName() { return "VSS Win 2003"; };
private:
- virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore);
- virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
+ virtual bool Initialize(DWORD dwContext, bool bDuringRestore);
+ virtual bool WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
virtual void QuerySnapshotSet(GUID snapshotSetID);
- BOOL CheckWriterStatus();
+ bool CheckWriterStatus();
};
class VSSClientVista:public VSSClient
public:
VSSClientVista();
virtual ~VSSClientVista();
- virtual BOOL CreateSnapshots(char* szDriveLetters);
- virtual BOOL CloseBackup();
+ virtual bool CreateSnapshots(char* szDriveLetters);
+ virtual bool CloseBackup();
virtual const char* GetDriverName() { return "VSS Vista"; };
private:
- virtual BOOL Initialize(DWORD dwContext, BOOL bDuringRestore);
- virtual BOOL WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
+ virtual bool Initialize(DWORD dwContext, bool bDuringRestore);
+ virtual bool WaitAndCheckForAsyncOperation(IVssAsync* pAsync);
virtual void QuerySnapshotSet(GUID snapshotSetID);
- BOOL CheckWriterStatus();
+ bool CheckWriterStatus();
};
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2005-2008 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.
}
// 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;
}
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 */