[ox/fs] Add Error return to FileStore compact
This commit is contained in:
parent
22378d0a9f
commit
2d2cd2bbb6
@ -130,7 +130,7 @@ class FileStoreTemplate {
|
||||
|
||||
bool valid() const;
|
||||
|
||||
void compact();
|
||||
ox::Error compact();
|
||||
|
||||
private:
|
||||
FileStoreData *fileStoreData() const;
|
||||
@ -247,7 +247,7 @@ Error FileStoreTemplate<size_t>::write(InodeId_t id, void *data, FsSize_t dataSi
|
||||
oxTrace("ox::fs::FileStoreTemplate::write") << "Attempting to write to inode" << id;
|
||||
auto existing = find(id);
|
||||
if (!canWrite(existing, dataSize)) {
|
||||
compact();
|
||||
oxReturnError(compact());
|
||||
existing = find(id);
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ Error FileStoreTemplate<size_t>::write(InodeId_t id, void *data, FsSize_t dataSi
|
||||
// if first malloc failed, compact and try again
|
||||
if (!dest.valid()) {
|
||||
oxTrace("ox::fs::FileStoreTemplate::write") << "Allocation failed, compacting";
|
||||
compact();
|
||||
oxReturnError(compact());
|
||||
dest = m_buffer->malloc(dataSize);
|
||||
}
|
||||
if (dest.valid()) {
|
||||
@ -413,7 +413,7 @@ const ptrarith::Ptr<uint8_t, std::size_t> FileStoreTemplate<size_t>::read(InodeI
|
||||
|
||||
template<typename size_t>
|
||||
ox::Error FileStoreTemplate<size_t>::resize() {
|
||||
compact();
|
||||
oxReturnError(compact());
|
||||
oxReturnError(m_buffer->setSize(size() - available()));
|
||||
oxTrace("ox::fs::FileStoreTemplate::resize") << "resize to:" << size() - available();
|
||||
oxTrace("ox::fs::FileStoreTemplate::resize") << "resized to:" << m_buffer->size();
|
||||
@ -491,15 +491,15 @@ ValErr<typename FileStoreTemplate<size_t>::InodeId_t> FileStoreTemplate<size_t>:
|
||||
}
|
||||
|
||||
template<typename size_t>
|
||||
void FileStoreTemplate<size_t>::compact() {
|
||||
ox::Error FileStoreTemplate<size_t>::compact() {
|
||||
auto isFirstItem = true;
|
||||
m_buffer->compact([this, &isFirstItem](uint64_t oldAddr, ItemPtr item) {
|
||||
return m_buffer->compact([this, &isFirstItem](uint64_t oldAddr, ItemPtr item) -> ox::Error {
|
||||
if (isFirstItem) {
|
||||
isFirstItem = false;
|
||||
return;
|
||||
return OxError(0);
|
||||
}
|
||||
if (!item.valid()) {
|
||||
return;
|
||||
return OxError(1);
|
||||
}
|
||||
oxTrace("ox::FileStoreTemplate::compact::moveItem")
|
||||
<< "Moving Item:" << item->id
|
||||
@ -520,6 +520,7 @@ void FileStoreTemplate<size_t>::compact() {
|
||||
parent->right = item;
|
||||
}
|
||||
}
|
||||
return OxError(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
7
deps/ox/src/ox/ptrarith/nodebuffer.hpp
vendored
7
deps/ox/src/ox/ptrarith/nodebuffer.hpp
vendored
@ -150,7 +150,7 @@ class __attribute__((packed)) NodeBuffer {
|
||||
size_t spaceNeeded(size_t size);
|
||||
|
||||
template<typename F>
|
||||
void compact(F cb = [](uint64_t, ItemPtr) {});
|
||||
ox::Error compact(F cb = [](uint64_t, ItemPtr) {});
|
||||
|
||||
void truncate();
|
||||
|
||||
@ -354,13 +354,13 @@ size_t NodeBuffer<size_t, Item>::spaceNeeded(size_t size) {
|
||||
|
||||
template<typename size_t, typename Item>
|
||||
template<typename F>
|
||||
void NodeBuffer<size_t, Item>::compact(F cb) {
|
||||
ox::Error NodeBuffer<size_t, Item>::compact(F cb) {
|
||||
auto src = firstItem();
|
||||
auto dest = ptr(sizeof(*this));
|
||||
while (src.valid() && dest.valid() && dest.offset() <= src.offset()) {
|
||||
// move node
|
||||
ox_memcpy(dest, src, src.size());
|
||||
cb(src, dest);
|
||||
oxReturnError(cb(src, dest));
|
||||
// update surrounding nodes
|
||||
auto prev = ptr(dest->prev);
|
||||
if (prev.valid()) {
|
||||
@ -374,6 +374,7 @@ void NodeBuffer<size_t, Item>::compact(F cb) {
|
||||
src = ptr(dest->next);
|
||||
dest = ptr(dest.offset() + dest.size());
|
||||
}
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
template<typename size_t, typename Item>
|
||||
|
Loading…
Reference in New Issue
Block a user