blob: 1a915baa084e03c0404c90d4efca9ba87c20105c [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
15//! JSON configuration for running `mk_cdisk`.
16
17use anyhow::{Context, Error};
18use serde::{Deserialize, Serialize};
19use std::io::Write;
20use std::path::PathBuf;
21
22#[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 {
41 pub fn write_json(&self, writer: impl Write) -> Result<(), Error> {
42 serde_json::to_writer(writer, self).context("Failed to write config JSON for mk_cdisk")
43 }
44}