Loading fs_mgr/libsnapshot/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ filegroup { "snapshot.cpp", "snapshot_metadata_updater.cpp", "partition_cow_creator.cpp", "return.cpp", "utility.cpp", ], } Loading fs_mgr/libsnapshot/include/libsnapshot/return.h 0 → 100644 +59 −0 Original line number Diff line number Diff line // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include <stdint.h> #include <string.h> #include <libfiemap/fiemap_status.h> namespace android::snapshot { // SnapshotManager functions return either bool or Return objects. "Return" types provides // more information about the reason of the failure. class Return { using FiemapStatus = android::fiemap::FiemapStatus; public: enum class ErrorCode : int32_t { SUCCESS = static_cast<int32_t>(FiemapStatus::ErrorCode::SUCCESS), ERROR = static_cast<int32_t>(FiemapStatus::ErrorCode::ERROR), NO_SPACE = static_cast<int32_t>(FiemapStatus::ErrorCode::NO_SPACE), }; ErrorCode error_code() const { return error_code_; } bool is_ok() const { return error_code() == ErrorCode::SUCCESS; } operator bool() const { return is_ok(); } // Total required size on /userdata. uint64_t required_size() const { return required_size_; } std::string string() const; static Return Ok() { return Return(ErrorCode::SUCCESS); } static Return Error() { return Return(ErrorCode::ERROR); } static Return NoSpace(uint64_t size) { return Return(ErrorCode::NO_SPACE, size); } // Does not set required_size_ properly even when status.error_code() == NO_SPACE. explicit Return(const FiemapStatus& status) : error_code_(FromFiemapStatusErrorCode(status.error_code())), required_size_(0) {} private: ErrorCode error_code_; uint64_t required_size_; Return(ErrorCode error_code, uint64_t required_size = 0) : error_code_(error_code), required_size_(required_size) {} // FiemapStatus::ErrorCode -> ErrorCode static ErrorCode FromFiemapStatusErrorCode(FiemapStatus::ErrorCode error_code); }; } // namespace android::snapshot fs_mgr/libsnapshot/include/libsnapshot/snapshot.h +1 −21 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ #include <update_engine/update_metadata.pb.h> #include <libsnapshot/auto_device.h> #include <libsnapshot/return.h> #ifndef FRIEND_TEST #define FRIEND_TEST(test_set_name, individual_test) \ Loading Loading @@ -91,27 +92,6 @@ class SnapshotManager final { using FiemapStatus = android::fiemap::FiemapStatus; public: // SnapshotManager functions return either bool or Return objects. "Return" types provides // more information about the reason of the failure. class Return : public FiemapStatus { public: // Total required size on /userdata. uint64_t required_size() const { return required_size_; } static Return Ok() { return Return(FiemapStatus::ErrorCode::SUCCESS); } static Return Error() { return Return(FiemapStatus::ErrorCode::ERROR); } static Return NoSpace(uint64_t size) { return Return(FiemapStatus::ErrorCode::NO_SPACE, size); } // Does not set required_size_ properly even when status.error_code() == NO_SPACE. explicit Return(const FiemapStatus& status) : Return(status.error_code()) {} private: uint64_t required_size_; Return(FiemapStatus::ErrorCode code, uint64_t required_size = 0) : FiemapStatus(code), required_size_(required_size) {} }; // Dependency injection for testing. class IDeviceInfo { public: Loading fs_mgr/libsnapshot/include_test/libsnapshot/test_helpers.h +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ using chromeos_update_engine::PartitionUpdate; using testing::_; using testing::AssertionResult; using testing::NiceMock; using testing::Return; using namespace android::storage_literals; using namespace std::string_literals; Loading Loading @@ -117,6 +116,7 @@ class TestDeviceInfo : public SnapshotManager::IDeviceInfo { class SnapshotTestPropertyFetcher : public android::fs_mgr::testing::MockPropertyFetcher { public: SnapshotTestPropertyFetcher(const std::string& slot_suffix) { using testing::Return; ON_CALL(*this, GetProperty("ro.boot.slot_suffix", _)).WillByDefault(Return(slot_suffix)); ON_CALL(*this, GetBoolProperty("ro.boot.dynamic_partitions", _)) .WillByDefault(Return(true)); Loading fs_mgr/libsnapshot/return.cpp 0 → 100644 +44 −0 Original line number Diff line number Diff line // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <libsnapshot/return.h> #include <string.h> using android::fiemap::FiemapStatus; namespace android::snapshot { std::string Return::string() const { switch (error_code()) { case ErrorCode::ERROR: return "Error"; case ErrorCode::SUCCESS: [[fallthrough]]; case ErrorCode::NO_SPACE: return strerror(-static_cast<int>(error_code())); } } Return::ErrorCode Return::FromFiemapStatusErrorCode(FiemapStatus::ErrorCode error_code) { switch (error_code) { case FiemapStatus::ErrorCode::SUCCESS: case FiemapStatus::ErrorCode::ERROR: case FiemapStatus::ErrorCode::NO_SPACE: return static_cast<ErrorCode>(error_code); default: return ErrorCode::ERROR; } } } // namespace android::snapshot Loading
fs_mgr/libsnapshot/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ filegroup { "snapshot.cpp", "snapshot_metadata_updater.cpp", "partition_cow_creator.cpp", "return.cpp", "utility.cpp", ], } Loading
fs_mgr/libsnapshot/include/libsnapshot/return.h 0 → 100644 +59 −0 Original line number Diff line number Diff line // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include <stdint.h> #include <string.h> #include <libfiemap/fiemap_status.h> namespace android::snapshot { // SnapshotManager functions return either bool or Return objects. "Return" types provides // more information about the reason of the failure. class Return { using FiemapStatus = android::fiemap::FiemapStatus; public: enum class ErrorCode : int32_t { SUCCESS = static_cast<int32_t>(FiemapStatus::ErrorCode::SUCCESS), ERROR = static_cast<int32_t>(FiemapStatus::ErrorCode::ERROR), NO_SPACE = static_cast<int32_t>(FiemapStatus::ErrorCode::NO_SPACE), }; ErrorCode error_code() const { return error_code_; } bool is_ok() const { return error_code() == ErrorCode::SUCCESS; } operator bool() const { return is_ok(); } // Total required size on /userdata. uint64_t required_size() const { return required_size_; } std::string string() const; static Return Ok() { return Return(ErrorCode::SUCCESS); } static Return Error() { return Return(ErrorCode::ERROR); } static Return NoSpace(uint64_t size) { return Return(ErrorCode::NO_SPACE, size); } // Does not set required_size_ properly even when status.error_code() == NO_SPACE. explicit Return(const FiemapStatus& status) : error_code_(FromFiemapStatusErrorCode(status.error_code())), required_size_(0) {} private: ErrorCode error_code_; uint64_t required_size_; Return(ErrorCode error_code, uint64_t required_size = 0) : error_code_(error_code), required_size_(required_size) {} // FiemapStatus::ErrorCode -> ErrorCode static ErrorCode FromFiemapStatusErrorCode(FiemapStatus::ErrorCode error_code); }; } // namespace android::snapshot
fs_mgr/libsnapshot/include/libsnapshot/snapshot.h +1 −21 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ #include <update_engine/update_metadata.pb.h> #include <libsnapshot/auto_device.h> #include <libsnapshot/return.h> #ifndef FRIEND_TEST #define FRIEND_TEST(test_set_name, individual_test) \ Loading Loading @@ -91,27 +92,6 @@ class SnapshotManager final { using FiemapStatus = android::fiemap::FiemapStatus; public: // SnapshotManager functions return either bool or Return objects. "Return" types provides // more information about the reason of the failure. class Return : public FiemapStatus { public: // Total required size on /userdata. uint64_t required_size() const { return required_size_; } static Return Ok() { return Return(FiemapStatus::ErrorCode::SUCCESS); } static Return Error() { return Return(FiemapStatus::ErrorCode::ERROR); } static Return NoSpace(uint64_t size) { return Return(FiemapStatus::ErrorCode::NO_SPACE, size); } // Does not set required_size_ properly even when status.error_code() == NO_SPACE. explicit Return(const FiemapStatus& status) : Return(status.error_code()) {} private: uint64_t required_size_; Return(FiemapStatus::ErrorCode code, uint64_t required_size = 0) : FiemapStatus(code), required_size_(required_size) {} }; // Dependency injection for testing. class IDeviceInfo { public: Loading
fs_mgr/libsnapshot/include_test/libsnapshot/test_helpers.h +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ using chromeos_update_engine::PartitionUpdate; using testing::_; using testing::AssertionResult; using testing::NiceMock; using testing::Return; using namespace android::storage_literals; using namespace std::string_literals; Loading Loading @@ -117,6 +116,7 @@ class TestDeviceInfo : public SnapshotManager::IDeviceInfo { class SnapshotTestPropertyFetcher : public android::fs_mgr::testing::MockPropertyFetcher { public: SnapshotTestPropertyFetcher(const std::string& slot_suffix) { using testing::Return; ON_CALL(*this, GetProperty("ro.boot.slot_suffix", _)).WillByDefault(Return(slot_suffix)); ON_CALL(*this, GetBoolProperty("ro.boot.dynamic_partitions", _)) .WillByDefault(Return(true)); Loading
fs_mgr/libsnapshot/return.cpp 0 → 100644 +44 −0 Original line number Diff line number Diff line // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include <libsnapshot/return.h> #include <string.h> using android::fiemap::FiemapStatus; namespace android::snapshot { std::string Return::string() const { switch (error_code()) { case ErrorCode::ERROR: return "Error"; case ErrorCode::SUCCESS: [[fallthrough]]; case ErrorCode::NO_SPACE: return strerror(-static_cast<int>(error_code())); } } Return::ErrorCode Return::FromFiemapStatusErrorCode(FiemapStatus::ErrorCode error_code) { switch (error_code) { case FiemapStatus::ErrorCode::SUCCESS: case FiemapStatus::ErrorCode::ERROR: case FiemapStatus::ErrorCode::NO_SPACE: return static_cast<ErrorCode>(error_code); default: return ErrorCode::ERROR; } } } // namespace android::snapshot