diff options
| author | Stefan Boberg <[email protected]> | 2023-09-20 15:22:03 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-20 15:22:03 +0200 |
| commit | 14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f (patch) | |
| tree | bf24ac15759385cea339f7e1cf5380f984f5699a /src/zenvfs/include | |
| parent | changelog version bump (diff) | |
| download | zen-14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f.tar.xz zen-14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f.zip | |
VFS implementation for local storage service (#396)
currently, only Windows (using Projected File System) is supported
Diffstat (limited to 'src/zenvfs/include')
| -rw-r--r-- | src/zenvfs/include/zenvfs/projfs.h | 14 | ||||
| -rw-r--r-- | src/zenvfs/include/zenvfs/vfs.h | 89 | ||||
| -rw-r--r-- | src/zenvfs/include/zenvfs/zenvfs.h | 9 |
3 files changed, 112 insertions, 0 deletions
diff --git a/src/zenvfs/include/zenvfs/projfs.h b/src/zenvfs/include/zenvfs/projfs.h new file mode 100644 index 000000000..8a89c2835 --- /dev/null +++ b/src/zenvfs/include/zenvfs/projfs.h @@ -0,0 +1,14 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "zenvfs.h" + +#if ZEN_WITH_VFS + +namespace zen { + +bool IsProjFsAvailable(); + +} // namespace zen +#endif diff --git a/src/zenvfs/include/zenvfs/vfs.h b/src/zenvfs/include/zenvfs/vfs.h new file mode 100644 index 000000000..412970860 --- /dev/null +++ b/src/zenvfs/include/zenvfs/vfs.h @@ -0,0 +1,89 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "zenvfs.h" + +#if ZEN_WITH_VFS + +# include <zencore/zencore.h> +# include <zencore/refcount.h> +# include <zencore/uid.h> + +# include <string_view> +# include <memory> +# include <vector> + +namespace zen { + +struct VfsProvider; + +////////////////////////////////////////////////////////////////////////// + +struct VfsTreeNode; + +struct VfsTreeDataSource : public RefCounted +{ + virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) = 0; + virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) = 0; + virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) = 0; +}; + +struct VfsTreeNode +{ + inline VfsTreeNode(VfsTreeNode* InParent) : ParentNode(InParent) {} + + const std::string_view GetName() const { return Name; } + uint64_t GetFileSize() const { return FileSize; } + VfsTreeDataSource* GetDataSource() const { return DataSource.Get(); } + const Oid& GetChunkId() const { return ChunkId; } + + const std::string GetPath() const; + + VfsTreeNode* FindNode(std::wstring_view NodeName); + VfsTreeNode* FindNode(std::string_view NodeName); + + void AddVirtualNode(std::string_view NodeName, Ref<VfsTreeDataSource>&& DataSource); + void AddFileNode(std::string_view NodeName, uint64_t InFileSize, Oid InChunkId, Ref<VfsTreeDataSource> DataSource = {}); + void NormalizeTree(); + bool IsDirectory() const; + void PopulateVirtualNode(); + + const std::vector<std::unique_ptr<VfsTreeNode>>& GetChildren() const { return ChildArray; } + std::vector<std::unique_ptr<VfsTreeNode>>& GetChildren() { return ChildArray; } + +private: + std::string Name; + uint64_t FileSize = 0; + Oid ChunkId = Oid::Zero; + Ref<VfsTreeDataSource> DataSource; + + inline static const uint64_t DirectoryMarker = ~uint64_t(0); + std::vector<std::unique_ptr<VfsTreeNode>> ChildArray; + VfsTreeNode* ParentNode = nullptr; + + VfsTreeNode* AddNewChildNode() { return ChildArray.emplace_back(std::make_unique<VfsTreeNode>(this)).get(); } + + void GetPath(StringBuilderBase& Path) const; +}; + +////////////////////////////////////////////////////////////////////////// + +class VfsHost +{ +public: + VfsHost(std::string_view VfsRootPath); + ~VfsHost(); + + void Initialize(); + void AddMount(std::string_view Mountpoint, Ref<VfsTreeDataSource>&& DataSource); + void Run(); + void RequestStop(); + void Cleanup(); + +private: + VfsProvider* m_Provider = nullptr; +}; + +} // namespace zen +#endif diff --git a/src/zenvfs/include/zenvfs/zenvfs.h b/src/zenvfs/include/zenvfs/zenvfs.h new file mode 100644 index 000000000..c70368a1d --- /dev/null +++ b/src/zenvfs/include/zenvfs/zenvfs.h @@ -0,0 +1,9 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include <zencore/zencore.h> + +#ifndef ZEN_WITH_VFS +# define ZEN_WITH_VFS ZEN_PLATFORM_WINDOWS +#endif |