Ai
1 Star 0 Fork 0

wangcichen/urbackup_backend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
file.h 2.69 KB
一键复制 编辑 原始数据 按行查看 历史
Martin Raiber 提交于 2021-05-08 15:15 +08:00 . Improve memory file
#ifndef FILE_H
#define FILE_H
#include "Interface/File.h"
const int MODE_TEMP=4;
//#define MODE_STL //No 64bit
#ifdef _WIN32
# define MODE_WIN
#elif LINUX
# define MODE_LIN
#else
# define MODE_STL
# warning "using STL file access files>4GB are not supported"
#endif
#ifdef MODE_STL
# include <fstream>
#endif
#ifdef MODE_WIN
# include <windows.h>
# include "Interface/Mutex.h"
#endif
#ifdef MODE_LIN
#if !defined(_LARGEFILE64_SOURCE) && !defined(__APPLE__)
# define _LARGEFILE64_SOURCE
#endif
# include <fcntl.h>
# include <sys/stat.h>
# include <stdlib.h>
# include <unistd.h>
# define _unlink unlink
#if defined(__FreeBSD__) || defined(__APPLE__)
#define off64_t off_t
#endif
#endif
class File : public IFsFile
{
public:
File();
~File();
bool Open(std::string pfn, int mode=MODE_READ);
bool Open(void *handle, const std::string& pFilename);
bool OpenTemporaryFile(const std::string &tmpdir="", bool first_try=true);
std::string Read(_u32 tr, bool *has_error=NULL);
std::string Read(int64 spos, _u32 tr, bool *has_error = NULL);
_u32 Read(char* buffer, _u32 bsize, bool *has_error=NULL);
_u32 Read(int64 spos, char* buffer, _u32 bsize, bool *has_error = NULL);
_u32 Write(const std::string &tw, bool *has_error=NULL);
_u32 Write(int64 spos, const std::string &tw, bool *has_error = NULL);
_u32 Write(const char* buffer, _u32 bsize, bool *has_error=NULL);
_u32 Write(int64 spos, const char* buffer, _u32 bsize, bool *has_error = NULL);
bool Seek(_i64 spos);
_i64 Size(void);
_i64 RealSize();
void Close();
bool PunchHole( _i64 spos, _i64 size );
bool Sync();
bool Resize(int64 new_size, bool set_sparse=true);
void resetSparseExtentIter();
SSparseExtent nextSparseExtent();
std::vector<SFileExtent> getFileExtents(int64 starting_offset, int64 block_size, bool& more_data, unsigned int flags);
IFsFile::os_file_handle getOsHandle(bool release_handle = false);
IVdlVolCache* createVdlVolCache();
int64 getValidDataLength(IVdlVolCache* vol_cache);
#ifdef _WIN32
static void init_mutex();
static void destroy_mutex();
#endif
std::string getFilename(void);
private:
#ifdef MODE_STL
std::fstream fi;
#endif
#ifdef MODE_WIN
HANDLE hfile;
bool is_sparse;
#endif
#ifdef MODE_LIN
int fd;
#endif
std::string fn;
#ifdef _WIN32
class VdlVolCache : public IVdlVolCache
{
public:
~VdlVolCache();
std::string volfn;
HANDLE vol;
NTFS_VOLUME_DATA_BUFFER vol_data;
};
bool setSparse();
static size_t tmp_file_index;
static IMutex* index_mutex;
static std::string random_prefix;
bool more_extents;
std::vector<FILE_ALLOCATED_RANGE_BUFFER> res_extent_buffer;
size_t curr_extent;
int64 last_sparse_pos;
#else
off64_t last_sparse_pos;
#endif
};
bool DeleteFileInt(std::string pFilename);
#endif //FILE_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/wangcichen/urbackup_backend.git
git@gitee.com:wangcichen/urbackup_backend.git
wangcichen
urbackup_backend
urbackup_backend
dev

搜索帮助