From 4226e548662339ea1ca37b45385a7cf9b237ff1e Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:07:43 +0200 Subject: 3.8 --- shared/ShadowCopy/Shadow_2003.vcproj | 413 ---------------------------------- shared/ShadowCopy/Shadow_2003.vcxproj | 238 ++++++++++++++++++++ shared/ShadowCopy/Shadow_XP.vcproj | 413 ---------------------------------- shared/ShadowCopy/Shadow_XP.vcxproj | 239 ++++++++++++++++++++ shared/ShadowCopy/dllmain.cpp | 2 +- shared/ShadowCopy/shadow.cpp | 71 ++++-- 6 files changed, 524 insertions(+), 852 deletions(-) delete mode 100644 shared/ShadowCopy/Shadow_2003.vcproj create mode 100644 shared/ShadowCopy/Shadow_2003.vcxproj delete mode 100644 shared/ShadowCopy/Shadow_XP.vcproj create mode 100644 shared/ShadowCopy/Shadow_XP.vcxproj (limited to 'shared/ShadowCopy') diff --git a/shared/ShadowCopy/Shadow_2003.vcproj b/shared/ShadowCopy/Shadow_2003.vcproj deleted file mode 100644 index 49730440..00000000 --- a/shared/ShadowCopy/Shadow_2003.vcproj +++ /dev/null @@ -1,413 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/shared/ShadowCopy/Shadow_2003.vcxproj b/shared/ShadowCopy/Shadow_2003.vcxproj new file mode 100644 index 00000000..b7d31ae4 --- /dev/null +++ b/shared/ShadowCopy/Shadow_2003.vcxproj @@ -0,0 +1,238 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + Server2003 + {2F2994D6-FB89-4BAA-A5DF-03BAF7337FF2} + ShadowDll + Win32Proj + + + + DynamicLibrary + Unicode + true + false + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + true + Windows7.1SDK + + + DynamicLibrary + Unicode + Windows7.1SDK + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + Shadow_$(ProjectName)_$(Platform) + Shadow_$(ProjectName)_$(Platform) + Shadow_$(ProjectName)_$(Platform) + Shadow_$(ProjectName)_$(Platform) + + + + $(IntDir)Build.html + + + Disabled + _DEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_2003;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + true + EditAndContinue + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + true + $(IntDir)$(TargetName).pdb + Windows + + + $(IntDir)$(TargetName).lib + MachineX86 + + + + + $(IntDir)Build.html + + + X64 + + + Disabled + _DEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_2003;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + true + ProgramDatabase + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + true + $(IntDir)$(TargetName).pdb + Windows + + + $(IntDir)$(TargetName).lib + MachineX64 + + + + + $(IntDir)Build.html + + + MaxSpeed + true + NDEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_2003;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level4 + true + ProgramDatabase + Speed + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + false + Windows + true + true + UseLinkTimeCodeGeneration + + + $(IntDir)$(TargetName).lib + MachineX86 + + + + + $(IntDir)Build.html + + + X64 + + + MaxSpeed + true + NDEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_2003;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level4 + true + ProgramDatabase + Speed + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + false + Windows + true + true + UseLinkTimeCodeGeneration + + + $(IntDir)$(TargetName).lib + MachineX64 + + + + + + + false + + + false + + + false + + + false + + + + + + + + + + + + + \ No newline at end of file diff --git a/shared/ShadowCopy/Shadow_XP.vcproj b/shared/ShadowCopy/Shadow_XP.vcproj deleted file mode 100644 index 74b231de..00000000 --- a/shared/ShadowCopy/Shadow_XP.vcproj +++ /dev/null @@ -1,413 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/shared/ShadowCopy/Shadow_XP.vcxproj b/shared/ShadowCopy/Shadow_XP.vcxproj new file mode 100644 index 00000000..5c531a27 --- /dev/null +++ b/shared/ShadowCopy/Shadow_XP.vcxproj @@ -0,0 +1,239 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + XP + {70394AEF-5897-4911-AFA1-82EAF0581EFA} + ShadowDll + Win32Proj + + + + DynamicLibrary + Unicode + true + + + DynamicLibrary + Unicode + + + DynamicLibrary + Unicode + true + Windows7.1SDK + + + DynamicLibrary + Unicode + Windows7.1SDK + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + .\ + OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ + false + Shadow_$(ProjectName)_$(Platform) + Shadow_$(ProjectName)_$(Platform) + Shadow_$(ProjectName)_$(Platform) + Shadow_$(ProjectName)_$(Platform) + + + + $(IntDir)Build.html + + + Disabled + _DEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_XP;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + true + EditAndContinue + Neither + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + true + $(IntDir)$(TargetName).pdb + Windows + + + $(IntDir)$(TargetName).lib + MachineX86 + + + + + $(IntDir)Build.html + + + X64 + + + Disabled + _DEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_XP;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level4 + true + ProgramDatabase + Neither + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + true + $(IntDir)$(TargetName).pdb + Windows + + + $(IntDir)$(TargetName).lib + MachineX64 + + + + + $(IntDir)Build.html + + + MaxSpeed + true + NDEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_XP;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level4 + true + ProgramDatabase + Speed + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + false + Windows + true + true + UseLinkTimeCodeGeneration + + + $(IntDir)$(TargetName).lib + MachineX86 + + + + + $(IntDir)Build.html + + + X64 + + + MaxSpeed + true + NDEBUG;_WINDOWS;_USRDLL;SHADOWDLL_EXPORTS;USE_SHADOW_XP;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level4 + true + ProgramDatabase + Speed + 4100 + + + $(OutDir)$(TargetName)$(TargetExt) + true + false + Windows + true + true + UseLinkTimeCodeGeneration + + + $(IntDir)$(TargetName).lib + MachineX64 + + + + + + + false + + + false + + + false + + + false + + + + + + + + + + + + + \ No newline at end of file diff --git a/shared/ShadowCopy/dllmain.cpp b/shared/ShadowCopy/dllmain.cpp index 7db39bff..8dae897a 100644 --- a/shared/ShadowCopy/dllmain.cpp +++ b/shared/ShadowCopy/dllmain.cpp @@ -14,7 +14,7 @@ BOOL APIENTRY DllMain( HMODULE hModule, LPVOID lpReserved ) { - switch (ul_reason_for_call) + switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: diff --git a/shared/ShadowCopy/shadow.cpp b/shared/ShadowCopy/shadow.cpp index b15bd4f9..1fb78769 100644 --- a/shared/ShadowCopy/shadow.cpp +++ b/shared/ShadowCopy/shadow.cpp @@ -15,7 +15,7 @@ #include "xp/inc/vsbackup.h" #elif defined USE_SHADOW_2003 -#include "Server 2003/inc/vss.h" +#include "Server 2003/inc/vss.h" #include "Server 2003/inc/vswriter.h" #include "Server 2003/inc/vsbackup.h" #else @@ -30,6 +30,37 @@ adapt! //typedef GUID VSS_ID; + +//IShellItem resource management: better handled with boost::shared_ptr or CComPtr, but we avoid dependency with boost and ATL in this case +template +class ItemHolder +{ +public: + ItemHolder(T* item) : item_(item) {} + ~ItemHolder() + { + if (item_) + item_->Release(); + } + + T* release() +{ +T* rv = item_; +item_ = 0; + return rv; + } + + T* operator->() const +{ + return item_; + } +private: + ItemHolder(const ItemHolder&); + ItemHolder& operator=(const ItemHolder&); + T* item_; +}; + + void writeString(const wchar_t* input, wchar_t* output, unsigned int outputBufferLen) { const size_t newSize = min(wcslen(input) + 1, outputBufferLen); //including null-termination @@ -59,7 +90,7 @@ void writeErrorMsg(const wchar_t* input, HRESULT hr, wchar_t* output, unsigned i } -bool shadow::createShadowCopy(const wchar_t* volumeName, +bool Shadow::createShadowCopy(const wchar_t* volumeName, wchar_t* shadowVolName, unsigned int shadowBufferLen, void** backupHandle, @@ -70,8 +101,8 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, *backupHandle = NULL; HRESULT hr = NULL; - IVssBackupComponents* pBackupComponents = NULL; - if (FAILED(hr = CreateVssBackupComponents(&pBackupComponents))) + IVssBackupComponents* pBackupPtr = NULL; + if (FAILED(hr = CreateVssBackupComponents(&pBackupPtr))) { if (hr == E_ACCESSDENIED) writeErrorMsg(L"The caller does not have sufficient backup privileges or is not an administrator.", hr, errorMessage, errorBufferLen); @@ -80,19 +111,25 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, return false; } + ItemHolder pBackupComponents(pBackupPtr); if (FAILED(hr = pBackupComponents->InitializeForBackup())) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"InitializeForBackup\".", hr, errorMessage, errorBufferLen); return false; } + if (FAILED(hr = pBackupComponents->SetBackupState(false, false, VSS_BT_FULL))) + { + writeErrorMsg(L"Error calling \"SetBackupState\".", hr, errorMessage, errorBufferLen); + return false; + } + + IVssAsync* pWriteMetaData = NULL; if (FAILED(hr = pBackupComponents->GatherWriterMetadata( &pWriteMetaData ))) { //this can happen if XP-version of VSS is used on Windows Vista (which needs at least VSS-Server2003 build) - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"GatherWriterMetadata\".", hr, errorMessage, errorBufferLen); return false; } @@ -105,7 +142,6 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, pWriteMetaData->Release(); if (FAILED(hr)) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"ppWriteMetaData->Wait\".", hr, errorMessage, errorBufferLen); return false; } @@ -114,7 +150,6 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, VSS_ID snapshotSetId = {0}; if (FAILED(hr = pBackupComponents->StartSnapshotSet( &snapshotSetId ))) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"StartSnapshotSet\".", hr, errorMessage, errorBufferLen); return false; } @@ -123,24 +158,14 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, VSS_ID SnapShotId = {0}; if (FAILED(hr = pBackupComponents->AddToSnapshotSet(const_cast(volumeName), GUID_NULL, &SnapShotId))) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"AddToSnapshotSet\".", hr, errorMessage, errorBufferLen); return false; } - if (FAILED(hr = pBackupComponents->SetBackupState( false, false, VSS_BT_FULL ))) - { - releaseShadowCopy(pBackupComponents); - writeErrorMsg(L"Error calling \"SetBackupState\".", hr, errorMessage, errorBufferLen); - return false; - } - - IVssAsync* pPrepare = NULL; if (FAILED(hr = pBackupComponents->PrepareForBackup( &pPrepare ))) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"PrepareForBackup\".", hr, errorMessage, errorBufferLen); return false; } @@ -152,16 +177,14 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, pPrepare->Release(); if (FAILED(hr)) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"pPrepare->Wait\".", hr, errorMessage, errorBufferLen); return false; } IVssAsync* pDoShadowCopy = NULL; - if (FAILED(hr = pBackupComponents->DoSnapshotSet( &pDoShadowCopy ))) + if (FAILED(hr = pBackupComponents->DoSnapshotSet(&pDoShadowCopy))) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"DoSnapshotSet\".", hr, errorMessage, errorBufferLen); return false; } @@ -173,7 +196,6 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, pDoShadowCopy->Release(); if (FAILED(hr)) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"pPrepare->Wait\".", hr, errorMessage, errorBufferLen); return false; } @@ -181,7 +203,6 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, VSS_SNAPSHOT_PROP props; if (FAILED(hr = pBackupComponents->GetSnapshotProperties( SnapShotId, &props ))) { - releaseShadowCopy(pBackupComponents); writeErrorMsg(L"Error calling \"GetSnapshotProperties\".", hr, errorMessage, errorBufferLen); return false; } @@ -191,13 +212,13 @@ bool shadow::createShadowCopy(const wchar_t* volumeName, VssFreeSnapshotProperties(&props); - *backupHandle = pBackupComponents; + *backupHandle = pBackupComponents.release(); //release ownership return true; } -void shadow::releaseShadowCopy(void* backupHandle) +void Shadow::releaseShadowCopy(void* backupHandle) { if (backupHandle != NULL) static_cast(backupHandle)->Release(); -- cgit