Loading fs_mgr/libsnapshot/include/libsnapshot/cow_format.h +6 −0 Original line number Diff line number Diff line Loading @@ -226,6 +226,9 @@ struct CowOperationV3 { uint64_t source_info_; constexpr uint64_t source() const { return source_info_ & kCowOpSourceInfoDataMask; } constexpr void set_source(uint64_t source) { // Clear the first 48 bit first source_info_ &= ~kCowOpSourceInfoDataMask; // Set the actual source field source_info_ |= source & kCowOpSourceInfoDataMask; } constexpr CowOperationType type() const { Loading @@ -234,6 +237,9 @@ struct CowOperationV3 { return static_cast<CowOperationType>(type); } constexpr void set_type(CowOperationType type) { // Clear the top 4 bits first source_info_ &= ((1ULL << kCowOpSourceInfoTypeBit) - 1); // set the actual type bits source_info_ |= (static_cast<uint64_t>(type) & kCowOpSourceInfoTypeMask) << kCowOpSourceInfoTypeBit; } Loading fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp +37 −0 Original line number Diff line number Diff line Loading @@ -621,5 +621,42 @@ TEST_F(CowTestV3, ResumeSeqOp) { ASSERT_EQ(expected_block, 0); ASSERT_TRUE(iter->AtEnd()); } TEST_F(CowTestV3, SetSourceManyTimes) { CowOperationV3 op{}; op.set_source(1); ASSERT_EQ(op.source(), 1); op.set_source(2); ASSERT_EQ(op.source(), 2); op.set_source(4); ASSERT_EQ(op.source(), 4); op.set_source(8); ASSERT_EQ(op.source(), 8); } TEST_F(CowTestV3, SetTypeManyTimes) { CowOperationV3 op{}; op.set_type(kCowCopyOp); ASSERT_EQ(op.type(), kCowCopyOp); op.set_type(kCowReplaceOp); ASSERT_EQ(op.type(), kCowReplaceOp); op.set_type(kCowZeroOp); ASSERT_EQ(op.type(), kCowZeroOp); op.set_type(kCowXorOp); ASSERT_EQ(op.type(), kCowXorOp); } TEST_F(CowTestV3, SetTypeSourceInverleave) { CowOperationV3 op{}; op.set_type(kCowCopyOp); ASSERT_EQ(op.type(), kCowCopyOp); op.set_source(0x010203040506); ASSERT_EQ(op.source(), 0x010203040506); ASSERT_EQ(op.type(), kCowCopyOp); op.set_type(kCowReplaceOp); ASSERT_EQ(op.source(), 0x010203040506); ASSERT_EQ(op.type(), kCowReplaceOp); } } // namespace snapshot } // namespace android Loading
fs_mgr/libsnapshot/include/libsnapshot/cow_format.h +6 −0 Original line number Diff line number Diff line Loading @@ -226,6 +226,9 @@ struct CowOperationV3 { uint64_t source_info_; constexpr uint64_t source() const { return source_info_ & kCowOpSourceInfoDataMask; } constexpr void set_source(uint64_t source) { // Clear the first 48 bit first source_info_ &= ~kCowOpSourceInfoDataMask; // Set the actual source field source_info_ |= source & kCowOpSourceInfoDataMask; } constexpr CowOperationType type() const { Loading @@ -234,6 +237,9 @@ struct CowOperationV3 { return static_cast<CowOperationType>(type); } constexpr void set_type(CowOperationType type) { // Clear the top 4 bits first source_info_ &= ((1ULL << kCowOpSourceInfoTypeBit) - 1); // set the actual type bits source_info_ |= (static_cast<uint64_t>(type) & kCowOpSourceInfoTypeMask) << kCowOpSourceInfoTypeBit; } Loading
fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp +37 −0 Original line number Diff line number Diff line Loading @@ -621,5 +621,42 @@ TEST_F(CowTestV3, ResumeSeqOp) { ASSERT_EQ(expected_block, 0); ASSERT_TRUE(iter->AtEnd()); } TEST_F(CowTestV3, SetSourceManyTimes) { CowOperationV3 op{}; op.set_source(1); ASSERT_EQ(op.source(), 1); op.set_source(2); ASSERT_EQ(op.source(), 2); op.set_source(4); ASSERT_EQ(op.source(), 4); op.set_source(8); ASSERT_EQ(op.source(), 8); } TEST_F(CowTestV3, SetTypeManyTimes) { CowOperationV3 op{}; op.set_type(kCowCopyOp); ASSERT_EQ(op.type(), kCowCopyOp); op.set_type(kCowReplaceOp); ASSERT_EQ(op.type(), kCowReplaceOp); op.set_type(kCowZeroOp); ASSERT_EQ(op.type(), kCowZeroOp); op.set_type(kCowXorOp); ASSERT_EQ(op.type(), kCowXorOp); } TEST_F(CowTestV3, SetTypeSourceInverleave) { CowOperationV3 op{}; op.set_type(kCowCopyOp); ASSERT_EQ(op.type(), kCowCopyOp); op.set_source(0x010203040506); ASSERT_EQ(op.source(), 0x010203040506); ASSERT_EQ(op.type(), kCowCopyOp); op.set_type(kCowReplaceOp); ASSERT_EQ(op.source(), 0x010203040506); ASSERT_EQ(op.type(), kCowReplaceOp); } } // namespace snapshot } // namespace android