mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
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.
This commit is contained in:
parent
61027e5303
commit
0f010cee02
Notes:
sideshowbarker
2024-07-17 20:02:04 +09:00
Author: https://github.com/Panky-codes
Commit: 0f010cee02
Pull-request: https://github.com/SerenityOS/serenity/pull/12198
Reviewed-by: https://github.com/IdanHo
1 changed files with 5 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Math.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
#include <Kernel/Devices/Device.h>
|
#include <Kernel/Devices/Device.h>
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ public:
|
||||||
virtual ~BlockDevice() override;
|
virtual ~BlockDevice() override;
|
||||||
|
|
||||||
size_t block_size() const { return m_block_size; }
|
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; }
|
virtual bool is_seekable() const override { return true; }
|
||||||
|
|
||||||
bool read_block(u64 index, UserOrKernelBuffer&);
|
bool read_block(u64 index, UserOrKernelBuffer&);
|
||||||
|
@ -70,12 +72,15 @@ protected:
|
||||||
{
|
{
|
||||||
// 512 is the minimum sector size in most block devices
|
// 512 is the minimum sector size in most block devices
|
||||||
VERIFY(m_block_size >= 512);
|
VERIFY(m_block_size >= 512);
|
||||||
|
VERIFY(is_power_of_two(m_block_size));
|
||||||
|
m_block_size_log = AK::log2(m_block_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool is_block_device() const final { return true; }
|
virtual bool is_block_device() const final { return true; }
|
||||||
|
|
||||||
size_t m_block_size { 0 };
|
size_t m_block_size { 0 };
|
||||||
|
u8 m_block_size_log { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue