 |
Bitcoin Core
21.99.0
P2P Digital Currency
|
Go to the documentation of this file.
14 m_dir(std::move(dir)),
16 m_chunk_size(chunk_size)
18 if (chunk_size == 0) {
19 throw std::invalid_argument(
"chunk_size must be positive");
39 fs::create_directories(path.parent_path());
41 if (!file && !read_only)
44 LogPrintf(
"Unable to open file %s\n", path.string());
47 if (pos.
nPos && fseek(file, pos.
nPos, SEEK_SET)) {
48 LogPrintf(
"Unable to seek to position %u of %s\n", pos.
nPos, path.string());
61 if (n_new_chunks > n_old_chunks) {
62 size_t old_size = pos.
nPos;
64 size_t inc_size = new_size - old_size;
67 FILE *file =
Open(pos);
85 return error(
"%s: failed to open file %d", __func__, pos.
nFile);
89 return error(
"%s: failed to truncate file %d", __func__, pos.
nFile);
93 return error(
"%s: failed to commit file %d", __func__, pos.
nFile);
FILE * fopen(const fs::path &p, const char *mode)
std::string ToString() const
const size_t m_chunk_size
size_t Allocate(const FlatFilePos &pos, size_t add_size, bool &out_of_space)
Allocate additional space in a file after the given starting position.
bool TruncateFile(FILE *file, unsigned int length)
FlatFileSeq(fs::path dir, const char *prefix, size_t chunk_size)
Constructor.
FILE * Open(const FlatFilePos &pos, bool read_only=false)
Open a handle to the file at the given position.
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
#define LogPrint(category,...)
fs::path FileName(const FlatFilePos &pos) const
Get the name of the file at the given position.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
const char *const m_prefix
bool error(const char *fmt, const Args &... args)
bool Flush(const FlatFilePos &pos, bool finalize=false)
Commit a file to disk, and optionally truncate off extra pre-allocated bytes if final.