[ox/fs] Add modelWrite handler to FileAddress
This commit is contained in:
1
deps/ox/src/ox/fs/CMakeLists.txt
vendored
1
deps/ox/src/ox/fs/CMakeLists.txt
vendored
@@ -52,7 +52,6 @@ install(
|
||||
|
||||
install(
|
||||
FILES
|
||||
filestore/filestoretemplate.hpp
|
||||
filesystem/filesystem.hpp
|
||||
filesystem/pathiterator.hpp
|
||||
DESTINATION
|
||||
|
@@ -10,6 +10,11 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
FileAddress::FileAddress() {
|
||||
m_data.inode = 0;
|
||||
m_type = FileAddressType::Inode;
|
||||
}
|
||||
|
||||
FileAddress::FileAddress(uint64_t inode) {
|
||||
m_data.inode = inode;
|
||||
m_type = FileAddressType::Inode;
|
||||
|
50
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
50
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@@ -9,18 +9,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <ox/std/std.hpp>
|
||||
#include <ox/model/types.hpp>
|
||||
|
||||
namespace ox {
|
||||
|
||||
enum class FileAddressType {
|
||||
None = -1,
|
||||
enum class FileAddressType: int8_t {
|
||||
None = -1,
|
||||
Path,
|
||||
ConstPath,
|
||||
Inode,
|
||||
};
|
||||
|
||||
class FileAddress {
|
||||
private:
|
||||
|
||||
template<typename T>
|
||||
friend ox::Error modelWrite(T*, FileAddress*);
|
||||
|
||||
public:
|
||||
static constexpr auto Fields = 2;
|
||||
|
||||
protected:
|
||||
FileAddressType m_type = FileAddressType::None;
|
||||
union {
|
||||
char *path;
|
||||
@@ -29,6 +37,8 @@ class FileAddress {
|
||||
} m_data;
|
||||
|
||||
public:
|
||||
FileAddress();
|
||||
|
||||
FileAddress(uint64_t inode);
|
||||
|
||||
FileAddress(char *path);
|
||||
@@ -69,4 +79,38 @@ class FileAddress {
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
ox::Error modelWrite(T *io, FileAddress *fa) {
|
||||
io->setTypeInfo("ox::FileAddress", FileAddress::Fields);
|
||||
switch (fa->m_type) {
|
||||
case FileAddressType::Path:
|
||||
case FileAddressType::ConstPath:
|
||||
{
|
||||
decltype(fa->m_data.inode) blank = 0;
|
||||
const auto strSize = ox_strlen(fa->m_data.constPath) + 1;
|
||||
auto path = ox_malloca(strSize, char, 0);
|
||||
memcpy(path.get(), fa->m_data.constPath, strSize);
|
||||
oxReturnError(io->field("path", SerStr(path.get(), strSize - 1)));
|
||||
oxReturnError(io->field("inode", &blank));
|
||||
break;
|
||||
}
|
||||
case FileAddressType::Inode:
|
||||
{
|
||||
char blankPath[1] = "";
|
||||
oxReturnError(io->field("path", SerStr(blankPath, 0)));
|
||||
oxReturnError(io->field("inode", &fa->m_data.inode));
|
||||
break;
|
||||
}
|
||||
case FileAddressType::None:
|
||||
{
|
||||
char blankPath[1] = "";
|
||||
decltype(fa->m_data.inode) blankInode = 0;
|
||||
oxReturnError(io->field("path", SerStr(blankPath, 0)));
|
||||
oxReturnError(io->field("inode", &blankInode));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -84,6 +84,9 @@ ox::Error PassThroughFS::resize(uint64_t, void*) {
|
||||
Error PassThroughFS::write(const char *path, void *buffer, uint64_t size, uint8_t) {
|
||||
auto p = (m_path / stripSlash(path));
|
||||
auto f = fopen(p.c_str(), "w");
|
||||
if (!f) {
|
||||
return OxError(1);
|
||||
}
|
||||
auto err = OxError(fwrite(buffer, size, 1, f) == 1 ? 0 : 1);
|
||||
fclose(f);
|
||||
return err;
|
||||
|
Reference in New Issue
Block a user