From 53d36be339e206a3b1dafd2f015a9cbb79c00a86 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 1 Oct 2022 12:13:38 +0200 Subject: [PATCH] Add a much-needed get_blocks_from_size function --- kernel/include/misc/utils.h | 8 ++++++++ kernel/src/init/InitRD.cpp | 3 ++- kernel/src/misc/utils.cpp | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 kernel/include/misc/utils.h create mode 100644 kernel/src/misc/utils.cpp diff --git a/kernel/include/misc/utils.h b/kernel/include/misc/utils.h new file mode 100644 index 00000000..a2ecab57 --- /dev/null +++ b/kernel/include/misc/utils.h @@ -0,0 +1,8 @@ +#pragma once +#include + +namespace Utilities +{ + uint64_t get_blocks_from_size(uint64_t blocksize, + uint64_t size); // Returns how many blocks of size blocksize does size occupy. +} \ No newline at end of file diff --git a/kernel/src/init/InitRD.cpp b/kernel/src/init/InitRD.cpp index b66f7056..125fd5a9 100644 --- a/kernel/src/init/InitRD.cpp +++ b/kernel/src/init/InitRD.cpp @@ -5,6 +5,7 @@ #include "io/Serial.h" #include "log/Log.h" #include "memory/MemoryManager.h" +#include "misc/utils.h" #include "std/stdlib.h" #include @@ -56,7 +57,7 @@ InitRD::File InitRD::get_file(TarHeader* header) multiplier *= 8; } result.addr = (void*)((uint64_t)header + TAR_BLOCKSIZE); - result.size_in_blocks = (result.size + (TAR_BLOCKSIZE - 1)) / TAR_BLOCKSIZE; + result.size_in_blocks = Utilities::get_blocks_from_size(TAR_BLOCKSIZE, result.size); return result; } diff --git a/kernel/src/misc/utils.cpp b/kernel/src/misc/utils.cpp new file mode 100644 index 00000000..528d5e38 --- /dev/null +++ b/kernel/src/misc/utils.cpp @@ -0,0 +1,6 @@ +#include "misc/utils.h" + +uint64_t Utilities::get_blocks_from_size(uint64_t blocksize, uint64_t size) +{ + return (size + (blocksize - 1)) / blocksize; +} \ No newline at end of file