Move shared config structs to shared crate.
Bug: 184131523
Test: mm
Change-Id: I53e46a2985addbee9facd5b007778ae60c583900
diff --git a/compositediskconfig/Android.bp b/compositediskconfig/Android.bp
new file mode 100644
index 0000000..4608323
--- /dev/null
+++ b/compositediskconfig/Android.bp
@@ -0,0 +1,18 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+rust_library {
+ name: "libcompositediskconfig",
+ host_supported: true,
+ crate_name: "compositediskconfig",
+ srcs: ["src/lib.rs"],
+ edition: "2018",
+ rustlibs: [
+ "libserde_json",
+ "libserde",
+ ],
+ apex_available: [
+ "com.android.virt",
+ ],
+}
diff --git a/compositediskconfig/src/lib.rs b/compositediskconfig/src/lib.rs
new file mode 100644
index 0000000..3546dd3
--- /dev/null
+++ b/compositediskconfig/src/lib.rs
@@ -0,0 +1,45 @@
+// Copyright 2021, The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//! JSON configuration for composite disks, as used for running `mk_cdisk` and by the `vm` tool.
+
+use serde::{Deserialize, Serialize};
+use std::io::Write;
+use std::path::PathBuf;
+
+/// Configuration for running `mk_cdisk`.
+#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
+pub struct Config {
+ /// The set of partitions to be assembled into a composite image.
+ pub partitions: Vec<Partition>,
+}
+
+/// A partition to be assembled into a composite image.
+#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
+pub struct Partition {
+ /// A label for the partition.
+ pub label: String,
+ /// The filename of the partition image.
+ pub path: PathBuf,
+ /// Whether the partition should be writable.
+ #[serde(default)]
+ pub writable: bool,
+}
+
+impl Config {
+ /// Write the configuration as JSON, in the format used by `mk_cdisk`.
+ pub fn write_json(&self, writer: impl Write) -> serde_json::Result<()> {
+ serde_json::to_writer(writer, self)
+ }
+}