From 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 6 Jul 2018 10:51:32 -0400 Subject: Virtual Filesystem (#597) * Add VfsFile and VfsDirectory classes * Finish abstract Vfs classes * Implement RealVfsFile (computer fs backend) * Finish RealVfsFile and RealVfsDirectory * Finished OffsetVfsFile * More changes * Fix import paths * Major refactor * Remove double const * Use experimental/filesystem or filesystem depending on compiler * Port partition_filesystem * More changes * More Overhaul * FSP_SRV fixes * Fixes and testing * Try to get filesystem to compile * Filesystem on linux * Remove std::filesystem and document/test * Compile fixes * Missing include * Bug fixes * Fixes * Rename v_file and v_dir * clang-format fix * Rename NGLOG_* to LOG_* * Most review changes * Fix TODO * Guess 'main' to be Directory by filename --- src/core/file_sys/vfs_offset.h | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/core/file_sys/vfs_offset.h (limited to 'src/core/file_sys/vfs_offset.h') diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs_offset.h new file mode 100644 index 000000000..adc615b38 --- /dev/null +++ b/src/core/file_sys/vfs_offset.h @@ -0,0 +1,46 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "core/file_sys/vfs.h" + +namespace FileSys { + +// An implementation of VfsFile that wraps around another VfsFile at a certain offset. +// Similar to seeking to an offset. +// If the file is writable, operations that would write past the end of the offset file will expand +// the size of this wrapper. +struct OffsetVfsFile : public VfsFile { + OffsetVfsFile(std::shared_ptr file, size_t size, size_t offset = 0, + const std::string& new_name = ""); + + std::string GetName() const override; + size_t GetSize() const override; + bool Resize(size_t new_size) override; + std::shared_ptr GetContainingDirectory() const override; + bool IsWritable() const override; + bool IsReadable() const override; + size_t Read(u8* data, size_t length, size_t offset) const override; + size_t Write(const u8* data, size_t length, size_t offset) override; + boost::optional ReadByte(size_t offset) const override; + std::vector ReadBytes(size_t size, size_t offset) const override; + std::vector ReadAllBytes() const override; + bool WriteByte(u8 data, size_t offset) override; + size_t WriteBytes(std::vector data, size_t offset) override; + + bool Rename(const std::string& name) override; + + size_t GetOffset() const; + +private: + size_t TrimToFit(size_t r_size, size_t r_offset) const; + + std::shared_ptr file; + size_t offset; + size_t size; + std::string name; +}; + +} // namespace FileSys -- cgit v1.2.3