From 14d7568f9c7d970b7bbf7b6463a0a8530f98bb6f Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Wed, 20 Sep 2023 15:22:03 +0200 Subject: VFS implementation for local storage service (#396) currently, only Windows (using Projected File System) is supported --- src/zenvfs/include/zenvfs/projfs.h | 14 ++++++ src/zenvfs/include/zenvfs/vfs.h | 89 ++++++++++++++++++++++++++++++++++++++ src/zenvfs/include/zenvfs/zenvfs.h | 9 ++++ 3 files changed, 112 insertions(+) create mode 100644 src/zenvfs/include/zenvfs/projfs.h create mode 100644 src/zenvfs/include/zenvfs/vfs.h create mode 100644 src/zenvfs/include/zenvfs/zenvfs.h (limited to 'src/zenvfs/include') 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 +# include +# include + +# include +# include +# include + +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&& DataSource); + void AddFileNode(std::string_view NodeName, uint64_t InFileSize, Oid InChunkId, Ref DataSource = {}); + void NormalizeTree(); + bool IsDirectory() const; + void PopulateVirtualNode(); + + const std::vector>& GetChildren() const { return ChildArray; } + std::vector>& GetChildren() { return ChildArray; } + +private: + std::string Name; + uint64_t FileSize = 0; + Oid ChunkId = Oid::Zero; + Ref DataSource; + + inline static const uint64_t DirectoryMarker = ~uint64_t(0); + std::vector> ChildArray; + VfsTreeNode* ParentNode = nullptr; + + VfsTreeNode* AddNewChildNode() { return ChildArray.emplace_back(std::make_unique(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&& 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 + +#ifndef ZEN_WITH_VFS +# define ZEN_WITH_VFS ZEN_PLATFORM_WINDOWS +#endif -- cgit v1.2.3