[ox/fs] Cleanup
This commit is contained in:
parent
6eec25e4c0
commit
423f575386
20
deps/ox/src/ox/fs/filesystem2/directory.hpp
vendored
20
deps/ox/src/ox/fs/filesystem2/directory.hpp
vendored
@ -21,7 +21,7 @@ struct __attribute__((packed)) DirectoryEntry {
|
|||||||
struct __attribute__((packed)) DirectoryEntryData {
|
struct __attribute__((packed)) DirectoryEntryData {
|
||||||
// DirectoryEntry fields
|
// DirectoryEntry fields
|
||||||
LittleEndian<InodeId_t> inode = 0;
|
LittleEndian<InodeId_t> inode = 0;
|
||||||
BString<MaxFileNameLength> name;
|
char name[MaxFileNameLength];
|
||||||
};
|
};
|
||||||
|
|
||||||
// NodeBuffer fields
|
// NodeBuffer fields
|
||||||
@ -30,11 +30,11 @@ struct __attribute__((packed)) DirectoryEntry {
|
|||||||
|
|
||||||
DirectoryEntry() = default;
|
DirectoryEntry() = default;
|
||||||
|
|
||||||
explicit DirectoryEntry(InodeId_t inode, const char *name) {
|
DirectoryEntry(InodeId_t inode, const char *name) {
|
||||||
auto d = data();
|
auto d = data();
|
||||||
if (d.valid()) {
|
if (d.valid()) {
|
||||||
d->inode = inode;
|
d->inode = inode;
|
||||||
d->name = name;
|
ox_strncpy(d->name, name, MaxFileNameLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,17 +42,13 @@ struct __attribute__((packed)) DirectoryEntry {
|
|||||||
return ptrarith::Ptr<DirectoryEntryData, InodeId_t>(this, this->fullSize(), sizeof(*this), this->size());
|
return ptrarith::Ptr<DirectoryEntryData, InodeId_t>(this, this->fullSize(), sizeof(*this), this->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
const ptrarith::Ptr<DirectoryEntryData, InodeId_t> data() const {
|
|
||||||
return ptrarith::Ptr<DirectoryEntryData, InodeId_t>(const_cast<DirectoryEntry*>(this), this->fullSize(), sizeof(*this), this->size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the size of the data + the size of the Item type
|
* @return the size of the data + the size of the Item type
|
||||||
*/
|
*/
|
||||||
InodeId_t fullSize() const {
|
InodeId_t fullSize() const {
|
||||||
auto d = data();
|
const auto d = const_cast<DirectoryEntry*>(this)->data();
|
||||||
if (d.valid()) {
|
if (d.valid()) {
|
||||||
return sizeof(*this) + offsetof(DirectoryEntryData, name) + d->name.size();
|
return sizeof(*this) + offsetof(DirectoryEntryData, name) + ox_strnlen(d->name, MaxFileNameLength);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -84,7 +80,7 @@ class Directory {
|
|||||||
FileStore *m_fs = nullptr;
|
FileStore *m_fs = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Directory(fs::FileStore *fs, InodeId_t inode);
|
Directory(FileStore *fs, InodeId_t inode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes Directory.
|
* Initializes Directory.
|
||||||
@ -100,7 +96,7 @@ class Directory {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename InodeId_t>
|
template<typename InodeId_t>
|
||||||
Directory<InodeId_t>::Directory(fs::FileStore *fs, InodeId_t id) {
|
Directory<InodeId_t>::Directory(FileStore *fs, InodeId_t id) {
|
||||||
m_fs = fs;
|
m_fs = fs;
|
||||||
m_inodeId = id;
|
m_inodeId = id;
|
||||||
auto buff = fs->read(id).template to<Buffer>();
|
auto buff = fs->read(id).template to<Buffer>();
|
||||||
@ -136,6 +132,7 @@ Error Directory<InodeId_t>::write(PathIterator path, InodeId_t inode) noexcept {
|
|||||||
if (old.valid()) {
|
if (old.valid()) {
|
||||||
const auto newSize = m_size + DirectoryEntry<InodeId_t>::spaceNeeded(name.size());
|
const auto newSize = m_size + DirectoryEntry<InodeId_t>::spaceNeeded(name.size());
|
||||||
auto cpy = ox_malloca(newSize, Buffer, old);
|
auto cpy = ox_malloca(newSize, Buffer, old);
|
||||||
|
if (cpy != nullptr) {
|
||||||
cpy->setSize(newSize);
|
cpy->setSize(newSize);
|
||||||
auto val = cpy->malloc(name.size());
|
auto val = cpy->malloc(name.size());
|
||||||
if (val.valid()) {
|
if (val.valid()) {
|
||||||
@ -143,6 +140,7 @@ Error Directory<InodeId_t>::write(PathIterator path, InodeId_t inode) noexcept {
|
|||||||
err = m_fs->write(m_inodeId, cpy, cpy->size());
|
err = m_fs->write(m_inodeId, cpy, cpy->size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user