[ox/fs] Make Directory type a type parameter in FileSystemTemplate

This commit is contained in:
Gary Talent 2018-09-01 15:52:59 -05:00
parent 6a82e96db7
commit 0c6a557878
2 changed files with 55 additions and 55 deletions

View File

@ -13,7 +13,7 @@ namespace ox::fs {
template class Directory<uint16_t>; template class Directory<uint16_t>;
template class Directory<uint32_t>; template class Directory<uint32_t>;
template class FileSystemTemplate<uint16_t>; template class FileSystemTemplate<uint16_t, Directory<uint16_t>>;
template class FileSystemTemplate<uint32_t>; template class FileSystemTemplate<uint32_t, Directory<uint32_t>>;
} }

View File

@ -15,7 +15,7 @@
namespace ox::fs { namespace ox::fs {
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
class FileSystemTemplate { class FileSystemTemplate {
private: private:
static constexpr InodeId_t InodeFsData = 2; static constexpr InodeId_t InodeFsData = 2;
@ -82,21 +82,21 @@ class FileSystemTemplate {
}; };
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
FileSystemTemplate<InodeId_t>::FileSystemTemplate(FileStore *fs) { FileSystemTemplate<InodeId_t, Directory>::FileSystemTemplate(FileStore *fs) {
m_fs = fs; m_fs = fs;
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
FileSystemTemplate<InodeId_t>::~FileSystemTemplate() { FileSystemTemplate<InodeId_t, Directory>::~FileSystemTemplate() {
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::format() { Error FileSystemTemplate<InodeId_t, Directory>::format() {
oxReturnError(m_fs->format()); oxReturnError(m_fs->format());
constexpr auto rootDirInode = MaxValue<InodeId_t> / 2; constexpr auto rootDirInode = MaxValue<InodeId_t> / 2;
Directory<InodeId_t> rootDir(m_fs, rootDirInode); Directory rootDir(m_fs, rootDirInode);
oxReturnError(rootDir.init()); oxReturnError(rootDir.init());
FileSystemData fd; FileSystemData fd;
@ -111,12 +111,12 @@ Error FileSystemTemplate<InodeId_t>::format() {
return OxError(0); return OxError(0);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::mkdir(const char *path, bool recursive) { Error FileSystemTemplate<InodeId_t, Directory>::mkdir(const char *path, bool recursive) {
auto fd = fileSystemData(); auto fd = fileSystemData();
if (fd.ok()) { if (fd.ok()) {
oxTrace("ox::fs::FileSystemTemplate::mkdir") << "rootDirInode:" << fd.value.rootDirInode; oxTrace("ox::fs::FileSystemTemplate::mkdir") << "rootDirInode:" << fd.value.rootDirInode;
Directory<InodeId_t> rootDir(m_fs, fd.value.rootDirInode); Directory rootDir(m_fs, fd.value.rootDirInode);
return rootDir.mkdir(path, recursive); return rootDir.mkdir(path, recursive);
} else { } else {
oxLogError(fd.error); oxLogError(fd.error);
@ -124,11 +124,11 @@ Error FileSystemTemplate<InodeId_t>::mkdir(const char *path, bool recursive) {
} }
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::move(const char *src, const char *dest) { Error FileSystemTemplate<InodeId_t, Directory>::move(const char *src, const char *dest) {
auto fd = fileSystemData(); auto fd = fileSystemData();
oxReturnError(fd.error); oxReturnError(fd.error);
Directory<InodeId_t> rootDir(m_fs, fd.value.rootDirInode); Directory rootDir(m_fs, fd.value.rootDirInode);
auto inode = rootDir.find(src); auto inode = rootDir.find(src);
oxReturnError(inode.error); oxReturnError(inode.error);
oxReturnError(rootDir.write(dest, inode)); oxReturnError(rootDir.write(dest, inode));
@ -136,31 +136,31 @@ Error FileSystemTemplate<InodeId_t>::move(const char *src, const char *dest) {
return OxError(0); return OxError(0);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::read(const char *path, void *buffer, std::size_t buffSize) { Error FileSystemTemplate<InodeId_t, Directory>::read(const char *path, void *buffer, std::size_t buffSize) {
auto fd = fileSystemData(); auto fd = fileSystemData();
oxReturnError(fd.error); oxReturnError(fd.error);
Directory<InodeId_t> rootDir(m_fs, fd.value.rootDirInode); Directory rootDir(m_fs, fd.value.rootDirInode);
auto inode = rootDir.find(path); auto inode = rootDir.find(path);
oxReturnError(inode.error); oxReturnError(inode.error);
return read(inode, buffer, buffSize); return read(inode, buffer, buffSize);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::read(uint64_t inode, void *buffer, std::size_t buffSize) { Error FileSystemTemplate<InodeId_t, Directory>::read(uint64_t inode, void *buffer, std::size_t buffSize) {
return m_fs->read(inode, buffer, buffSize); return m_fs->read(inode, buffer, buffSize);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) { Error FileSystemTemplate<InodeId_t, Directory>::read(uint64_t inode, std::size_t readStart, std::size_t readSize, void *buffer, std::size_t *size) {
return m_fs->read(inode, readStart, readSize, buffer, size); return m_fs->read(inode, readStart, readSize, buffer, size);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::remove(const char *path, bool recursive) { Error FileSystemTemplate<InodeId_t, Directory>::remove(const char *path, bool recursive) {
auto fd = fileSystemData(); auto fd = fileSystemData();
oxReturnError(fd.error); oxReturnError(fd.error);
Directory<InodeId_t> rootDir(m_fs, fd.value.rootDirInode); Directory rootDir(m_fs, fd.value.rootDirInode);
auto inode = rootDir.find(path); auto inode = rootDir.find(path);
oxReturnError(inode.error); oxReturnError(inode.error);
auto st = stat(inode); auto st = stat(inode);
@ -178,26 +178,26 @@ Error FileSystemTemplate<InodeId_t>::remove(const char *path, bool recursive) {
return OxError(0); return OxError(0);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
void FileSystemTemplate<InodeId_t>::resize(uint64_t size, void *buffer) { void FileSystemTemplate<InodeId_t, Directory>::resize(uint64_t size, void *buffer) {
m_fs->resize(size, buffer); m_fs->resize(size, buffer);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) { Error FileSystemTemplate<InodeId_t, Directory>::write(const char *path, void *buffer, uint64_t size, uint8_t fileType) {
auto inode = find(path); auto inode = find(path);
oxReturnError(inode.error); oxReturnError(inode.error);
return write(inode, buffer, size, fileType); return write(inode, buffer, size, fileType);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType) { Error FileSystemTemplate<InodeId_t, Directory>::write(uint64_t inode, void *buffer, uint64_t size, uint8_t fileType) {
// TODO: directory insert // TODO: directory insert
return m_fs->write(inode, buffer, size, fileType); return m_fs->write(inode, buffer, size, fileType);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
ValErr<FileStat> FileSystemTemplate<InodeId_t>::stat(uint64_t inode) { ValErr<FileStat> FileSystemTemplate<InodeId_t, Directory>::stat(uint64_t inode) {
auto s = m_fs->stat(inode); auto s = m_fs->stat(inode);
FileStat out; FileStat out;
out.inode = s.value.inode; out.inode = s.value.inode;
@ -207,8 +207,8 @@ ValErr<FileStat> FileSystemTemplate<InodeId_t>::stat(uint64_t inode) {
return {out, s.error}; return {out, s.error};
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
ValErr<FileStat> FileSystemTemplate<InodeId_t>::stat(const char *path) { ValErr<FileStat> FileSystemTemplate<InodeId_t, Directory>::stat(const char *path) {
auto inode = find(path); auto inode = find(path);
if (inode.error) { if (inode.error) {
return {{}, inode.error}; return {{}, inode.error};
@ -216,33 +216,33 @@ ValErr<FileStat> FileSystemTemplate<InodeId_t>::stat(const char *path) {
return stat(inode.value); return stat(inode.value);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
uint64_t FileSystemTemplate<InodeId_t>::spaceNeeded(uint64_t size) { uint64_t FileSystemTemplate<InodeId_t, Directory>::spaceNeeded(uint64_t size) {
return m_fs->spaceNeeded(size); return m_fs->spaceNeeded(size);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
uint64_t FileSystemTemplate<InodeId_t>::available() { uint64_t FileSystemTemplate<InodeId_t, Directory>::available() {
return m_fs->available(); return m_fs->available();
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
uint64_t FileSystemTemplate<InodeId_t>::size() { uint64_t FileSystemTemplate<InodeId_t, Directory>::size() {
return m_fs->size(); return m_fs->size();
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
uint8_t *FileSystemTemplate<InodeId_t>::buff() { uint8_t *FileSystemTemplate<InodeId_t, Directory>::buff() {
return m_fs->buff(); return m_fs->buff();
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
Error FileSystemTemplate<InodeId_t>::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) { Error FileSystemTemplate<InodeId_t, Directory>::walk(Error(*cb)(uint8_t, uint64_t, uint64_t)) {
return m_fs->walk(cb); return m_fs->walk(cb);
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
ValErr<typename FileSystemTemplate<InodeId_t>::FileSystemData> FileSystemTemplate<InodeId_t>::fileSystemData() { ValErr<typename FileSystemTemplate<InodeId_t, Directory>::FileSystemData> FileSystemTemplate<InodeId_t, Directory>::fileSystemData() {
FileSystemData fd; FileSystemData fd;
auto err = m_fs->read(InodeFsData, &fd, sizeof(fd)); auto err = m_fs->read(InodeFsData, &fd, sizeof(fd));
if (err != 0) { if (err != 0) {
@ -251,11 +251,11 @@ ValErr<typename FileSystemTemplate<InodeId_t>::FileSystemData> FileSystemTemplat
return fd; return fd;
} }
template<typename InodeId_t> template<typename InodeId_t, typename Directory>
ValErr<uint64_t> FileSystemTemplate<InodeId_t>::find(const char *path) { ValErr<uint64_t> FileSystemTemplate<InodeId_t, Directory>::find(const char *path) {
auto fd = fileSystemData(); auto fd = fileSystemData();
oxReturnError(fd.error); oxReturnError(fd.error);
Directory<InodeId_t> rootDir(m_fs, fd.value.rootDirInode); Directory rootDir(m_fs, fd.value.rootDirInode);
auto inode = rootDir.find(path); auto inode = rootDir.find(path);
oxReturnError(inode.error); oxReturnError(inode.error);
return inode.value; return inode.value;
@ -264,10 +264,10 @@ ValErr<uint64_t> FileSystemTemplate<InodeId_t>::find(const char *path) {
extern template class Directory<uint16_t>; extern template class Directory<uint16_t>;
extern template class Directory<uint32_t>; extern template class Directory<uint32_t>;
extern template class FileSystemTemplate<uint16_t>; extern template class FileSystemTemplate<uint16_t, Directory<uint16_t>>;
extern template class FileSystemTemplate<uint32_t>; extern template class FileSystemTemplate<uint32_t, Directory<uint16_t>>;
using FileSystem16 = FileSystemTemplate<uint16_t>; using FileSystem16 = FileSystemTemplate<uint16_t, Directory<uint16_t>>;
using FileSystem32 = FileSystemTemplate<uint32_t>; using FileSystem32 = FileSystemTemplate<uint32_t, Directory<uint32_t>>;
} }