Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual file system #148

Open
milesrout opened this issue Nov 22, 2019 · 5 comments
Open

Virtual file system #148

milesrout opened this issue Nov 22, 2019 · 5 comments
Assignees
Labels
feature new feature stale issues that are very old and the original reporter may no longer be able to verify
Milestone

Comments

@milesrout
Copy link
Member

milesrout commented Nov 22, 2019

Trillek needs a virtual file system (VFS). This is an abstraction layer over the real disk. By adopting a layered bind mount approach it would be very flexible allowing us to load assets from zip/tgz archives transparently, sandbox plugins' disk access to a directory and its children, load resources over the network transparently, load new versions of resources from different places hiding the previous version at runtime, etc.

With a file extension registration system, different systems will be able to register file extension handlers to load resources into the VFS in their own way. For example, client/resources/md5mesh.cpp can register a handler for the ".md5mesh" extension, and then whenever a file with extension ".md5mesh" is loaded, the handler will read the file, parse it, and load an MD5Mesh object into the VFS at that path. Or for example, a handler for the ".zip" extension will be able to load the zip archive and present it transparently to the rest of the system as a directory.

When directories are mounted, they would create virtual directories, the contents of which are lazily mounted to the filesystem as they are loaded. So if I mount (real filesystem path) ./assets.zip to (virtual filesystem path) /, then load /models/bob/bob.md5mesh, /models/bob/bob.md5mesh will be loaded from the archive and passed as a file stream (backed by a custom ZIP archive streambuf) to the ".md5mesh" file extension handler, which basically shouldn't need to know whether it's dealing with a real physical file or not. It just uses an iostream.

// archive.cpp
vfs.RegisterExtension(".zip", [] (VFS::Path mountpoint, std::iostream fileStream, VFS::Handle h) {
    h.MountDirectory(...);
});
// md5mesh.cpp
vfs.RegisterExtension(".md5mesh", [] (VFS::Path mountpoint, std::iostream fileStream, VFS::Handle h) {
   auto mesh = MD5Mesh::Create(...);
   h.MountFile(mesh);
});
// main.cpp
vfs.Mount("/", FilePath{"./assets.zip"});
vfs.Mount("/logs", FilePath::GetLogDirectory());
std::shared_ptr<MD5Mesh> mesh = vfs.Load("/models/bob/bob.md5mesh");

@adam4813 I would like to use std::filesystem, a C++17 feature, to replace the current FilePath which is pretty limited. Are you happy with that? Are we okay with requiring C++17?

@milesrout milesrout added the feature new feature label Nov 22, 2019
@milesrout milesrout added this to the 0.11 milestone Nov 22, 2019
@milesrout milesrout self-assigned this Nov 22, 2019
@adam4813
Copy link
Member

adam4813 commented Nov 22, 2019 via email

@milesrout
Copy link
Member Author

Yeah, if you have a look at my filesystem branch, I've started work on this.

@adam4813
Copy link
Member

adam4813 commented Nov 22, 2019 via email

@milesrout
Copy link
Member Author

milesrout commented Nov 22, 2019

I don't think I pushed my latest changes to that branch, but essentially it makes it work as described above. Currently it's not quite architected right: it gives extension handlers the raw file path, assuming every resource they can access is a raw file on disk, which according to the above design wouldn't be true. Still, it basically works as of my latest unpushed changes. Just wanted some feedback before I put a whole lot more work into it.

@adam4813
Copy link
Member

adam4813 commented Nov 22, 2019 via email

@adam4813 adam4813 added stale issues that are very old and the original reporter may no longer be able to verify and removed stale issues that are very old and the original reporter may no longer be able to verify labels May 16, 2020
@adam4813 adam4813 added the stale issues that are very old and the original reporter may no longer be able to verify label Feb 15, 2021
@Meisaka Meisaka mentioned this issue Sep 10, 2021
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature stale issues that are very old and the original reporter may no longer be able to verify
Projects
None yet
Development

No branches or pull requests

2 participants