payload_generation_config.h revision 2d3b2d635e50c6886e285afb86c3187d9e0bd360
1// Copyright 2015 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#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 6#define UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 7 8#include <cstddef> 9 10#include <memory> 11#include <string> 12#include <vector> 13 14#include "update_engine/payload_generator/filesystem_interface.h" 15#include "update_engine/update_metadata.pb.h" 16 17namespace chromeos_update_engine { 18 19// The list different kind of partitions supported by the updater. 20enum class PartitionName { 21 kKernel, 22 kRootfs, 23}; 24 25// Return a string name for the PartitionName. 26std::string PartitionNameString(PartitionName name); 27 28struct PartitionConfig { 29 explicit PartitionConfig(PartitionName name) : name(name) {} 30 31 // Returns whether the PartitionConfig is not an empty image and all the 32 // fields are set correctly to a valid image file. 33 bool ValidateExists() const; 34 35 // Open then filesystem stored in this partition and stores it in 36 // |fs_interface|. Returns whether opening the filesystem worked. 37 bool OpenFilesystem(); 38 39 // The path to the partition file. This can be a regular file or a block 40 // device such as a loop device. 41 std::string path; 42 43 // The size of the data in |path|. If rootfs verification is used (verity) 44 // this value should match the size of the verity device for the rootfs, and 45 // the size of the whole kernel. This value could be smaller than the 46 // partition and is the size of the data update_engine assumes verified for 47 // the source image, and the size of that data it should generate for the 48 // target image. 49 uint64_t size = 0; 50 51 // The FilesystemInterface implementation used to access this partition's 52 // files. 53 std::unique_ptr<FilesystemInterface> fs_interface; 54 55 PartitionName name; 56}; 57 58// The ImageConfig struct describes a pair of binaries kernel and rootfs and the 59// metadata associated with the image they are part of, like build number, size, 60// etc. 61struct ImageConfig { 62 // Returns whether the ImageConfig is an empty image. 63 bool ValidateIsEmpty() const; 64 65 // Load |rootfs_size| and |kernel.size| from the respective image files. For 66 // the kernel, the whole |kernel.path| file is assumed. For the rootfs, the 67 // size is detected from the filesystem. 68 // Returns whether the image size was properly detected. 69 bool LoadImageSize(); 70 71 // Load the |rootfs_size| stored in the kernel command line in the 72 // |kernel.path| when the kernel is using rootfs verification (dm-verity). 73 // Returns whether it loaded the size from the kernel command line. For 74 // example, it would return false if no |kernel.path| was provided or the 75 // kernel doesn't have verity enabled. 76 bool LoadVerityRootfsSize(); 77 78 // Returns whether the |image_info| field is empty. 79 bool ImageInfoIsEmpty() const; 80 81 // The ImageInfo message defined in the update_metadata.proto file describes 82 // the metadata of the image. 83 ImageInfo image_info; 84 85 // The updated partitions. 86 PartitionConfig rootfs = PartitionConfig{PartitionName::kRootfs}; 87 PartitionConfig kernel = PartitionConfig{PartitionName::kKernel}; 88}; 89 90// The PayloadGenerationConfig struct encapsulates all the configuration to 91// build the requested payload. This includes information about the old and new 92// image as well as the restrictions applied to the payload (like minor-version 93// and full/delta payload). 94struct PayloadGenerationConfig { 95 // Returns whether the PayloadGenerationConfig is valid. 96 bool Validate() const; 97 98 // Image information about the new image that's the target of this payload. 99 ImageConfig target; 100 101 // Image information pertaining the old image, if any. This is only valid 102 // if is_full is false, so we are requested a delta payload. 103 ImageConfig source; 104 105 // Wheter the requested payload is a delta payload. 106 bool is_delta = false; 107 108 // The minor_version of the requested payload. 109 uint32_t minor_version; 110 111 // The size of the rootfs partition, that not necessarily is the same as the 112 // filesystem in either source or target version, since there is some space 113 // after the partition used to store the verity hashes and or the bootcache. 114 uint64_t rootfs_partition_size = 0; 115 116 // The |hard_chunk_size| is the maximum size that a single operation should 117 // write in the destination. Operations bigger than chunk_size should be 118 // split. A value of -1 means no hard chunk size limit. A very low limit 119 // means more operations, and less of a chance to reuse the data. 120 ssize_t hard_chunk_size = -1; 121 122 // The |soft_chunk_size| is the preferred chunk size to use when there's no 123 // significant impact to the operations. For example, REPLACE, MOVE and 124 // SOURCE_COPY operations are not significantly impacted by the chunk size, 125 // except for a few bytes overhead in the manifest to describe extra 126 // operations. On the other hand, splitting BSDIFF operations impacts the 127 // payload size since it is not possible to use the redundancy *between* 128 // chunks. 129 size_t soft_chunk_size = 2 * 1024 * 1024; 130 131 // TODO(deymo): Remove the block_size member and maybe replace it with a 132 // minimum alignment size for blocks (if needed). Algorithms should be able to 133 // pick the block_size they want, but for now only 4 KiB is supported. 134 135 // The block size used for all the operations in the manifest. 136 size_t block_size = 4096; 137}; 138 139} // namespace chromeos_update_engine 140 141#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_PAYLOAD_GENERATION_CONFIG_H_ 142