From 810274071da6be521d9e198bf6fde64afd1fd077 Mon Sep 17 00:00:00 2001 From: Akilesh Kailash Date: Sat, 23 Sep 2023 01:07:47 -0700 Subject: [PATCH] Create_cow: Hash of target blocks should not be stored. Target block hash was in-correctly getting added to map thereby overriding the source-hash. Bug: 299011882 Test: Flash Pixel 6 Pro from A->B and from B->A Change-Id: Ib3887c29cd6b8f2abd50e932273a5cfc2a096bd5 Signed-off-by: Akilesh Kailash --- fs_mgr/libsnapshot/libsnapshot_cow/create_cow.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/create_cow.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/create_cow.cpp index 4e07fe3b3..efb1035c2 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/create_cow.cpp +++ b/fs_mgr/libsnapshot/libsnapshot_cow/create_cow.cpp @@ -240,9 +240,11 @@ bool CreateSnapshot::ReadBlocks(off_t offset, const int skip_blocks, const uint6 SHA256(bufptr, BLOCK_SZ, checksum); std::string hash = ToHexString(checksum, sizeof(checksum)); - if (create_snapshot_patch_ && !WriteSnapshot(bufptr, blkindex, hash)) { - LOG(ERROR) << "WriteSnapshot failed for block: " << blkindex; - return false; + if (create_snapshot_patch_) { + if (!WriteSnapshot(bufptr, blkindex, hash)) { + LOG(ERROR) << "WriteSnapshot failed for block: " << blkindex; + return false; + } } else { std::lock_guard lock(source_block_hash_lock_); { @@ -256,7 +258,7 @@ bool CreateSnapshot::ReadBlocks(off_t offset, const int skip_blocks, const uint6 num_blocks -= 1; } - file_offset += (skip_blocks * kBlockSizeToRead); + file_offset += (skip_blocks * to_read); if (file_offset >= dev_sz) { break; }