Add a much-needed get_blocks_from_size function

This commit is contained in:
apio 2022-10-01 12:13:38 +02:00
parent e769cb45a7
commit 53d36be339
3 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,8 @@
#pragma once
#include <stdint.h>
namespace Utilities
{
uint64_t get_blocks_from_size(uint64_t blocksize,
uint64_t size); // Returns how many blocks of size blocksize does size occupy.
}

View File

@ -5,6 +5,7 @@
#include "io/Serial.h" #include "io/Serial.h"
#include "log/Log.h" #include "log/Log.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "misc/utils.h"
#include "std/stdlib.h" #include "std/stdlib.h"
#include <string.h> #include <string.h>
@ -56,7 +57,7 @@ InitRD::File InitRD::get_file(TarHeader* header)
multiplier *= 8; multiplier *= 8;
} }
result.addr = (void*)((uint64_t)header + TAR_BLOCKSIZE); 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; return result;
} }

View File

@ -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;
}