From bd6336c629841c6db3a6ca53a936d629d34db53b Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:15:16 +0200 Subject: 4.1 --- shared/ShadowCopy/LockFile.cpp | 44 ------- shared/ShadowCopy/Shadow_2003.vcxproj | 240 --------------------------------- shared/ShadowCopy/Shadow_XP.vcxproj | 241 ---------------------------------- shared/ShadowCopy/dll_main.cpp | 25 ---- shared/ShadowCopy/shadow.cpp | 178 ------------------------- shared/ShadowCopy/shadow.h | 106 --------------- 6 files changed, 834 deletions(-) delete mode 100644 shared/ShadowCopy/LockFile.cpp delete mode 100644 shared/ShadowCopy/Shadow_2003.vcxproj delete mode 100644 shared/ShadowCopy/Shadow_XP.vcxproj delete mode 100644 shared/ShadowCopy/dll_main.cpp delete mode 100644 shared/ShadowCopy/shadow.cpp delete mode 100644 shared/ShadowCopy/shadow.h (limited to 'shared/ShadowCopy') diff --git a/shared/ShadowCopy/LockFile.cpp b/shared/ShadowCopy/LockFile.cpp deleted file mode 100644 index 7df3ec66..00000000 --- a/shared/ShadowCopy/LockFile.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * -// ************************************************************************** - - -#include -#include -#define WIN32_LEAN_AND_MEAN -#include "windows.h" - -int wmain(int argc, wchar_t* argv[]) -{ - if (argc <= 1) - { - std::wcout << "Please enter the filename to be locked as %1 parameter!" << "\n\n"; - system("pause"); - return -1; - } - std::wstring filename = argv[1]; - - //obtain exclusive lock on test file - HANDLE hFile = ::CreateFile(filename.c_str(), - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, - NULL); - if (hFile == INVALID_HANDLE_VALUE) - { - std::wcout << "Error obtaining exclusive lock on test file: " << filename << "\n\n"; - system("pause"); - return -1; - } - - std::wcout << "File " << filename << " is locked! Press a key to unlock." << "\n\n"; - system("pause"); - - ::CloseHandle(hFile); - return 0; -} - diff --git a/shared/ShadowCopy/Shadow_2003.vcxproj b/shared/ShadowCopy/Shadow_2003.vcxproj deleted file mode 100644 index 710b65bf..00000000 --- a/shared/ShadowCopy/Shadow_2003.vcxproj +++ /dev/null @@ -1,240 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - Server2003 - {2F2994D6-FB89-4BAA-A5DF-03BAF7337FF2} - ShadowDll - Win32Proj - - - - DynamicLibrary - Unicode - true - false - Windows7.1SDK - - - DynamicLibrary - Unicode - Windows7.1SDK - - - DynamicLibrary - Unicode - true - Windows7.1SDK - - - DynamicLibrary - Unicode - Windows7.1SDK - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - OBJ\ - OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ - false - OBJ\ - 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.vcxproj b/shared/ShadowCopy/Shadow_XP.vcxproj deleted file mode 100644 index 6211afd5..00000000 --- a/shared/ShadowCopy/Shadow_XP.vcxproj +++ /dev/null @@ -1,241 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - XP - {70394AEF-5897-4911-AFA1-82EAF0581EFA} - ShadowDll - Win32Proj - - - - DynamicLibrary - Unicode - true - Windows7.1SDK - - - DynamicLibrary - Unicode - Windows7.1SDK - - - DynamicLibrary - Unicode - true - Windows7.1SDK - - - DynamicLibrary - Unicode - Windows7.1SDK - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - OBJ\ - OBJ\$(ProjectName)_$(Configuration)_$(Platform)\ - false - OBJ\ - 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/dll_main.cpp b/shared/ShadowCopy/dll_main.cpp deleted file mode 100644 index 3805c99d..00000000 --- a/shared/ShadowCopy/dll_main.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * -// ************************************************************************** - - -#define WIN32_LEAN_AND_MEAN -#include - -//optional: add init/teardown logic here -BOOL APIENTRY DllMain(HINSTANCE hinstDLL, - DWORD fdwReason, - LPVOID lpvReserved) -{ - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - case DLL_PROCESS_DETACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - break; - } - return TRUE; -} diff --git a/shared/ShadowCopy/shadow.cpp b/shared/ShadowCopy/shadow.cpp deleted file mode 100644 index 8b7b9971..00000000 --- a/shared/ShadowCopy/shadow.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * -// ************************************************************************** - -#include "shadow.h" -#include -#include -#include -#include "../com_ptr.h" -#include "../com_error.h" -#include "../c_dll.h" - -#define WIN32_LEAN_AND_MEAN -#include "windows.h" - -#ifdef USE_SHADOW_XP -#include "xp/inc/vss.h" -#include "xp/inc/vswriter.h" -#include "xp/inc/vsbackup.h" - -#elif defined USE_SHADOW_2003 -#include "Server 2003/inc/vss.h" -#include "Server 2003/inc/vswriter.h" -#include "Server 2003/inc/vsbackup.h" -#else -adapt! -#endif - -using namespace c_dll; - - -namespace -{ -typedef HandleProvider > HandleShadowMap; - -void writeErrorMsg(const wchar_t* input, HRESULT hr, wchar_t* output, unsigned int outputBufferLen) -{ - writeString(util::generateErrorMsg(input, hr).c_str(), output, outputBufferLen); -} -} - - -bool shadow::createShadowCopy(const wchar_t* volumeName, - wchar_t* shadowVolName, - unsigned int shadowBufferLen, - ShadowHandle* handle, - wchar_t* errorMessage, - unsigned int errorBufferLen) -{ - using util::ComPtr; - using util::generateErrorMsg; - - //MessageBox(0, L"backup err", L"", 0); */ - *handle = 0; - HRESULT hr = NULL; - - ComPtr backupComp; - if (FAILED(hr = CreateVssBackupComponents(backupComp.init()))) - { - if (hr == E_ACCESSDENIED) - writeErrorMsg(L"The caller does not have sufficient backup privileges or is not an administrator.", hr, errorMessage, errorBufferLen); - else - writeErrorMsg(L"Error calling \"CreateVssBackupComponents\".", hr, errorMessage, errorBufferLen); - return false; - } - - if (FAILED(hr = backupComp->InitializeForBackup())) - { - writeErrorMsg(L"Error calling \"InitializeForBackup\".", hr, errorMessage, errorBufferLen); - return false; - } - - if (FAILED(hr = backupComp->SetBackupState(false, false, VSS_BT_FULL))) - { - writeErrorMsg(L"Error calling \"SetBackupState\".", hr, errorMessage, errorBufferLen); - return false; - } - - ComPtr vssWriters; - if (FAILED(hr = backupComp->GatherWriterMetadata(vssWriters.init()))) - { - //this can happen if XP-version of VSS is used on Windows Vista (which needs at least VSS-Server2003 build) - writeErrorMsg(L"Error calling \"GatherWriterMetadata\".", hr, errorMessage, errorBufferLen); - return false; - } - - //wait for shadow copy writers to complete - if (FAILED(hr = vssWriters->Wait())) - { - writeErrorMsg(L"Error calling \"vssWriters->Wait\".", hr, errorMessage, errorBufferLen); - return false; - } - - vssWriters->QueryStatus(&hr, NULL); //check if the async operation succeeded... - if (FAILED(hr)) - { - writeErrorMsg(L"Error calling \"vssWriters->QueryStatus\".", hr, errorMessage, errorBufferLen); - return false; - } - - VSS_ID snapshotSetId = {0}; - if (FAILED(hr = backupComp->StartSnapshotSet(&snapshotSetId))) - { - writeErrorMsg(L"Error calling \"StartSnapshotSet\".", hr, errorMessage, errorBufferLen); - return false; - } - - VSS_ID SnapShotId = {0}; - if (FAILED(hr = backupComp->AddToSnapshotSet(const_cast(volumeName), GUID_NULL, &SnapShotId))) - { - writeErrorMsg(L"Error calling \"AddToSnapshotSet\".", hr, errorMessage, errorBufferLen); - return false; - } - - ComPtr vssPrepare; - if (FAILED(hr = backupComp->PrepareForBackup(vssPrepare.init()))) - { - writeErrorMsg(L"Error calling \"PrepareForBackup\".", hr, errorMessage, errorBufferLen); - return false; - } - - if (FAILED(hr = vssPrepare->Wait())) - { - writeErrorMsg(L"Error calling \"vssPrepare->Wait\".", hr, errorMessage, errorBufferLen); - return false; - } - - vssPrepare->QueryStatus(&hr, NULL); //check if the async operation succeeded... - if (FAILED(hr)) - { - writeErrorMsg(L"Error calling \"vssPrepare->QueryStatus\".", hr, errorMessage, errorBufferLen); - return false; - } - - ComPtr vssDoShadowCopy; - if (FAILED(hr = backupComp->DoSnapshotSet(vssDoShadowCopy.init()))) - { - writeErrorMsg(L"Error calling \"DoSnapshotSet\".", hr, errorMessage, errorBufferLen); - return false; - } - - if (FAILED(hr = vssDoShadowCopy->Wait())) - { - writeErrorMsg(L"Error calling \"vssDoShadowCopy->Wait\".", hr, errorMessage, errorBufferLen); - return false; - } - - vssDoShadowCopy->QueryStatus(&hr, NULL); //check if the async operation succeeded... - if (FAILED(hr)) - { - writeErrorMsg(L"Error calling \"vssDoShadowCopy->QueryStatus\".", hr, errorMessage, errorBufferLen); - return false; - } - - VSS_SNAPSHOT_PROP props; - if (FAILED(hr = backupComp->GetSnapshotProperties(SnapShotId, &props))) - { - writeErrorMsg(L"Error calling \"GetSnapshotProperties\".", hr, errorMessage, errorBufferLen); - return false; - } - - //finally: write volume name of newly created shadow copy - writeString(props.m_pwszSnapshotDeviceObject, shadowVolName, shadowBufferLen); - - VssFreeSnapshotProperties(&props); - - *handle = HandleShadowMap::instance().insert(backupComp); - - return true; -} - - -void shadow::releaseShadowCopy(ShadowHandle handle) -{ - HandleShadowMap::instance().remove(handle); -} diff --git a/shared/ShadowCopy/shadow.h b/shared/ShadowCopy/shadow.h deleted file mode 100644 index 8721b906..00000000 --- a/shared/ShadowCopy/shadow.h +++ /dev/null @@ -1,106 +0,0 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * -// ************************************************************************** - -#ifndef SHADOWCOPY_H -#define SHADOWCOPY_H - -#ifdef SHADOWDLL_EXPORTS -#define SHADOWDLL_API extern "C" __declspec(dllexport) -#else -#define SHADOWDLL_API extern "C" __declspec(dllimport) -#endif - -#include "../build_info.h" - - -namespace shadow -{ -/*-------------- - |declarations| - --------------*/ - -//COM needs to be initialized before calling any of these functions! CoInitializeEx/CoUninitialize - -typedef size_t ShadowHandle; - -//volumeName must end with "\", while shadowVolName does not end with "\" -SHADOWDLL_API -bool createShadowCopy(const wchar_t* volumeName, //[in] - wchar_t* shadowVolName, //[out] - unsigned int shadowBufferLen, //[in] - ShadowHandle* handle, //[out] - wchar_t* errorMessage, //[out] - unsigned int errorBufferLen); //[in] - - -//don't forget to release the backupHandle after shadow copy is not needed anymore! -SHADOWDLL_API -void releaseShadowCopy(ShadowHandle handle); - - -//########################################################################################## - - -/*---------- - |typedefs| - ----------*/ -typedef bool (*CreateShadowCopyFct)(const wchar_t* volumeName, - wchar_t* shadowVolName, - unsigned int shadowBufferLen, - ShadowHandle* handle, - wchar_t* errorMessage, - unsigned int errorBufferLen); - -typedef void (*ReleaseShadowCopyFct)(ShadowHandle handle); - -/*-------------- - |symbol names| - --------------*/ -//(use const pointers to ensure internal linkage) -const char createShadowCopyFctName[] = "createShadowCopy"; -const char releaseShadowCopyFctName[] = "releaseShadowCopy"; - -/*--------------- - |library names| - ---------------*/ -namespace impl -{ -bool newerThanXP() -{ - OSVERSIONINFO osvi = {}; - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - if (::GetVersionEx(&osvi)) - return osvi.dwMajorVersion > 5 || - (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion > 1) ; - //XP has majorVersion == 5, minorVersion == 1 - //Server 2003 has majorVersion == 5, minorVersion == 2 - //version overview: http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx - return false; -} -} - -inline -const wchar_t* getDllName() -{ - /* - distinguish a bunch of VSS builds: we use XP and Server 2003 implementations... - VSS version and compatibility overview: http://msdn.microsoft.com/en-us/library/aa384627(VS.85).aspx - */ - return impl::newerThanXP() ? - (util::is64BitBuild ? - L"Shadow_Server2003_x64.dll" : - L"Shadow_Server2003_Win32.dll") : - - (util::is64BitBuild ? - L"Shadow_XP_x64.dll" : - L"Shadow_XP_Win32.dll"); -} -} - - - -#endif //SHADOWCOPY_H -- cgit