summaryrefslogtreecommitdiff
path: root/Kernel/Devices/BlockDevice.h
diff options
context:
space:
mode:
authorPankaj Raghav <pankydev8@gmail.com>2022-01-29 13:03:55 +0530
committerIdan Horowitz <idan.horowitz@gmail.com>2022-01-29 17:41:06 +0200
commit0f010cee02b87aa0fedf032b222316af53f67ede (patch)
tree620746474c28e1aad1bf605a5d0737a8b0e86c48 /Kernel/Devices/BlockDevice.h
parent61027e530379fcdb202715ca3f9933252730c84e (diff)
downloadserenity-0f010cee02b87aa0fedf032b222316af53f67ede.zip
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.
Diffstat (limited to 'Kernel/Devices/BlockDevice.h')
-rw-r--r--Kernel/Devices/BlockDevice.h5
1 files changed, 5 insertions, 0 deletions
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 <AK/Math.h>
#include <AK/Weakable.h>
#include <Kernel/Devices/Device.h>
@@ -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 };
};
}