blob: dcb8bf87fa0505be92b4c57aa0840831a0edbfb3 [file] [log] [blame]
Alex Deymo5c6c6552015-06-03 19:06:50 +02001// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "update_engine/payload_generator/extent_utils.h"
6
7#include <string>
8#include <utility>
9#include <vector>
10
11#include <base/logging.h>
12#include <base/macros.h>
13
14#include "update_engine/payload_constants.h"
15#include "update_engine/payload_generator/annotated_operation.h"
16
17using std::string;
18using std::vector;
19
20namespace chromeos_update_engine {
21
22void AppendBlockToExtents(vector<Extent>* extents, uint64_t block) {
23 // First try to extend the last extent in |extents|, if any.
24 if (!extents->empty()) {
25 Extent& extent = extents->back();
26 uint64_t next_block = extent.start_block() == kSparseHole ?
27 kSparseHole : extent.start_block() + extent.num_blocks();
28 if (next_block == block) {
29 extent.set_num_blocks(extent.num_blocks() + 1);
30 return;
31 }
32 }
33 // If unable to extend the last extent, append a new single-block extent.
34 Extent new_extent;
35 new_extent.set_start_block(block);
36 new_extent.set_num_blocks(1);
37 extents->push_back(new_extent);
38}
39
40Extent GetElement(const vector<Extent>& collection, size_t index) {
41 return collection[index];
42}
43Extent GetElement(
44 const google::protobuf::RepeatedPtrField<Extent>& collection,
45 size_t index) {
46 return collection.Get(index);
47}
48
49bool operator==(const Extent& a, const Extent& b) {
50 return a.start_block() == b.start_block() && a.num_blocks() == b.num_blocks();
51}
52
53} // namespace chromeos_update_engine