urbackup_backend/fsimageplugin/FSImageFactory.cpp
Martin 6447563c2e Merge remote-tracking branch 'urpc/next' into dev
Conflicts:
	.gitignore
	Interface/Database.h
	configure.ac_client
	configure.ac_server
	fileservplugin/CClientThread.cpp
	fileservplugin/CClientThread.h
	fileservplugin/FileServFactory.cpp
	fileservplugin/FileServFactory.h
	fileservplugin/IFileServFactory.h
	fsimageplugin/FSImageFactory.cpp
	fsimageplugin/FSImageFactory.h
	fsimageplugin/FileWrapper.cpp
	fsimageplugin/FileWrapper.h
	fsimageplugin/IFSImageFactory.h
	fsimageplugin/Makefile.am_client
	fsimageplugin/Makefile.am_server
	fsimageplugin/dllmain.cpp
	fsimageplugin/filesystem.cpp
	fsimageplugin/filesystem.h
	fsimageplugin/fs/ntfs.cpp
	fsimageplugin/fs/ntfs.h
	fsimageplugin/fs/ntfs_win.cpp
	fsimageplugin/fs/ntfs_win.h
	fsimageplugin/fs/unknown.cpp
	fsimageplugin/fs/unknown.h
	fsimageplugin/fsimageplugin.vcxproj.filters
	start_urbackup_client
	start_urbackup_server
	urbackupclient/ChangeJournalWatcher.cpp
	urbackupclient/ClientService.cpp
	urbackupclient/ClientServiceCMD.cpp
	urbackupclient/ImageThread.cpp
	urbackupclient/client.cpp
	urbackupclient/client.h
	urbackupclient/client_restore.cpp
	urbackupclient/clientdao.cpp
	urbackupclient/dllmain.cpp
	urbackupclient/win_sysvol.cpp
	urbackupclient/win_sysvol.h
	urbackupcommon/fileclient/FileClient.cpp
	urbackupcommon/fileclient/FileClientChunked.cpp
	urbackupcommon/os_functions.h
	urbackupcommon/os_functions_lin.cpp
	urbackupcommon/os_functions_win.cpp
	urbackupcommon/settingslist.cpp
	urbackupserver/ImageBackup.cpp
	urbackupserver/SQLiteFileCache.cpp
	urbackupserver/ServerDownloadThread.cpp
	urbackupserver/dao/ServerBackupDao.cpp
	urbackupserver/dao/ServerBackupDao.h
	urbackupserver/dllmain.cpp
	urbackupserver/doc/admin_guide.tex
	urbackupserver/server_channel.cpp
	urbackupserver/server_channel.h
	urbackupserver/server_cleanup.cpp
	urbackupserver/server_dir_links.cpp
	urbackupserver/server_get.cpp
	urbackupserver/server_hash.cpp
	urbackupserver/server_hash.h
	urbackupserver/server_settings.cpp
	urbackupserver/server_settings.h
	urbackupserver/server_update_stats.cpp
	urbackupserver/server_writer.cpp
	urbackupserver/serverinterface/backups.cpp
	urbackupserver/serverinterface/settings.cpp
	urbackupserver/serverinterface/usage.cpp
	urbackupserver/www/js/urbackup.js
	urbackupserver/www/templates.js
	urbackupserver/www/templates/settings_inv_row.htm
	urbackupserver/www/translations/urbackup.webinterface/ar_SA.po
2015-12-09 14:49:13 +01:00

186 lines
4.8 KiB
C++

