[VFS] Port new BlockToOffsetSTFS algo from stfs-headers

65ca664fdb
This should give better compatibility with CON packages - ie. profiles taken from actual consoles should hopefully extract properly without errors, now there's shouldn't be any need for extracting them with Velocity/Horizon first.
This commit is contained in:
emoose 2020-01-05 20:18:14 +00:00 committed by illusion
parent d934bccac5
commit 18c930c1b2
2 changed files with 37 additions and 1 deletions

View File

@ -591,10 +591,43 @@ StfsContainerDevice::Error StfsContainerDevice::ReadSTFS() {
} }
} }
if (all_entries.size() > 0) {
return Error::kSuccess; return Error::kSuccess;
}
// Failed to load any entries, try with old algo if we haven't already
if (!use_old_algorithm_) {
use_old_algorithm_ = true;
return ReadSTFS();
}
// Tried with old algo and still no entries... return failure
return Error::kErrorReadError;
} }
size_t StfsContainerDevice::BlockToOffsetSTFS(uint64_t block_index) { size_t StfsContainerDevice::BlockToOffsetSTFS(uint64_t block_index) {
if (use_old_algorithm_) {
return BlockToOffsetSTFS_Old(block_index);
}
uint32_t num_tables = 1; // num hashtables per block? or maybe backingblocks?
if (((header_.header_size + 0xFFF) & 0xB000) == 0xB000 ||
(header_.stfs_volume_descriptor.flags & 0x1) == 0x0) {
num_tables++;
}
uint64_t dataBlock = block_index + num_tables * ((block_index + 0xAA) / 0xAA);
if (block_index >= 170) {
dataBlock += num_tables * ((block_index + 0x70E4) / 0x70E4);
if (block_index >= 28900) {
dataBlock += num_tables * ((block_index + 0x4AF768) / 0x4AF768);
}
}
return xe::round_up(header_.header_size, 0x1000) + (dataBlock * 0x1000);
}
size_t StfsContainerDevice::BlockToOffsetSTFS_Old(uint64_t block_index) {
uint64_t block; uint64_t block;
uint32_t block_shift = 0; uint32_t block_shift = 0;
if (((header_.header_size + 0x0FFF) & 0xB000) == 0xB000 || if (((header_.header_size + 0x0FFF) & 0xB000) == 0xB000 ||

View File

@ -217,6 +217,7 @@ class StfsContainerDevice : public Device {
Error ReadSTFS(); Error ReadSTFS();
size_t BlockToOffsetSTFS(uint64_t block); size_t BlockToOffsetSTFS(uint64_t block);
size_t BlockToOffsetSTFS_Old(uint64_t block);
BlockHash GetBlockHash(const uint8_t* map_ptr, uint32_t block_index, BlockHash GetBlockHash(const uint8_t* map_ptr, uint32_t block_index,
uint32_t table_offset); uint32_t table_offset);
@ -231,6 +232,8 @@ class StfsContainerDevice : public Device {
StfsPackageType package_type_; StfsPackageType package_type_;
StfsHeader header_; StfsHeader header_;
uint32_t table_size_shift_; uint32_t table_size_shift_;
bool use_old_algorithm_ = false;
}; };
} // namespace vfs } // namespace vfs