diff options
author | madmaxoft <github@xoft.cz> | 2014-02-13 12:48:22 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-02-13 16:54:39 +0100 |
commit | cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a (patch) | |
tree | 22a1dd2465a4587bef25f50973da6863d8c1dcea /Tools/MCADefrag/MCADefrag.cpp | |
parent | MCADefrag: Initial implementation. (diff) | |
download | cuberite-cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a.tar cuberite-cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a.tar.gz cuberite-cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a.tar.bz2 cuberite-cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a.tar.lz cuberite-cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a.tar.xz cuberite-cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a.tar.zst cuberite-cd658e02e8dcb7503d8aa5d75c314dcddb1ca11a.zip |
Diffstat (limited to 'Tools/MCADefrag/MCADefrag.cpp')
-rw-r--r-- | Tools/MCADefrag/MCADefrag.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Tools/MCADefrag/MCADefrag.cpp b/Tools/MCADefrag/MCADefrag.cpp index 2f24469c9..59a67e45d 100644 --- a/Tools/MCADefrag/MCADefrag.cpp +++ b/Tools/MCADefrag/MCADefrag.cpp @@ -11,6 +11,13 @@ +// An array of 4096 zero bytes, used for writing the padding +static const Byte g_Zeroes[4096] = {0}; + + + + + int main(int argc, char ** argv) { new cMCLogger(Printf("Defrag_%08x.log", time(NULL))); @@ -275,7 +282,7 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw) a_LocationRaw[0] = m_CurrentSectorOut >> 16; a_LocationRaw[1] = (m_CurrentSectorOut >> 8) & 0xff; a_LocationRaw[2] = m_CurrentSectorOut & 0xff; - a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) - 1) / (4 KiB); + a_LocationRaw[3] = (m_CompressedChunkDataSize + (4 KiB) + 3) / (4 KiB); // +3 because the m_CompressedChunkDataSize doesn't include the exact-length // Write the data length: Byte Buf[4]; @@ -295,6 +302,17 @@ bool cMCADefrag::cThread::WriteChunk(cFile & a_File, Byte * a_LocationRaw) LOGWARNING("Failed to write chunk data!"); return false; } + + // Pad onto the next sector: + int NumPadding = a_LocationRaw[3] * 4096 - (m_CompressedChunkDataSize + 4); + ASSERT(NumPadding >= 0); + if ((NumPadding > 0) && (a_File.Write(g_Zeroes, NumPadding) != NumPadding)) + { + LOGWARNING("Failed to write padding"); + return false; + } + + m_CurrentSectorOut += a_LocationRaw[3]; return true; } |