feat(vfs): implement VFS context, disk, mount support, and tests#550
Open
jnyfah wants to merge 2 commits into
Open
feat(vfs): implement VFS context, disk, mount support, and tests#550jnyfah wants to merge 2 commits into
jnyfah wants to merge 2 commits into
Conversation
Closed
JeanPhilippeKernel
requested changes
Jul 8, 2026
JeanPhilippeKernel
requested changes
Jul 9, 2026
| return VFSResult<IVFSFile*>::Fail(VFSError::PermissionDenied); | ||
| } | ||
|
|
||
| VFSDiskFile* file = new VFSDiskFile(); |
There was a problem hiding this comment.
this present itself as good candidate of PoolAllocator
eg of usage:
// IVFSContext.h
struct IVFSContext
{
protected:
explicit IVFSContext(size_t file_chunk_size, size_t max_open_files, size_t file_alignment)
{
const size_t pool_size = max_open_files * file_chunk_size;
m_arena.Initialize(pool_size, platform_page_size());
m_file_pool.Initialize(&m_arena, pool_size, file_chunk_size, file_alignment);
}
Core::Memory::PoolAllocator m_file_pool; // must be before m_arena
Core::Memory::ArenaAllocator m_arena;
public:
virtual ~IVFSContext() = default;
virtual VFSResult<IVFSFile*> Open(const VFSPath& path, VFSOpenFlags flags) = 0;
virtual void Close(IVFSFile* file) = 0;
// ... rest unchanged
};
struct VFSDiskContext final : public IVFSContext
{
explicit VFSDiskContext(cstring native_root)
: IVFSContext(sizeof(VFSDiskFile), 20000, alignof(VFSDiskFile))
{ /* root setup only */ }
};
struct ZipFileContext final : public IVFSContext
{
explicit ZipFileContext(cstring zip_path)
: IVFSContext(sizeof(ZipFile), 4000, alignof(ZipFile))
{ /* zip setup only */ }
};
struct MemoryFileContext final : public IVFSContext
{
explicit MemoryFileContext(/* ... */)
: IVFSContext(sizeof(MemoryFile), 1000, alignof(MemoryFile))
{ }
};
Each context passes its own sizeof/alignof/capacity — the pool wiring lives in exactly one place. The Close() implementation could even be provided once in the base since the pattern is always the same (~IVFSFile() then m_file_pool.Free()):
// base provides a default Close() — concrete types only override if they need extra teardown
void IVFSContext::Close(IVFSFile* file)
{
if (!file) return;
file->~IVFSFile();
m_file_pool.Free(file);
}There was a problem hiding this comment.
here since VFSDiskFile has a non-trivial destructor (fclose). The pool only manages raw memory, so you'd need the placement-new + explicit destructor pattern:
VFSResult<IVFSFile*> VFSDiskContext::Open(const VFSPath& path, VFSOpenFlags flags)
{
// ... existing fopen logic ...
void* mem = m_file_pool.Allocate(__FILE__, __LINE__);
if (!mem)
{
std::fclose(handle);
return VFSResult<IVFSFile*>::Fail(VFSError::OutOfMemory);
}
return VFSResult<IVFSFile*>::Ok(new (mem) VFSDiskFile(handle, path));
}
void VFSDiskContext::Close(IVFSFile* file)
{
if (!file) return;
file->~IVFSFile(); // runs fclose via ~VFSDiskFile
m_file_pool.Free(file); // returns chunk to free list — O(1)
}This purely idea. - you might want to refine on it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.