diff --git a/src/hpfs/hpfs_mount.cpp b/src/hpfs/hpfs_mount.cpp index 98add6a3..9822e3e9 100644 --- a/src/hpfs/hpfs_mount.cpp +++ b/src/hpfs/hpfs_mount.cpp @@ -5,6 +5,7 @@ #include "../util/h32.hpp" #include "../sc/sc.hpp" #include "../crypto.hpp" +#include "../util/version.hpp" namespace hpfs { @@ -523,7 +524,7 @@ namespace hpfs return -1; } close(fd); - seq_no = st.st_size / (sizeof(uint64_t) + sizeof(util::h32)); + seq_no = (st.st_size - version::HPFS_VERSION_BYTES_LEN) / (sizeof(uint64_t) + sizeof(util::h32)); return 0; } @@ -551,7 +552,7 @@ namespace hpfs return -1; } - const off_t offset = ((seq_no - 1) * (sizeof(uint64_t) + sizeof(util::h32))) + sizeof(uint64_t); + const off_t offset = version::HPFS_VERSION_BYTES_LEN + ((seq_no - 1) * (sizeof(uint64_t) + sizeof(util::h32))) + sizeof(uint64_t); // If calculated offset is beyond our file size means, // Requested seq_no is invalid or we do not have that seq_no in our hpfs log file. if (offset >= st.st_size) diff --git a/src/util/version.cpp b/src/util/version.cpp index 35e1e9b2..cf56557e 100644 --- a/src/util/version.cpp +++ b/src/util/version.cpp @@ -34,7 +34,7 @@ namespace version if (end == std::string::npos) { - LOG_ERROR << "Invalid version " << version; + std::cerr << "Invalid version " << version << std::endl; return -1; } @@ -45,7 +45,7 @@ namespace version if (end == std::string::npos) { - LOG_ERROR << "Invalid version " << version; + std::cerr << "Invalid version " << version << std::endl; return -1; } diff --git a/src/util/version.hpp b/src/util/version.hpp index 3fbd8c06..6c619eab 100644 --- a/src/util/version.hpp +++ b/src/util/version.hpp @@ -18,6 +18,10 @@ namespace version // 2 bytes each for 3 version components. 2 bytes reserved. constexpr const size_t VERSION_BYTES_LEN = 8; + // Hpfs version header length. This is currently same length as hpcore version header. + // This value needs to be updated when hpfs version header length changes. + constexpr const size_t HPFS_VERSION_BYTES_LEN = 8; + // Binary representations of the versions. (populated during version init) extern uint8_t HP_VERSION_BYTES[VERSION_BYTES_LEN]; extern uint8_t LEDGER_VERSION_BYTES[VERSION_BYTES_LEN]; diff --git a/test/bin/hpfs b/test/bin/hpfs index d2396e16..06ec66cf 100755 Binary files a/test/bin/hpfs and b/test/bin/hpfs differ