blob: 3546dd3a6891a7833973fd21d8654da26729aecb [file] [log] [blame]
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +00001// 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 Walbran0c4d3df2021-05-27 14:00:42 +000015//! JSON configuration for composite disks, as used for running `mk_cdisk` and by the `vm` tool.
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000016
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000017use serde::{Deserialize, Serialize};
18use std::io::Write;
19use std::path::PathBuf;
20
Andrew Walbran0c4d3df2021-05-27 14:00:42 +000021/// Configuration for running `mk_cdisk`.
Andrew Walbranf5fbb7d2021-05-12 17:15:48 +000022#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
23pub 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)]
30pub 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
40impl Config {
Andrew Walbran0c4d3df2021-05-27 14:00:42 +000041 /// 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 Walbranf5fbb7d2021-05-12 17:15:48 +000044 }
45}