| Amin Hassani | 924183b | 2017-09-27 14:50:59 -0700 | [diff] [blame] | 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 |  | 
| Colin Cross | 26b82b1 | 2021-12-22 10:09:19 -0800 | [diff] [blame] | 20 | #include <string> | 
| Amin Hassani | 924183b | 2017-09-27 14:50:59 -0700 | [diff] [blame] | 21 | #include <vector> | 
|  | 22 |  | 
| Colin Cross | 26b82b1 | 2021-12-22 10:09:19 -0800 | [diff] [blame] | 23 | #include <puffin/puffdiff.h> | 
|  | 24 |  | 
| Amin Hassani | 924183b | 2017-09-27 14:50:59 -0700 | [diff] [blame] | 25 | #include "update_engine/payload_generator/filesystem_interface.h" | 
|  | 26 | #include "update_engine/payload_generator/payload_generation_config.h" | 
|  | 27 |  | 
|  | 28 | namespace chromeos_update_engine { | 
|  | 29 | namespace deflate_utils { | 
|  | 30 |  | 
| Amin Hassani | 3cd4df1 | 2017-08-25 11:21:53 -0700 | [diff] [blame] | 31 | // Gets the files from the partition and processes all its files. Processing | 
|  | 32 | // includes: | 
|  | 33 | //  - splitting large Squashfs containers into its smaller files. | 
| Sen Jiang | 23bae40 | 2018-11-13 11:27:29 -0800 | [diff] [blame] | 34 | //  - extracting deflates in zip and gzip files. | 
| Sen Jiang | ce39e67 | 2018-11-28 16:43:00 -0800 | [diff] [blame] | 35 | bool PreprocessPartitionFiles(const PartitionConfig& part, | 
|  | 36 | std::vector<FilesystemInterface::File>* result, | 
|  | 37 | bool extract_deflates); | 
| Amin Hassani | 3cd4df1 | 2017-08-25 11:21:53 -0700 | [diff] [blame] | 38 |  | 
| Amin Hassani | 924183b | 2017-09-27 14:50:59 -0700 | [diff] [blame] | 39 | // Spreads all extents in |over_extents| over |base_extents|. Here we assume the | 
| Amin Hassani | 3cd4df1 | 2017-08-25 11:21:53 -0700 | [diff] [blame] | 40 | // |over_extents| are non-overlapping and sorted by their offset. | 
| Amin Hassani | 924183b | 2017-09-27 14:50:59 -0700 | [diff] [blame] | 41 | // | 
|  | 42 | // |base_extents|: | 
|  | 43 | // |               -----------------------        ------         -------------- | 
|  | 44 | // |over_extents|: | 
|  | 45 | // |  ==========  ====    ==========  ====== | 
|  | 46 | // |over_extents| is transforms to: | 
|  | 47 | // |                 ==========  ====    =        ======         ===  ====== | 
|  | 48 | // | 
|  | 49 | bool ShiftExtentsOverExtents(const std::vector<Extent>& base_extents, | 
|  | 50 | std::vector<Extent>* over_extents); | 
|  | 51 |  | 
| Amin Hassani | 3cd4df1 | 2017-08-25 11:21:53 -0700 | [diff] [blame] | 52 | // Spreads all extents in |over_extents| over |base_extents|. Here we assume the | 
|  | 53 | // |over_extents| are non-overlapping and sorted by their offset. An item in | 
|  | 54 | // |over_extents| is removed if it is spread in two or more extents in | 
|  | 55 | // |base_extents|. | 
|  | 56 | // | 
|  | 57 | // |base_extents|: | 
|  | 58 | // |               -----------------------        ------         -------------- | 
|  | 59 | // |over_extents|: | 
|  | 60 | // |  ==========  ====    ==========  ====== | 
|  | 61 | // |over_extents| is transforms to: | 
|  | 62 | // |                 ==========  ====                                 ====== | 
|  | 63 | // | 
|  | 64 | bool ShiftBitExtentsOverExtents(const std::vector<Extent>& base_extents, | 
|  | 65 | std::vector<puffin::BitExtent>* over_extents); | 
|  | 66 |  | 
|  | 67 | // Finds all deflate locations in |deflates| that are inside an Extent in | 
|  | 68 | // |extents|. This function should not change the order of deflates. | 
|  | 69 | std::vector<puffin::BitExtent> FindDeflates( | 
|  | 70 | const std::vector<Extent>& extents, | 
|  | 71 | const std::vector<puffin::BitExtent>& deflates); | 
|  | 72 |  | 
|  | 73 | // Creates a new list of deflate locations (|out_deflates|) from |in_deflates| | 
|  | 74 | // by assuming all extents in the |extents| have been put together | 
|  | 75 | // linearly. This function assumes that all deflate locations given in | 
|  | 76 | // |in_deflates| are located somewhere in the |extents|. |out_deflates| should | 
|  | 77 | // be empty on call. | 
|  | 78 | // | 
|  | 79 | // |extents|: | 
|  | 80 | // |               -----------------------        ------         -------------- | 
|  | 81 | // |in_deflates|: | 
|  | 82 | // |                   ========  ====              ====           ====== | 
|  | 83 | // |out_deflates|: | 
|  | 84 | // |    ========  ====      ====  ====== | 
|  | 85 | // | 
|  | 86 | bool CompactDeflates(const std::vector<Extent>& extents, | 
|  | 87 | const std::vector<puffin::BitExtent>& in_deflates, | 
|  | 88 | std::vector<puffin::BitExtent>* out_deflates); | 
|  | 89 |  | 
|  | 90 | // Combines |FindDeflates| and |CompcatDeflates| for ease of use. | 
|  | 91 | bool FindAndCompactDeflates(const std::vector<Extent>& extents, | 
|  | 92 | const std::vector<puffin::BitExtent>& in_deflates, | 
|  | 93 | std::vector<puffin::BitExtent>* out_deflates); | 
|  | 94 |  | 
|  | 95 | // Expands a BitExtents to a ByteExtent. | 
|  | 96 | puffin::ByteExtent ExpandToByteExtent(const puffin::BitExtent& extent); | 
| Amin Hassani | 924183b | 2017-09-27 14:50:59 -0700 | [diff] [blame] | 97 |  | 
| Kelvin Zhang | cb2dc88 | 2021-11-22 09:26:50 -0800 | [diff] [blame] | 98 | bool IsFileExtensions( | 
|  | 99 | const std::string_view name, | 
|  | 100 | const std::initializer_list<std::string_view>& extensions); | 
|  | 101 |  | 
|  | 102 | bool DeflatePreprocessFileData(const std::string_view filename, | 
|  | 103 | const brillo::Blob& data, | 
|  | 104 | std::vector<puffin::BitExtent>* deflates); | 
| Kelvin Zhang | 0af0122 | 2021-10-05 13:36:47 -0700 | [diff] [blame] | 105 |  | 
| Amin Hassani | 924183b | 2017-09-27 14:50:59 -0700 | [diff] [blame] | 106 | }  // namespace deflate_utils | 
|  | 107 | }  // namespace chromeos_update_engine | 
|  | 108 | #endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_DEFLATE_UTILS_H_ |