21#include "pedigree/kernel/processor/types.h"
23Partition::Partition(
const String& type, uint64_t start, uint64_t length)
31 setSpecificType(
String(
"partition"));
34Partition::~Partition() {}
36bool Partition::containsRange(uint64_t location,
size_t length)
const {
38 if (!parent || location > m_Length || length > m_Length - location ||
39 location > ~uint64_t{0} - m_Start)
41 const uint64_t translated = m_Start + location;
42 return translated <= parent->getSize() && length <= parent->getSize() - translated;
46 if (!containsRange(location, length))
49 ensureAligned(parent);
50 return parent->readInto(m_Start + location, buffer, length);
54 if (count > MaxReadBuffers || (count && !buffers))
56 for (
size_t i = 0; i < count; ++i)
57 buffers[i].complete =
false;
61 for (
size_t i = 0; i < count; ++i) {
62 if (!containsRange(buffers[i].location, buffers[i].length))
64 translated[i] = buffers[i];
65 translated[i].location += m_Start;
68 ensureAligned(parent);
69 const bool success = parent->readIntoBatch(translated, count);
70 for (
size_t i = 0; i < count; ++i)
71 buffers[i].complete = translated[i].complete;
75bool Partition::writeFrom(uint64_t location,
const void* buffer,
size_t length) {
76 if (!containsRange(location, length))
79 ensureAligned(parent);
80 return parent->writeFrom(m_Start + location, buffer, length);
84 if (count > MaxWriteBuffers || (count && !buffers))
87 for (
size_t i = 0; i < count; ++i)
88 buffers[i].complete =
false;
89 for (
size_t i = 0; i < count; ++i) {
90 if (!containsRange(buffers[i].location, buffers[i].length))
92 translated[i] = buffers[i];
93 translated[i].location += m_Start;
98 ensureAligned(parent);
99 const bool success = parent->writeFromBatch(translated, count);
100 for (
size_t i = 0; i < count; ++i)
101 buffers[i].complete = translated[i].complete;
107 return parent && parent->
syncData();
111 if (count > MaxSyncPages || (count && !locations))
118 uint64_t translated[MaxSyncPages];
119 for (
size_t i = 0; i < count; ++i) {
120 if (!containsCachePage(locations[i]) || locations[i] > ~uint64_t(0) - m_Start)
122 translated[i] = locations[i] + m_Start;
123 if (translated[i] >= parent->
getSize())
126 ensureAligned(parent);
127 return parent->
syncPages(translated, count);
133 return parent && parent->
syncAll();
Device * getParent() const
virtual size_t getSize() const
Gets the size of the disk.
virtual MUST_USE_RESULT bool syncPages(const uint64_t *locations, size_t count)
virtual MUST_USE_RESULT bool syncData()
virtual MUST_USE_RESULT bool syncAll()
MUST_USE_RESULT bool syncPages(const uint64_t *locations, size_t count) override
bool writeFromBatch(WriteBuffer *buffers, size_t count) override
bool readIntoBatch(ReadBuffer *buffers, size_t count) override
virtual MUST_USE_RESULT bool syncAll() override
bool readInto(uint64_t location, void *buffer, size_t length) override