From 930f34865071298c63c566531b3615a7b470a0b9 Mon Sep 17 00:00:00 2001 From: emoose Date: Sun, 19 Jan 2020 21:46:46 +0000 Subject: [PATCH] [VFS] Fix StfsContainerDevice::total_allocation_units() --- src/xenia/vfs/devices/stfs_container_device.cc | 4 ++++ src/xenia/vfs/devices/stfs_container_device.h | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/xenia/vfs/devices/stfs_container_device.cc b/src/xenia/vfs/devices/stfs_container_device.cc index caa01877c..537d1a9b4 100644 --- a/src/xenia/vfs/devices/stfs_container_device.cc +++ b/src/xenia/vfs/devices/stfs_container_device.cc @@ -107,6 +107,8 @@ StfsContainerDevice::Error StfsContainerDevice::MapFiles() { return header_result; } + mmap_total_size_ += header_map->size(); + // If the STFS package is a single file, the header is self contained and // we don't need to map any extra files. // NOTE: data_file_count is 0 for STFS and 1 for SVOD @@ -145,8 +147,10 @@ StfsContainerDevice::Error StfsContainerDevice::MapFiles() { if (!data) { XELOGI("Failed to map SVOD file %ls.", path.c_str()); mmap_.clear(); + mmap_total_size_ = 0; return Error::kErrorReadError; } + mmap_total_size_ += data->size(); mmap_.emplace(std::make_pair(i, std::move(data))); } XELOGI("SVOD successfully mapped %d files.", fragment_files.size()); diff --git a/src/xenia/vfs/devices/stfs_container_device.h b/src/xenia/vfs/devices/stfs_container_device.h index 2d833ce50..0dcf1284e 100644 --- a/src/xenia/vfs/devices/stfs_container_device.h +++ b/src/xenia/vfs/devices/stfs_container_device.h @@ -437,7 +437,7 @@ class StfsContainerDevice : public Device { Entry* ResolvePath(const std::string& path) override; uint32_t total_allocation_units() const override { - return uint32_t(mmap_total_size_ / sectors_per_allocation_unit() / + return uint32_t(data_size() / sectors_per_allocation_unit() / bytes_per_sector()); } uint32_t available_allocation_units() const override { return 0; } @@ -496,7 +496,9 @@ class StfsContainerDevice : public Device { std::wstring local_path_; std::map> mmap_; - size_t mmap_total_size_; + size_t mmap_total_size_ = 0; + + size_t data_size() const { return mmap_total_size_ - sizeof(StfsHeader); } uint32_t blocks_per_hash_table_ = 1; uint32_t block_step_[2] = {0xAB, 0x718F};