From 0f010cee02b87aa0fedf032b222316af53f67ede Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Sat, 29 Jan 2022 13:03:55 +0530 Subject: [PATCH] Kernel: Add block_size_log helper to BlockDevice It is useful to have the log2 value of the block size while calculating index for an IO. --- Kernel/Devices/BlockDevice.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Kernel/Devices/BlockDevice.h b/Kernel/Devices/BlockDevice.h index a3c3197eb9..ecf544eaa9 100644 --- a/Kernel/Devices/BlockDevice.h +++ b/Kernel/Devices/BlockDevice.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -56,6 +57,7 @@ public: virtual ~BlockDevice() override; size_t block_size() const { return m_block_size; } + u8 block_size_log() const { return m_block_size_log; } virtual bool is_seekable() const override { return true; } bool read_block(u64 index, UserOrKernelBuffer&); @@ -70,12 +72,15 @@ protected: { // 512 is the minimum sector size in most block devices VERIFY(m_block_size >= 512); + VERIFY(is_power_of_two(m_block_size)); + m_block_size_log = AK::log2(m_block_size); } private: virtual bool is_block_device() const final { return true; } size_t m_block_size { 0 }; + u8 m_block_size_log { 0 }; }; }