blob: 9b40a4748d1455b78f229259ed66d905e93b936a [file] [log] [blame]
Amin Hassani924183b2017-09-27 14:50:59 -07001//
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
Amin Hassani3cd4df12017-08-25 11:21:53 -070020#include <puffin/puffdiff.h>
Amin Hassani924183b2017-09-27 14:50:59 -070021#include <vector>
22
23#include "update_engine/payload_generator/filesystem_interface.h"
24#include "update_engine/payload_generator/payload_generation_config.h"
25
26namespace chromeos_update_engine {
27namespace deflate_utils {
28
Amin Hassani3cd4df12017-08-25 11:21:53 -070029// Gets the files from the partition and processes all its files. Processing
30// includes:
31// - splitting large Squashfs containers into its smaller files.
Sen Jiang23bae402018-11-13 11:27:29 -080032// - extracting deflates in zip and gzip files.
Amin Hassani3cd4df12017-08-25 11:21:53 -070033bool PreprocessParitionFiles(const PartitionConfig& part,
34 std::vector<FilesystemInterface::File>* result,
35 bool extract_deflates);
36
Amin Hassani924183b2017-09-27 14:50:59 -070037// Spreads all extents in |over_extents| over |base_extents|. Here we assume the
Amin Hassani3cd4df12017-08-25 11:21:53 -070038// |over_extents| are non-overlapping and sorted by their offset.
Amin Hassani924183b2017-09-27 14:50:59 -070039//
40// |base_extents|:
41// | ----------------------- ------ --------------
42// |over_extents|:
43// | ========== ==== ========== ======
44// |over_extents| is transforms to:
45// | ========== ==== = ====== === ======
46//
47bool ShiftExtentsOverExtents(const std::vector<Extent>& base_extents,
48 std::vector<Extent>* over_extents);
49
Amin Hassani3cd4df12017-08-25 11:21:53 -070050// Spreads all extents in |over_extents| over |base_extents|. Here we assume the
51// |over_extents| are non-overlapping and sorted by their offset. An item in
52// |over_extents| is removed if it is spread in two or more extents in
53// |base_extents|.
54//
55// |base_extents|:
56// | ----------------------- ------ --------------
57// |over_extents|:
58// | ========== ==== ========== ======
59// |over_extents| is transforms to:
60// | ========== ==== ======
61//
62bool ShiftBitExtentsOverExtents(const std::vector<Extent>& base_extents,
63 std::vector<puffin::BitExtent>* over_extents);
64
65// Finds all deflate locations in |deflates| that are inside an Extent in
66// |extents|. This function should not change the order of deflates.
67std::vector<puffin::BitExtent> FindDeflates(
68 const std::vector<Extent>& extents,
69 const std::vector<puffin::BitExtent>& deflates);
70
71// Creates a new list of deflate locations (|out_deflates|) from |in_deflates|
72// by assuming all extents in the |extents| have been put together
73// linearly. This function assumes that all deflate locations given in
74// |in_deflates| are located somewhere in the |extents|. |out_deflates| should
75// be empty on call.
76//
77// |extents|:
78// | ----------------------- ------ --------------
79// |in_deflates|:
80// | ======== ==== ==== ======
81// |out_deflates|:
82// | ======== ==== ==== ======
83//
84bool CompactDeflates(const std::vector<Extent>& extents,
85 const std::vector<puffin::BitExtent>& in_deflates,
86 std::vector<puffin::BitExtent>* out_deflates);
87
88// Combines |FindDeflates| and |CompcatDeflates| for ease of use.
89bool FindAndCompactDeflates(const std::vector<Extent>& extents,
90 const std::vector<puffin::BitExtent>& in_deflates,
91 std::vector<puffin::BitExtent>* out_deflates);
92
93// Expands a BitExtents to a ByteExtent.
94puffin::ByteExtent ExpandToByteExtent(const puffin::BitExtent& extent);
Amin Hassani924183b2017-09-27 14:50:59 -070095
96} // namespace deflate_utils
97} // namespace chromeos_update_engine
98#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_DEFLATE_UTILS_H_