1 /* 2 * Copyright (C) 2019 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 #pragma once 17 18 /** 19 * Functions for manipulating disk files given to crosvm or QEMU. 20 */ 21 22 #include <string> 23 #include <vector> 24 25 struct ImagePartition { 26 std::string label; 27 std::string image_file_path; 28 }; 29 30 /** 31 * Combine the files in `partition` into a single raw disk file and write it to 32 * `output_path`. The raw disk file will have a GUID Partition Table and copy in 33 * the contents of the files mentioned in `partitions`. 34 */ 35 void AggregateImage(const std::vector<ImagePartition>& partitions, 36 const std::string& output_path); 37 38 /** 39 * Generate the files necessary for booting with a Composite Disk. 40 * 41 * Composite Disk is a crosvm disk format that is a layer of indirection over 42 * other disk files. The Composite Disk file lists names and offsets in the 43 * virtual disk. 44 * 45 * For a complete single disk inside the VM, there must also be a GUID Partition 46 * Table header and footer. These are saved to `header_file` and `footer_file`, 47 * then the specification file containing the file paths and offsets is saved to 48 * `output_composite_path`. 49 */ 50 void CreateCompositeDisk(std::vector<ImagePartition> partitions, 51 const std::string& header_file, 52 const std::string& footer_file, 53 const std::string& output_composite_path); 54 55 /** 56 * Generate a qcow overlay backed by a given implementation file. 57 * 58 * qcow, or "QEMU Copy-On-Write" is a file format containing a list of disk 59 * offsets and file contents. This can be combined with a backing file, to 60 * represent an original disk file plus disk updates over that file. The qcow 61 * files can be swapped out and replaced without affecting the original. qcow 62 * is supported by QEMU and crosvm. 63 * 64 * The crosvm binary at `crosvm_path` is used to generate an overlay file at 65 * `output_overlay_path` that functions as an overlay on the file at 66 * `backing_file`. 67 */ 68 void CreateQcowOverlay(const std::string& crosvm_path, 69 const std::string& backing_file, 70 const std::string& output_overlay_path); 71