• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2017 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 //
16 
17 #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_DEFLATE_UTILS_H_
18 #define UPDATE_ENGINE_PAYLOAD_GENERATOR_DEFLATE_UTILS_H_
19 
20 #include <puffin/puffdiff.h>
21 #include <vector>
22 
23 #include "update_engine/payload_generator/filesystem_interface.h"
24 #include "update_engine/payload_generator/payload_generation_config.h"
25 
26 namespace chromeos_update_engine {
27 namespace deflate_utils {
28 
29 // Gets the files from the partition and processes all its files. Processing
30 // includes:
31 //  - splitting large Squashfs containers into its smaller files.
32 bool PreprocessParitionFiles(const PartitionConfig& part,
33                              std::vector<FilesystemInterface::File>* result,
34                              bool extract_deflates);
35 
36 // Spreads all extents in |over_extents| over |base_extents|. Here we assume the
37 // |over_extents| are non-overlapping and sorted by their offset.
38 //
39 // |base_extents|:
40 // |               -----------------------        ------         --------------
41 // |over_extents|:
42 // |  ==========  ====    ==========  ======
43 // |over_extents| is transforms to:
44 // |                 ==========  ====    =        ======         ===  ======
45 //
46 bool ShiftExtentsOverExtents(const std::vector<Extent>& base_extents,
47                              std::vector<Extent>* over_extents);
48 
49 // Spreads all extents in |over_extents| over |base_extents|. Here we assume the
50 // |over_extents| are non-overlapping and sorted by their offset. An item in
51 // |over_extents| is removed if it is spread in two or more extents in
52 // |base_extents|.
53 //
54 // |base_extents|:
55 // |               -----------------------        ------         --------------
56 // |over_extents|:
57 // |  ==========  ====    ==========  ======
58 // |over_extents| is transforms to:
59 // |                 ==========  ====                                 ======
60 //
61 bool ShiftBitExtentsOverExtents(const std::vector<Extent>& base_extents,
62                                 std::vector<puffin::BitExtent>* over_extents);
63 
64 // Finds all deflate locations in |deflates| that are inside an Extent in
65 // |extents|. This function should not change the order of deflates.
66 std::vector<puffin::BitExtent> FindDeflates(
67     const std::vector<Extent>& extents,
68     const std::vector<puffin::BitExtent>& deflates);
69 
70 // Creates a new list of deflate locations (|out_deflates|) from |in_deflates|
71 // by assuming all extents in the |extents| have been put together
72 // linearly. This function assumes that all deflate locations given in
73 // |in_deflates| are located somewhere in the |extents|. |out_deflates| should
74 // be empty on call.
75 //
76 // |extents|:
77 // |               -----------------------        ------         --------------
78 // |in_deflates|:
79 // |                   ========  ====              ====           ======
80 // |out_deflates|:
81 // |    ========  ====      ====  ======
82 //
83 bool CompactDeflates(const std::vector<Extent>& extents,
84                      const std::vector<puffin::BitExtent>& in_deflates,
85                      std::vector<puffin::BitExtent>* out_deflates);
86 
87 // Combines |FindDeflates| and |CompcatDeflates| for ease of use.
88 bool FindAndCompactDeflates(const std::vector<Extent>& extents,
89                             const std::vector<puffin::BitExtent>& in_deflates,
90                             std::vector<puffin::BitExtent>* out_deflates);
91 
92 // Expands a BitExtents to a ByteExtent.
93 puffin::ByteExtent ExpandToByteExtent(const puffin::BitExtent& extent);
94 
95 }  // namespace deflate_utils
96 }  // namespace chromeos_update_engine
97 #endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_DEFLATE_UTILS_H_
98