summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys/vfs/vfs_offset.h
diff options
context:
space:
mode:
authorFearlessTobi <thm.frey@gmail.com>2024-01-16 06:23:01 +0100
committerLiam <byteslice@airmail.cc>2024-01-25 22:40:42 +0100
commit0f9288e38d80c6c63a545934557501fae40d3d83 (patch)
tree0643100d2471a1545dbfb447319b6ea26fdd6b63 /src/core/file_sys/vfs/vfs_offset.h
parentfs: Move fsp_srv subclasses to separate files (diff)
downloadyuzu-0f9288e38d80c6c63a545934557501fae40d3d83.tar
yuzu-0f9288e38d80c6c63a545934557501fae40d3d83.tar.gz
yuzu-0f9288e38d80c6c63a545934557501fae40d3d83.tar.bz2
yuzu-0f9288e38d80c6c63a545934557501fae40d3d83.tar.lz
yuzu-0f9288e38d80c6c63a545934557501fae40d3d83.tar.xz
yuzu-0f9288e38d80c6c63a545934557501fae40d3d83.tar.zst
yuzu-0f9288e38d80c6c63a545934557501fae40d3d83.zip
Diffstat (limited to 'src/core/file_sys/vfs/vfs_offset.h')
-rw-r--r--src/core/file_sys/vfs/vfs_offset.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs/vfs_offset.h b/src/core/file_sys/vfs/vfs_offset.h
new file mode 100644
index 000000000..4abe41d8e
--- /dev/null
+++ b/src/core/file_sys/vfs/vfs_offset.h
@@ -0,0 +1,50 @@
+// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <memory>
+
+#include "core/file_sys/vfs/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.
+class OffsetVfsFile : public VfsFile {
+public:
+ OffsetVfsFile(VirtualFile file, std::size_t size, std::size_t offset = 0,
+ std::string new_name = "", VirtualDir new_parent = nullptr);
+ ~OffsetVfsFile() override;
+
+ std::string GetName() const override;
+ std::size_t GetSize() const override;
+ bool Resize(std::size_t new_size) override;
+ VirtualDir GetContainingDirectory() const override;
+ bool IsWritable() const override;
+ bool IsReadable() const override;
+ std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
+ std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
+ std::optional<u8> ReadByte(std::size_t offset) const override;
+ std::vector<u8> ReadBytes(std::size_t size, std::size_t offset) const override;
+ std::vector<u8> ReadAllBytes() const override;
+ bool WriteByte(u8 data, std::size_t offset) override;
+ std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset) override;
+
+ bool Rename(std::string_view new_name) override;
+
+ std::size_t GetOffset() const;
+
+private:
+ std::size_t TrimToFit(std::size_t r_size, std::size_t r_offset) const;
+
+ VirtualFile file;
+ std::size_t offset;
+ std::size_t size;
+ std::string name;
+ VirtualDir parent;
+};
+
+} // namespace FileSys