/*************************************************************************
* UrBackup - Client/Server backup system
* Copyright (C) 2011-2015 Martin Raiber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "FSImageFactory.h"
#include "../Interface/Server.h"
#include "../Interface/File.h"
#include "fs/ntfs.h"
#ifdef _WIN32
#include "fs/ntfs_win.h"
#define FSNTFS FSNTFSWIN
#endif
#include "fs/unknown.h"
#include "vhdfile.h"
#include "../stringtools.h"
#ifdef _WIN32
#include <Windows.h>
#else
#include <errno.h>
#include "cowfile.h"
#endif
void PrintInfo(IFilesystem *fs)
{
Server->Log("FSINFO: blocksize="+nconvert(fs->getBlocksize())+" size="+nconvert(fs->getSize())+" has_error="+nconvert(fs->hasError())+" used_space="+nconvert(fs->calculateUsedSpace()), LL_DEBUG);
}
IFilesystem *FSImageFactory::createFilesystem(const std::wstring &pDev, bool read_ahead, bool background_priority, bool exclude_shadow_storage)
{
IFile *dev=Server->openFile(pDev, MODE_READ_DEVICE);
if(dev==NULL)
{
int last_error;
#ifdef _WIN32
last_error=GetLastError();
#else
last_error=errno;
#endif
Server->Log(L"Error opening device file ("+pDev+L") Errorcode: "+convert(last_error), LL_ERROR);
return NULL;
}
char buffer[1024];
_u32 rc=dev->Read(buffer, 1024);
if(rc!=1024)
{
Server->Log(L"Error reading data from device ("+pDev+L")", LL_ERROR);
return NULL;
}
Server->destroy(dev);
if(isNTFS(buffer) )
{
Server->Log(L"Filesystem type is ntfs ("+pDev+L")", LL_DEBUG);
FSNTFS *fs=new FSNTFS(pDev, read_ahead, background_priority);
/** NOT TESTED ENOUGH
if(exclude_shadow_storage && pDev.find(L"HarddiskVolumeShadowCopy")!=std::string::npos)
{
fs->excludeFiles(pDev+L"\\System Volume Information", L"{3808876b-c176-4e48-b7ae-04046e6cc752}");
fs->excludeFile(pDev+L"\\pagefile.sys");
}*/
/*
int64 idx=0;
while(idx<fs->getSize()/fs->getBlocksize())
{
std::string b1;
std::string b2;
int64 idx_start=idx;
for(size_t i=0;i<100;++i)
{
b1+=nconvert((int)fs->readBlock(idx, NULL));
b2+=nconvert((int)fs2->readBlock(idx, NULL));
++idx;
}
if(b1!=b2)
{
Server->Log(nconvert(idx_start)+" fs1: "+b1, LL_DEBUG);
Server->Log(nconvert(idx_start)+" fs2: "+b2, LL_DEBUG);
}
}*/
if(fs->hasError())
{
Server->Log("NTFS has error", LL_WARNING);
delete fs;
Server->Log("Unknown filesystem type", LL_DEBUG);
FSUnknown *fs2=new FSUnknown(pDev, read_ahead, background_priority);
if(fs2->hasError())
{
delete fs2;
return NULL;
}
PrintInfo(fs2);
return fs2;
}
PrintInfo(fs);
return fs;
}
else
{
Server->Log("Unknown filesystem type", LL_DEBUG);
FSUnknown *fs=new FSUnknown(pDev, read_ahead, background_priority);
if(fs->hasError())
{
delete fs;
return NULL;
}
PrintInfo(fs);
return fs;
}
}
bool FSImageFactory::isNTFS(char *buffer)
{
if(buffer[3]=='N' && buffer[4]=='T' && buffer[5]=='F' && buffer[6]=='S')
{
return true;
}
else
{
return false;
}
}
IVHDFile *FSImageFactory::createVHDFile(const std::wstring &fn, bool pRead_only, uint64 pDstsize,
unsigned int pBlocksize, bool fast_mode, ImageFormat format)
{
switch(format)
{
case ImageFormat_VHD:
case ImageFormat_CompressedVHD:
return new VHDFile(fn, pRead_only, pDstsize, pBlocksize, fast_mode, format!=ImageFormat_VHD);
case ImageFormat_RawCowFile:
#if !defined(_WIN32) && !defined(__APPLE__)
return new CowFile(fn, pRead_only, pDstsize);
#else
return NULL;
#endif
}
return NULL;
}
IVHDFile *FSImageFactory::createVHDFile(const std::wstring &fn, const std::wstring &parent_fn,
bool pRead_only, bool fast_mode, ImageFormat format)
{
switch(format)
{
case ImageFormat_VHD:
case ImageFormat_CompressedVHD:
return new VHDFile(fn, parent_fn, pRead_only, fast_mode, format!=ImageFormat_VHD);
case ImageFormat_RawCowFile:
#if !defined(_WIN32) && !defined(__APPLE__)
return new CowFile(fn, parent_fn, pRead_only);
#else
return NULL;
#endif
}
return NULL;
}
void FSImageFactory::destroyVHDFile(IVHDFile *vhd)
{
delete vhd;
}