23#include "pedigree/kernel/LockGuard.h"
24#include "pedigree/kernel/TargetInfo.h"
25#include "pedigree/kernel/machine/Disk.h"
26#include "pedigree/kernel/process/Mutex.h"
27#include "pedigree/kernel/processor/types.h"
28#include "pedigree/kernel/utilities/StaticString.h"
29#include "pedigree/kernel/utilities/String.h"
43 str.assign(str2, str2.length());
49 str2 +=
" partition at 0x";
50 str2.append(m_Start, 16);
52 str2.append(m_Start + m_Length, 16);
53 str.assign(str2, str2.length());
57 if (!containsCachePage(location))
62 ensureAligned(pParent);
69 const uint64_t remaining = m_Length - location;
70 return remaining < view.size() ? view.first(
static_cast<size_t>(remaining)) : view;
73 bool zero(uint64_t location,
size_t length)
override {
74 if (!containsRange(location, length))
77 ensureAligned(parent);
78 return parent->zero(m_Start + location, length);
82 if (!containsRange(location, 1))
85 ensureAligned(parent);
86 auto view = parent->readView(m_Start + location);
87 if (view && m_Length - location < view.size())
88 view.truncate(
static_cast<size_t>(m_Length - location));
93 if (!containsRange(location, 1))
96 ensureAligned(parent);
97 auto view = parent->writeView(m_Start + location);
98 if (view && m_Length - location < view.size())
99 view.truncate(
static_cast<size_t>(m_Length - location));
103 virtual void write(uint64_t location)
override {
104 if (!containsCachePage(location))
109 ensureAligned(pParent);
111 pParent->
write(location + m_Start);
114 virtual void flush(uint64_t location)
override {
115 if (!containsCachePage(location))
120 ensureAligned(pParent);
122 pParent->
flush(location + m_Start);
126 if (!containsCachePage(location))
131 ensureAligned(pParent);
136 virtual bool sync(uint64_t location,
bool async)
override {
137 if (!containsCachePage(location))
141 ensureAligned(parent);
142 return parent->
sync(location + m_Start, async);
147 bool readInto(uint64_t location,
void* buffer,
size_t length)
override;
148 bool readIntoBatch(ReadBuffer* buffers,
size_t count)
override;
149 bool writeFrom(uint64_t location,
const void* buffer,
size_t length)
override;
155 Disk* physicalDisk()
override {
157 return parent ? parent->physicalDisk() :
nullptr;
174 virtual bool pin(uint64_t location)
override {
175 if (!containsCachePage(location))
178 ensureAligned(pParent);
179 return pParent->
pin(location + m_Start);
182 virtual void unpin(uint64_t location)
override {
183 if (!containsCachePage(location))
186 pParent->
unpin(location + m_Start);
202 void setPartitionIdentity(
const String& uuid,
const String& label) {
209 return uuid.length() != 0;
212 bool getPartitionLabel(
String& label)
const override {
214 return label.length() != 0;
218 bool containsRange(uint64_t location,
size_t length)
const;
220 bool containsCachePage(uint64_t location)
const {
221 if (location >= m_Length) {
226 const uint64_t pageLocation = location - (location % pageSize);
227 return pageSize <= (m_Length - pageLocation);
230 void ensureAligned(
Disk* pParent) {
235 pParent->
align(m_Start);
245 Mutex m_AlignmentLock;
Device * getParent() const
virtual bool sync(uint64_t location, bool async)
virtual void align(uint64_t location)
Sets the page boundary alignment after a specific location on the disk.
virtual BufferView read(uint64_t location)
virtual void unpin(uint64_t location)=0
virtual void write(uint64_t location)
virtual void flush(uint64_t location)
Flush a cached page to disk.
virtual size_t getNativeBlockSize() const
virtual MUST_USE_RESULT bool pin(uint64_t location)=0
Pins a cache page.
virtual size_t getBlockSize() const
Gets the preferred I/O extent of the disk.
virtual MUST_USE_RESULT bool retireCachePage(uint64_t location)
virtual void unpin(uint64_t location) override
DiskReadView readView(uint64_t location) override
virtual void dump(String &str) override
virtual void write(uint64_t location) override
const String & getPartitionType() const
uint64_t getLength() const
MUST_USE_RESULT bool syncPages(const uint64_t *locations, size_t count) override
virtual void getName(String &str) override
bool writeFromBatch(WriteBuffer *buffers, size_t count) override
size_t getNativeBlockSize() const override
bool readIntoBatch(ReadBuffer *buffers, size_t count) override
virtual bool pin(uint64_t location) override
Pins a cache page.
virtual MUST_USE_RESULT bool retireCachePage(uint64_t location) override
virtual size_t getSize() const override
Gets the size of the disk.
virtual MUST_USE_RESULT bool syncAll() override
virtual void flush(uint64_t location) override
Flush a cached page to disk.
bool readInto(uint64_t location, void *buffer, size_t length) override
bool zero(uint64_t location, size_t length) override
virtual size_t getBlockSize() const override
Gets the preferred I/O extent of the disk.
bool getPartitionUuid(String &uuid) const override
virtual BufferView read(uint64_t location) override
virtual bool sync(uint64_t location, bool async) override
static constexpr size_t getPageSize() noexcept