summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/DiscScrubber.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2016-07-07 16:08:35 +0200
committerJosJuice <josjuice@gmail.com>2016-07-11 11:46:15 +0200
commit53e7eed28d977feec9371c39509b908aecbf13b8 (patch)
tree9d6e719d71cb8efd4de2e20be9134eeee26b3782 /Source/Core/DiscIO/DiscScrubber.cpp
parent31226b8503439641ecc1d4a2781bcc3fd08ede28 (diff)
DiscScrubber: Fix issue 9356
Diffstat (limited to 'Source/Core/DiscIO/DiscScrubber.cpp')
-rw-r--r--Source/Core/DiscIO/DiscScrubber.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/Source/Core/DiscIO/DiscScrubber.cpp b/Source/Core/DiscIO/DiscScrubber.cpp
index 2c8e3287cb..cad023f069 100644
--- a/Source/Core/DiscIO/DiscScrubber.cpp
+++ b/Source/Core/DiscIO/DiscScrubber.cpp
@@ -70,7 +70,7 @@ struct SPartitionGroup
static SPartitionGroup PartitionGroup[4];
void MarkAsUsed(u64 _Offset, u64 _Size);
-void MarkAsUsedE(u64 _PartitionDataOffset, u64 _Offset, u64 _Size);
+void MarkAsUsedE(u64 partition_data_offset, u64 offset, u64 size);
bool ReadFromVolume(u64 _Offset, u32& _Buffer, bool _Decrypt);
bool ReadFromVolume(u64 _Offset, u64& _Buffer, bool _Decrypt);
bool ParseDisc();
@@ -171,23 +171,24 @@ void MarkAsUsed(u64 _Offset, u64 _Size)
CurrentOffset += CLUSTER_SIZE;
}
}
-// Compensate for 0x400(SHA-1) per 0x8000(cluster)
-void MarkAsUsedE(u64 _PartitionDataOffset, u64 _Offset, u64 _Size)
-{
- u64 Offset;
- u64 Size;
-
- Offset = _Offset / 0x7c00;
- Offset = Offset * CLUSTER_SIZE;
- Offset += _PartitionDataOffset;
- Size = _Size / 0x7c00;
- Size = (Size + 1) * CLUSTER_SIZE;
+// Compensate for 0x400 (SHA-1) per 0x8000 (cluster), and round to whole clusters
+void MarkAsUsedE(u64 partition_data_offset, u64 offset, u64 size)
+{
+ u64 first_cluster_start = offset / 0x7c00 * CLUSTER_SIZE + partition_data_offset;
- // Add on the offset in the first block for the case where data straddles blocks
- Size += _Offset % 0x7c00;
+ u64 last_cluster_end;
+ if (size == 0)
+ {
+ // Without this special case, a size of 0 can be rounded to 1 cluster instead of 0
+ last_cluster_end = first_cluster_start;
+ }
+ else
+ {
+ last_cluster_end = ((offset + size - 1) / 0x7c00 + 1) * CLUSTER_SIZE + partition_data_offset;
+ }
- MarkAsUsed(Offset, Size);
+ MarkAsUsed(first_cluster_start, last_cluster_end - first_cluster_start);
}
// Helper functions for reading the BE volume