Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Alex Deymo | 477aec2 | 2015-03-24 23:40:48 -0700 | [diff] [blame] | 16 | |
| 17 | #include "update_engine/payload_generator/annotated_operation.h" |
| 18 | |
| 19 | #include <base/format_macros.h> |
| 20 | #include <base/strings/string_number_conversions.h> |
| 21 | #include <base/strings/stringprintf.h> |
| 22 | |
Alex Deymo | 2d621a3 | 2015-10-01 11:09:01 -0700 | [diff] [blame] | 23 | #include "update_engine/payload_constants.h" |
Gilad Arnold | 41e3474 | 2015-05-11 11:31:50 -0700 | [diff] [blame] | 24 | #include "update_engine/utils.h" |
| 25 | |
Alex Deymo | 477aec2 | 2015-03-24 23:40:48 -0700 | [diff] [blame] | 26 | namespace chromeos_update_engine { |
| 27 | |
| 28 | namespace { |
| 29 | // Output the list of extents as (start_block, num_blocks) in the passed output |
| 30 | // stream. |
| 31 | void OutputExtents(std::ostream* os, |
| 32 | const google::protobuf::RepeatedPtrField<Extent>& extents) { |
| 33 | for (const auto& extent : extents) { |
| 34 | *os << " (" << extent.start_block() << ", " << extent.num_blocks() << ")"; |
| 35 | } |
| 36 | } |
| 37 | } // namespace |
| 38 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 39 | bool AnnotatedOperation::SetOperationBlob(brillo::Blob* blob, |
Sen Jiang | 8cc502d | 2015-08-10 10:04:54 -0700 | [diff] [blame] | 40 | BlobFileWriter* blob_file) { |
Sen Jiang | 8cc502d | 2015-08-10 10:04:54 -0700 | [diff] [blame] | 41 | off_t data_offset = blob_file->StoreBlob(*blob); |
Sen Jiang | 5456c19 | 2015-08-19 15:01:16 -0700 | [diff] [blame] | 42 | TEST_AND_RETURN_FALSE(data_offset != -1); |
Sen Jiang | 8cc502d | 2015-08-10 10:04:54 -0700 | [diff] [blame] | 43 | op.set_data_offset(data_offset); |
Sen Jiang | 5456c19 | 2015-08-19 15:01:16 -0700 | [diff] [blame] | 44 | op.set_data_length(blob->size()); |
Gilad Arnold | 41e3474 | 2015-05-11 11:31:50 -0700 | [diff] [blame] | 45 | return true; |
| 46 | } |
| 47 | |
Alex Deymo | 477aec2 | 2015-03-24 23:40:48 -0700 | [diff] [blame] | 48 | std::ostream& operator<<(std::ostream& os, const AnnotatedOperation& aop) { |
| 49 | // For example, this prints: |
| 50 | // REPLACE_BZ 500 @3000 |
| 51 | // name: /foo/bar |
| 52 | // dst: (123, 3) (127, 2) |
| 53 | os << InstallOperationTypeName(aop.op.type()) << " " << aop.op.data_length(); |
| 54 | if (aop.op.data_length() > 0) |
| 55 | os << " @" << aop.op.data_offset(); |
| 56 | if (!aop.name.empty()) { |
| 57 | os << std::endl << " name: " << aop.name; |
| 58 | } |
| 59 | if (aop.op.src_extents_size() != 0) { |
| 60 | os << std::endl << " src:"; |
| 61 | OutputExtents(&os, aop.op.src_extents()); |
| 62 | } |
| 63 | if (aop.op.dst_extents_size() != 0) { |
| 64 | os << std::endl << " dst:"; |
| 65 | OutputExtents(&os, aop.op.dst_extents()); |
| 66 | } |
| 67 | return os; |
| 68 | } |
| 69 | |
| 70 | } // namespace chromeos_update_engine |