Loading fs_mgr/libsnapshot/Android.bp +5 −4 Original line number Diff line number Diff line Loading @@ -85,11 +85,9 @@ filegroup { "android/snapshot/snapshot.proto", "device_info.cpp", "snapshot.cpp", "snapshot_reader.cpp", "snapshot_stats.cpp", "snapshot_stub.cpp", "snapshot_metadata_updater.cpp", "snapshot_writer.cpp", "partition_cow_creator.cpp", "return.cpp", "utility.cpp", Loading Loading @@ -165,6 +163,9 @@ cc_defaults { "liblz4", "libzstd", ], header_libs: [ "libupdate_engine_headers", ], export_include_dirs: ["include"], } Loading @@ -179,6 +180,7 @@ cc_library_static { "libsnapshot_cow/cow_format.cpp", "libsnapshot_cow/cow_reader.cpp", "libsnapshot_cow/parser_v2.cpp", "libsnapshot_cow/snapshot_reader.cpp", "libsnapshot_cow/writer_base.cpp", "libsnapshot_cow/writer_v2.cpp", ], Loading Loading @@ -224,9 +226,7 @@ cc_defaults { srcs: [ "partition_cow_creator_test.cpp", "snapshot_metadata_updater_test.cpp", "snapshot_reader_test.cpp", "snapshot_test.cpp", "snapshot_writer_test.cpp", ], shared_libs: [ "libbinder", Loading Loading @@ -372,6 +372,7 @@ cc_test { "libsnapshot_cow_defaults", ], srcs: [ "libsnapshot_cow/snapshot_reader_test.cpp", "libsnapshot_cow/test_v2.cpp", ], cflags: [ Loading fs_mgr/libsnapshot/include/libsnapshot/cow_reader.h +7 −2 Original line number Diff line number Diff line Loading @@ -24,6 +24,10 @@ #include <android-base/unique_fd.h> #include <libsnapshot/cow_format.h> namespace chromeos_update_engine { class FileDescriptor; } // namespace chromeos_update_engine namespace android { namespace snapshot { Loading @@ -32,6 +36,8 @@ class ICowOpIter; // Interface for reading from a snapuserd COW. class ICowReader { public: using FileDescriptor = chromeos_update_engine::FileDescriptor; virtual ~ICowReader() {} // Return the file header. Loading Loading @@ -109,10 +115,9 @@ class CowReader final : public ICowReader { bool Parse(android::base::borrowed_fd fd, std::optional<uint64_t> label = {}); bool InitForMerge(android::base::unique_fd&& fd); bool VerifyMergeOps() override; bool VerifyMergeOps() override; bool GetFooter(CowFooter* footer) override; bool GetLastLabel(uint64_t* label) override; // Create a CowOpIter object which contains footer_.num_ops Loading fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h +13 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,8 @@ struct CowOptions { // will occur in the sequence they were added to the COW. class ICowWriter { public: using FileDescriptor = chromeos_update_engine::FileDescriptor; virtual ~ICowWriter() {} // Encode an operation that copies the contents of |old_block| to the Loading Loading @@ -93,6 +95,17 @@ class ICowWriter { virtual uint32_t GetBlockSize() const = 0; virtual std::optional<uint32_t> GetMaxBlocks() const = 0; // Open an ICowReader for this writer. The reader will be a snapshot of the // current operations in the writer; new writes after OpenReader() will not // be reflected. virtual std::unique_ptr<ICowReader> OpenReader() = 0; // Open a file descriptor. This allows reading and seeing through the cow // as if it were a normal file. The optional source_device must be a valid // path if the CowReader contains any copy or xor operations. virtual std::unique_ptr<FileDescriptor> OpenFileDescriptor( const std::optional<std::string>& source_device) = 0; }; class CompressWorker { Loading fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot_writer.h→fs_mgr/libsnapshot/include/libsnapshot/mock_cow_writer.h +8 −8 Original line number Diff line number Diff line Loading @@ -15,17 +15,16 @@ // #include <gmock/gmock.h> #include <libsnapshot/snapshot_writer.h> #include <libsnapshot/cow_writer.h> namespace android::snapshot { class MockSnapshotWriter : public ISnapshotWriter { class MockCowWriter : public ICowWriter { public: using FileDescriptor = ISnapshotWriter::FileDescriptor; using FileDescriptor = chromeos_update_engine::FileDescriptor; MOCK_METHOD(bool, Finalize, (), (override)); // Return number of bytes the cow image occupies on disk. MOCK_METHOD(uint64_t, GetCowSize, (), (override)); MOCK_METHOD(bool, AddCopy, (uint64_t, uint64_t, uint64_t), (override)); Loading @@ -35,11 +34,12 @@ class MockSnapshotWriter : public ISnapshotWriter { MOCK_METHOD(bool, AddZeroBlocks, (uint64_t, uint64_t), (override)); MOCK_METHOD(bool, AddLabel, (uint64_t), (override)); MOCK_METHOD(bool, AddSequenceData, (size_t, const uint32_t*), (override)); MOCK_METHOD(bool, Initialize, (), (override)); MOCK_METHOD(bool, InitializeAppend, (uint64_t), (override)); MOCK_METHOD(bool, VerifyMergeOps, (), (override, const, noexcept)); MOCK_METHOD(std::unique_ptr<FileDescriptor>, OpenReader, (), (override)); MOCK_METHOD(uint32_t, GetBlockSize, (), (override, const)); MOCK_METHOD(std::optional<uint32_t>, GetMaxBlocks, (), (override, const)); MOCK_METHOD(std::unique_ptr<ICowReader>, OpenReader, (), (override)); MOCK_METHOD(std::unique_ptr<FileDescriptor>, OpenFileDescriptor, (const std::optional<std::string>&), (override)); }; } // namespace android::snapshot fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot.h +2 −2 Original line number Diff line number Diff line Loading @@ -42,9 +42,9 @@ class MockSnapshotManager : public ISnapshotManager { (const android::fs_mgr::CreateLogicalPartitionParams& params, std::string* snapshot_path), (override)); MOCK_METHOD(std::unique_ptr<ISnapshotWriter>, OpenSnapshotWriter, MOCK_METHOD(std::unique_ptr<ICowWriter>, OpenSnapshotWriter, (const android::fs_mgr::CreateLogicalPartitionParams& params, const std::optional<std::string>&), std::optional<uint64_t>), (override)); MOCK_METHOD(bool, UnmapUpdateSnapshot, (const std::string& target_partition_name), (override)); MOCK_METHOD(bool, NeedSnapshotsInFirstStageMount, (), (override)); Loading Loading
fs_mgr/libsnapshot/Android.bp +5 −4 Original line number Diff line number Diff line Loading @@ -85,11 +85,9 @@ filegroup { "android/snapshot/snapshot.proto", "device_info.cpp", "snapshot.cpp", "snapshot_reader.cpp", "snapshot_stats.cpp", "snapshot_stub.cpp", "snapshot_metadata_updater.cpp", "snapshot_writer.cpp", "partition_cow_creator.cpp", "return.cpp", "utility.cpp", Loading Loading @@ -165,6 +163,9 @@ cc_defaults { "liblz4", "libzstd", ], header_libs: [ "libupdate_engine_headers", ], export_include_dirs: ["include"], } Loading @@ -179,6 +180,7 @@ cc_library_static { "libsnapshot_cow/cow_format.cpp", "libsnapshot_cow/cow_reader.cpp", "libsnapshot_cow/parser_v2.cpp", "libsnapshot_cow/snapshot_reader.cpp", "libsnapshot_cow/writer_base.cpp", "libsnapshot_cow/writer_v2.cpp", ], Loading Loading @@ -224,9 +226,7 @@ cc_defaults { srcs: [ "partition_cow_creator_test.cpp", "snapshot_metadata_updater_test.cpp", "snapshot_reader_test.cpp", "snapshot_test.cpp", "snapshot_writer_test.cpp", ], shared_libs: [ "libbinder", Loading Loading @@ -372,6 +372,7 @@ cc_test { "libsnapshot_cow_defaults", ], srcs: [ "libsnapshot_cow/snapshot_reader_test.cpp", "libsnapshot_cow/test_v2.cpp", ], cflags: [ Loading
fs_mgr/libsnapshot/include/libsnapshot/cow_reader.h +7 −2 Original line number Diff line number Diff line Loading @@ -24,6 +24,10 @@ #include <android-base/unique_fd.h> #include <libsnapshot/cow_format.h> namespace chromeos_update_engine { class FileDescriptor; } // namespace chromeos_update_engine namespace android { namespace snapshot { Loading @@ -32,6 +36,8 @@ class ICowOpIter; // Interface for reading from a snapuserd COW. class ICowReader { public: using FileDescriptor = chromeos_update_engine::FileDescriptor; virtual ~ICowReader() {} // Return the file header. Loading Loading @@ -109,10 +115,9 @@ class CowReader final : public ICowReader { bool Parse(android::base::borrowed_fd fd, std::optional<uint64_t> label = {}); bool InitForMerge(android::base::unique_fd&& fd); bool VerifyMergeOps() override; bool VerifyMergeOps() override; bool GetFooter(CowFooter* footer) override; bool GetLastLabel(uint64_t* label) override; // Create a CowOpIter object which contains footer_.num_ops Loading
fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h +13 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,8 @@ struct CowOptions { // will occur in the sequence they were added to the COW. class ICowWriter { public: using FileDescriptor = chromeos_update_engine::FileDescriptor; virtual ~ICowWriter() {} // Encode an operation that copies the contents of |old_block| to the Loading Loading @@ -93,6 +95,17 @@ class ICowWriter { virtual uint32_t GetBlockSize() const = 0; virtual std::optional<uint32_t> GetMaxBlocks() const = 0; // Open an ICowReader for this writer. The reader will be a snapshot of the // current operations in the writer; new writes after OpenReader() will not // be reflected. virtual std::unique_ptr<ICowReader> OpenReader() = 0; // Open a file descriptor. This allows reading and seeing through the cow // as if it were a normal file. The optional source_device must be a valid // path if the CowReader contains any copy or xor operations. virtual std::unique_ptr<FileDescriptor> OpenFileDescriptor( const std::optional<std::string>& source_device) = 0; }; class CompressWorker { Loading
fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot_writer.h→fs_mgr/libsnapshot/include/libsnapshot/mock_cow_writer.h +8 −8 Original line number Diff line number Diff line Loading @@ -15,17 +15,16 @@ // #include <gmock/gmock.h> #include <libsnapshot/snapshot_writer.h> #include <libsnapshot/cow_writer.h> namespace android::snapshot { class MockSnapshotWriter : public ISnapshotWriter { class MockCowWriter : public ICowWriter { public: using FileDescriptor = ISnapshotWriter::FileDescriptor; using FileDescriptor = chromeos_update_engine::FileDescriptor; MOCK_METHOD(bool, Finalize, (), (override)); // Return number of bytes the cow image occupies on disk. MOCK_METHOD(uint64_t, GetCowSize, (), (override)); MOCK_METHOD(bool, AddCopy, (uint64_t, uint64_t, uint64_t), (override)); Loading @@ -35,11 +34,12 @@ class MockSnapshotWriter : public ISnapshotWriter { MOCK_METHOD(bool, AddZeroBlocks, (uint64_t, uint64_t), (override)); MOCK_METHOD(bool, AddLabel, (uint64_t), (override)); MOCK_METHOD(bool, AddSequenceData, (size_t, const uint32_t*), (override)); MOCK_METHOD(bool, Initialize, (), (override)); MOCK_METHOD(bool, InitializeAppend, (uint64_t), (override)); MOCK_METHOD(bool, VerifyMergeOps, (), (override, const, noexcept)); MOCK_METHOD(std::unique_ptr<FileDescriptor>, OpenReader, (), (override)); MOCK_METHOD(uint32_t, GetBlockSize, (), (override, const)); MOCK_METHOD(std::optional<uint32_t>, GetMaxBlocks, (), (override, const)); MOCK_METHOD(std::unique_ptr<ICowReader>, OpenReader, (), (override)); MOCK_METHOD(std::unique_ptr<FileDescriptor>, OpenFileDescriptor, (const std::optional<std::string>&), (override)); }; } // namespace android::snapshot
fs_mgr/libsnapshot/include/libsnapshot/mock_snapshot.h +2 −2 Original line number Diff line number Diff line Loading @@ -42,9 +42,9 @@ class MockSnapshotManager : public ISnapshotManager { (const android::fs_mgr::CreateLogicalPartitionParams& params, std::string* snapshot_path), (override)); MOCK_METHOD(std::unique_ptr<ISnapshotWriter>, OpenSnapshotWriter, MOCK_METHOD(std::unique_ptr<ICowWriter>, OpenSnapshotWriter, (const android::fs_mgr::CreateLogicalPartitionParams& params, const std::optional<std::string>&), std::optional<uint64_t>), (override)); MOCK_METHOD(bool, UnmapUpdateSnapshot, (const std::string& target_partition_name), (override)); MOCK_METHOD(bool, NeedSnapshotsInFirstStageMount, (), (override)); Loading