more draft fs
This commit is contained in:
parent
eb307b9cd9
commit
ec362948f4
|
@ -19,6 +19,8 @@ class GenericHandleAllocator {
|
|||
};
|
||||
|
||||
class AbstractFileSystem {
|
||||
public:
|
||||
virtual bool ownsHandle(u32 handle) = 0;
|
||||
virtual u32 openFile(std::string filename, FileAccess access) = 0;
|
||||
virtual void closeFile(u32 handle) = 0;
|
||||
};
|
||||
|
|
|
@ -2,19 +2,51 @@
|
|||
|
||||
namespace Emulator::Host::GenericFS {
|
||||
|
||||
void MetaFileSystem::mount(std::string prefix, AbstractFileSystem* system) {}
|
||||
void MetaFileSystem::mount(std::string prefix, AbstractFileSystem* system) {
|
||||
System x;
|
||||
x.prefix = prefix;
|
||||
x.system = system;
|
||||
fileSystems.push_back(x);
|
||||
}
|
||||
|
||||
void MetaFileSystem::unMount(AbstractFileSystem* system) {}
|
||||
|
||||
void MetaFileSystem::unMountAll() {}
|
||||
void MetaFileSystem::unMountAll() { fileSystems.clear(); }
|
||||
|
||||
bool MetaFileSystem::mapFilePath(std::string inpath, std::string* outpath, AbstractFileSystem** system) { return false; }
|
||||
AbstractFileSystem* MetaFileSystem::getHandleOwner(u32 handle) {
|
||||
for (u32 i = 0; i < fileSystems.size(); i++) {
|
||||
if (fileSystems[i].system->ownsHandle(handle)) return fileSystems[i].system; // got it!
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
void MetaFileSystem::releaseHandle(u32 handle) {}
|
||||
}
|
||||
|
||||
u32 MetaFileSystem::openFile(std::string filename, FileAccess access) { return u32(); }
|
||||
bool MetaFileSystem::mapFilePath(std::string inpath, std::string* outpath, AbstractFileSystem** system) {
|
||||
for (unsigned int i = 0; i < fileSystems.size(); i++) {
|
||||
int prefLen = fileSystems[i].prefix.size();
|
||||
if (fileSystems[i].prefix == inpath.substr(0, prefLen))
|
||||
{
|
||||
*outpath = inpath.substr(prefLen);
|
||||
*system = fileSystems[i].system;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MetaFileSystem::closeFile(u32 handle) {}
|
||||
u32 MetaFileSystem::openFile(std::string filename, FileAccess access) {
|
||||
AbstractFileSystem* system;
|
||||
std::string of;
|
||||
if (mapFilePath(filename, &of, &system)) {
|
||||
return system->openFile(of, access);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MetaFileSystem::closeFile(u32 handle) {
|
||||
AbstractFileSystem* sys = getHandleOwner(handle);
|
||||
if (sys) sys->closeFile(handle);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Emulator::Host::GenericFS
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
#include <types.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "generic_file_system.h"
|
||||
|
||||
namespace Emulator::Host::GenericFS {
|
||||
|
@ -15,6 +17,7 @@ class MetaFileSystem : public GenericHandleAllocator, AbstractFileSystem {
|
|||
u32 current;
|
||||
std::vector<System> fileSystems;
|
||||
std::string currentDirectory;
|
||||
std::vector<u32> handler;
|
||||
|
||||
public:
|
||||
MetaFileSystem() : current(0) {}
|
||||
|
@ -24,9 +27,14 @@ class MetaFileSystem : public GenericHandleAllocator, AbstractFileSystem {
|
|||
void unMountAll();
|
||||
AbstractFileSystem *getHandleOwner(u32 handle);
|
||||
bool mapFilePath(std::string inpath, std::string *outpath, AbstractFileSystem **system);
|
||||
u32 requestHandle() { return ++current; }
|
||||
void releaseHandle(u32 handle);
|
||||
u32 requestHandle() {
|
||||
handler.push_back(current);
|
||||
current++;
|
||||
return handler.back();
|
||||
}
|
||||
void releaseHandle(u32 handle) { handler.erase(std::remove(handler.begin(), handler.end(), handle), handler.end()); }
|
||||
bool ownsHandle(u32 handle) { return false; }
|
||||
u32 openFile(std::string filename, FileAccess access);
|
||||
void closeFile(u32 handle);
|
||||
};
|
||||
}
|
||||
} // namespace Emulator::Host::GenericFS
|
Loading…
Reference in New Issue