MCPcopy Create free account
hub / github.com/ElementsProject/elements / Allocate

Method Allocate

src/flatfile.cpp:55–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_of_space)
56{
57 out_of_space = false;
58
59 unsigned int n_old_chunks = (pos.nPos + m_chunk_size - 1) / m_chunk_size;
60 unsigned int n_new_chunks = (pos.nPos + add_size + m_chunk_size - 1) / m_chunk_size;
61 if (n_new_chunks > n_old_chunks) {
62 size_t old_size = pos.nPos;
63 size_t new_size = n_new_chunks * m_chunk_size;
64 size_t inc_size = new_size - old_size;
65
66 if (CheckDiskSpace(m_dir, inc_size)) {
67 FILE *file = Open(pos);
68 if (file) {
69 LogPrint(BCLog::VALIDATION, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
70 AllocateFileRange(file, pos.nPos, inc_size);
71 fclose(file);
72 return inc_size;
73 }
74 } else {
75 out_of_space = true;
76 }
77 }
78 return 0;
79}
80
81bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize)
82{

Callers

nothing calls this directly

Calls 2

CheckDiskSpaceFunction · 0.85
AllocateFileRangeFunction · 0.85

Tested by

no test coverage detected