|
|
@ -1918,12 +1918,16 @@ bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeigh |
|
|
|
unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
|
|
|
unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
|
|
|
unsigned int nNewChunks = (infoLastBlockFile.nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
|
|
|
unsigned int nNewChunks = (infoLastBlockFile.nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; |
|
|
|
if (nNewChunks > nOldChunks) { |
|
|
|
if (nNewChunks > nOldChunks) { |
|
|
|
FILE *file = OpenBlockFile(pos); |
|
|
|
if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos)) { |
|
|
|
if (file) { |
|
|
|
FILE *file = OpenBlockFile(pos); |
|
|
|
printf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); |
|
|
|
if (file) { |
|
|
|
AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos); |
|
|
|
printf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile); |
|
|
|
fclose(file); |
|
|
|
AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos); |
|
|
|
|
|
|
|
fclose(file); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return error("FindBlockPos() : out of disk space"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1960,12 +1964,16 @@ bool FindUndoPos(int nFile, CDiskBlockPos &pos, unsigned int nAddSize) |
|
|
|
unsigned int nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; |
|
|
|
unsigned int nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; |
|
|
|
unsigned int nNewChunks = (nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; |
|
|
|
unsigned int nNewChunks = (nNewSize + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; |
|
|
|
if (nNewChunks > nOldChunks) { |
|
|
|
if (nNewChunks > nOldChunks) { |
|
|
|
FILE *file = OpenUndoFile(pos); |
|
|
|
if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos)) { |
|
|
|
if (file) { |
|
|
|
FILE *file = OpenUndoFile(pos); |
|
|
|
printf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); |
|
|
|
if (file) { |
|
|
|
AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos); |
|
|
|
printf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile); |
|
|
|
fclose(file); |
|
|
|
AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos); |
|
|
|
|
|
|
|
fclose(file); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return error("FindUndoPos() : out of disk space"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -2090,12 +2098,8 @@ bool CBlock::AcceptBlock(CDiskBlockPos *dbp) |
|
|
|
// Write block to history file
|
|
|
|
// Write block to history file
|
|
|
|
unsigned int nBlockSize = ::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION); |
|
|
|
unsigned int nBlockSize = ::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION); |
|
|
|
CDiskBlockPos blockPos; |
|
|
|
CDiskBlockPos blockPos; |
|
|
|
if (dbp == NULL) { |
|
|
|
if (dbp != NULL) |
|
|
|
if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION))) |
|
|
|
|
|
|
|
return error("AcceptBlock() : out of disk space"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
blockPos = *dbp; |
|
|
|
blockPos = *dbp; |
|
|
|
} |
|
|
|
|
|
|
|
if (!FindBlockPos(blockPos, nBlockSize+8, nHeight, nTime, dbp != NULL)) |
|
|
|
if (!FindBlockPos(blockPos, nBlockSize+8, nHeight, nTime, dbp != NULL)) |
|
|
|
return error("AcceptBlock() : FindBlockPos failed"); |
|
|
|
return error("AcceptBlock() : FindBlockPos failed"); |
|
|
|
if (dbp == NULL) |
|
|
|
if (dbp == NULL) |
|
|
|