Add a much-needed get_blocks_from_size function
This commit is contained in:
parent
e769cb45a7
commit
53d36be339
8
kernel/include/misc/utils.h
Normal file
8
kernel/include/misc/utils.h
Normal 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.
|
||||
}
|
@ -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 <string.h>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
6
kernel/src/misc/utils.cpp
Normal file
6
kernel/src/misc/utils.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user