Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 1 | // Copyright 2021, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Andrew Walbran | 0c4d3df | 2021-05-27 14:00:42 +0000 | [diff] [blame^] | 15 | //! JSON configuration for composite disks, as used for running `mk_cdisk` and by the `vm` tool. |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 16 | |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 17 | use serde::{Deserialize, Serialize}; |
| 18 | use std::io::Write; |
| 19 | use std::path::PathBuf; |
| 20 | |
Andrew Walbran | 0c4d3df | 2021-05-27 14:00:42 +0000 | [diff] [blame^] | 21 | /// Configuration for running `mk_cdisk`. |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 22 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 23 | pub struct Config { |
| 24 | /// The set of partitions to be assembled into a composite image. |
| 25 | pub partitions: Vec<Partition>, |
| 26 | } |
| 27 | |
| 28 | /// A partition to be assembled into a composite image. |
| 29 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] |
| 30 | pub struct Partition { |
| 31 | /// A label for the partition. |
| 32 | pub label: String, |
| 33 | /// The filename of the partition image. |
| 34 | pub path: PathBuf, |
| 35 | /// Whether the partition should be writable. |
| 36 | #[serde(default)] |
| 37 | pub writable: bool, |
| 38 | } |
| 39 | |
| 40 | impl Config { |
Andrew Walbran | 0c4d3df | 2021-05-27 14:00:42 +0000 | [diff] [blame^] | 41 | /// Write the configuration as JSON, in the format used by `mk_cdisk`. |
| 42 | pub fn write_json(&self, writer: impl Write) -> serde_json::Result<()> { |
| 43 | serde_json::to_writer(writer, self) |
Andrew Walbran | f5fbb7d | 2021-05-12 17:15:48 +0000 | [diff] [blame] | 44 | } |
| 45 | } |