1use fidl::unpersist;
2use fidl_cf_sc_internal_fshostconfig::Config as FidlConfig;
3use fuchsia_component_config::{Config as ComponentConfig, Error};
4use fuchsia_inspect::Node;
5use std::convert::TryInto;
6const EXPECTED_CHECKSUM: &[u8] = &[
7 0x3b, 0xf0, 0xf1, 0x63, 0x58, 0xcf, 0xc9, 0x14, 0x2a, 0x75, 0x5a, 0x7e, 0x41, 0x58, 0x40, 0xba,
8 0x0f, 0xd6, 0x79, 0xae, 0x4b, 0x4b, 0xc7, 0xdd, 0xce, 0xed, 0x2c, 0xba, 0x4b, 0xb3, 0x74, 0x62,
9];
10const EXPECTED_CHECKSUM_LENGTH: [u8; 2] = (EXPECTED_CHECKSUM.len() as u16).to_le_bytes();
11#[derive(Debug)]
12pub struct Config {
13 pub blob_max_bytes: u64,
14 pub blobfs: bool,
15 pub blobfs_initial_inodes: u64,
16 pub blobfs_use_deprecated_padded_format: bool,
17 pub check_filesystems: bool,
18 pub data: bool,
19 pub data_filesystem_format: String,
20 pub data_max_bytes: u64,
21 pub disable_automount: bool,
22 pub disable_block_watcher: bool,
23 pub factory: bool,
24 pub format_data_on_corruption: bool,
25 pub fvm: bool,
26 pub fvm_slice_size: u64,
27 pub fxfs_blob: bool,
28 pub fxfs_crypt_url: String,
29 pub gpt: bool,
30 pub gpt_all: bool,
31 pub inline_crypto: bool,
32 pub mbr: bool,
33 pub merge_super_and_userdata: bool,
34 pub no_zxcrypt: bool,
35 pub provision_fxfs: bool,
36 pub ramdisk_image: bool,
37 pub starnix_volume_name: String,
38 pub storage_host: bool,
39 pub use_disk_migration: bool,
40 pub watch_deprecated_v1_drivers: bool,
41}
42impl Config {
43 #[doc = r" Take the config startup handle and parse its contents."]
44 #[doc = r""]
45 #[doc = r" # Panics"]
46 #[doc = r""]
47 #[doc = r" If the config startup handle was already taken or if it is not valid."]
48 pub fn take_from_startup_handle() -> Self {
49 <Self as ComponentConfig>::take_from_startup_handle()
50 }
51 #[doc = r" Parse `Self` from `vmo`."]
52 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
53 <Self as ComponentConfig>::from_vmo(vmo)
54 }
55 #[doc = r" Parse `Self` from `bytes`."]
56 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
57 <Self as ComponentConfig>::from_bytes(bytes)
58 }
59 pub fn record_inspect(&self, inspector_node: &Node) {
60 <Self as ComponentConfig>::record_inspect(self, inspector_node)
61 }
62}
63impl ComponentConfig for Config {
64 #[doc = r" Parse `Self` from `bytes`."]
65 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
66 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
67 let checksum_len_bytes: [u8; 2] =
68 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
69 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
70 let (observed_checksum, bytes) =
71 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
72 if observed_checksum != EXPECTED_CHECKSUM {
73 return Err(Error::ChecksumMismatch {
74 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
75 observed_checksum: observed_checksum.to_vec(),
76 });
77 }
78 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
79 Ok(Self {
80 blob_max_bytes: fidl_config.blob_max_bytes,
81 blobfs: fidl_config.blobfs,
82 blobfs_initial_inodes: fidl_config.blobfs_initial_inodes,
83 blobfs_use_deprecated_padded_format: fidl_config.blobfs_use_deprecated_padded_format,
84 check_filesystems: fidl_config.check_filesystems,
85 data: fidl_config.data,
86 data_filesystem_format: fidl_config.data_filesystem_format,
87 data_max_bytes: fidl_config.data_max_bytes,
88 disable_automount: fidl_config.disable_automount,
89 disable_block_watcher: fidl_config.disable_block_watcher,
90 factory: fidl_config.factory,
91 format_data_on_corruption: fidl_config.format_data_on_corruption,
92 fvm: fidl_config.fvm,
93 fvm_slice_size: fidl_config.fvm_slice_size,
94 fxfs_blob: fidl_config.fxfs_blob,
95 fxfs_crypt_url: fidl_config.fxfs_crypt_url,
96 gpt: fidl_config.gpt,
97 gpt_all: fidl_config.gpt_all,
98 inline_crypto: fidl_config.inline_crypto,
99 mbr: fidl_config.mbr,
100 merge_super_and_userdata: fidl_config.merge_super_and_userdata,
101 no_zxcrypt: fidl_config.no_zxcrypt,
102 provision_fxfs: fidl_config.provision_fxfs,
103 ramdisk_image: fidl_config.ramdisk_image,
104 starnix_volume_name: fidl_config.starnix_volume_name,
105 storage_host: fidl_config.storage_host,
106 use_disk_migration: fidl_config.use_disk_migration,
107 watch_deprecated_v1_drivers: fidl_config.watch_deprecated_v1_drivers,
108 })
109 }
110 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
111 let fidl_config = FidlConfig {
112 blob_max_bytes: self.blob_max_bytes.clone(),
113 blobfs: self.blobfs.clone(),
114 blobfs_initial_inodes: self.blobfs_initial_inodes.clone(),
115 blobfs_use_deprecated_padded_format: self.blobfs_use_deprecated_padded_format.clone(),
116 check_filesystems: self.check_filesystems.clone(),
117 data: self.data.clone(),
118 data_filesystem_format: self.data_filesystem_format.clone(),
119 data_max_bytes: self.data_max_bytes.clone(),
120 disable_automount: self.disable_automount.clone(),
121 disable_block_watcher: self.disable_block_watcher.clone(),
122 factory: self.factory.clone(),
123 format_data_on_corruption: self.format_data_on_corruption.clone(),
124 fvm: self.fvm.clone(),
125 fvm_slice_size: self.fvm_slice_size.clone(),
126 fxfs_blob: self.fxfs_blob.clone(),
127 fxfs_crypt_url: self.fxfs_crypt_url.clone(),
128 gpt: self.gpt.clone(),
129 gpt_all: self.gpt_all.clone(),
130 inline_crypto: self.inline_crypto.clone(),
131 mbr: self.mbr.clone(),
132 merge_super_and_userdata: self.merge_super_and_userdata.clone(),
133 no_zxcrypt: self.no_zxcrypt.clone(),
134 provision_fxfs: self.provision_fxfs.clone(),
135 ramdisk_image: self.ramdisk_image.clone(),
136 starnix_volume_name: self.starnix_volume_name.clone(),
137 storage_host: self.storage_host.clone(),
138 use_disk_migration: self.use_disk_migration.clone(),
139 watch_deprecated_v1_drivers: self.watch_deprecated_v1_drivers.clone(),
140 };
141 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
142 let mut bytes = Vec::with_capacity(
143 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
144 );
145 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
146 bytes.extend_from_slice(EXPECTED_CHECKSUM);
147 bytes.append(&mut fidl_bytes);
148 Ok(bytes)
149 }
150 fn record_inspect(&self, inspector_node: &Node) {
151 inspector_node.record_uint("blob_max_bytes", self.blob_max_bytes);
152 inspector_node.record_bool("blobfs", self.blobfs);
153 inspector_node.record_uint("blobfs_initial_inodes", self.blobfs_initial_inodes);
154 inspector_node.record_bool(
155 "blobfs_use_deprecated_padded_format",
156 self.blobfs_use_deprecated_padded_format,
157 );
158 inspector_node.record_bool("check_filesystems", self.check_filesystems);
159 inspector_node.record_bool("data", self.data);
160 inspector_node.record_string("data_filesystem_format", &self.data_filesystem_format);
161 inspector_node.record_uint("data_max_bytes", self.data_max_bytes);
162 inspector_node.record_bool("disable_automount", self.disable_automount);
163 inspector_node.record_bool("disable_block_watcher", self.disable_block_watcher);
164 inspector_node.record_bool("factory", self.factory);
165 inspector_node.record_bool("format_data_on_corruption", self.format_data_on_corruption);
166 inspector_node.record_bool("fvm", self.fvm);
167 inspector_node.record_uint("fvm_slice_size", self.fvm_slice_size);
168 inspector_node.record_bool("fxfs_blob", self.fxfs_blob);
169 inspector_node.record_string("fxfs_crypt_url", &self.fxfs_crypt_url);
170 inspector_node.record_bool("gpt", self.gpt);
171 inspector_node.record_bool("gpt_all", self.gpt_all);
172 inspector_node.record_bool("inline_crypto", self.inline_crypto);
173 inspector_node.record_bool("mbr", self.mbr);
174 inspector_node.record_bool("merge_super_and_userdata", self.merge_super_and_userdata);
175 inspector_node.record_bool("no_zxcrypt", self.no_zxcrypt);
176 inspector_node.record_bool("provision_fxfs", self.provision_fxfs);
177 inspector_node.record_bool("ramdisk_image", self.ramdisk_image);
178 inspector_node.record_string("starnix_volume_name", &self.starnix_volume_name);
179 inspector_node.record_bool("storage_host", self.storage_host);
180 inspector_node.record_bool("use_disk_migration", self.use_disk_migration);
181 inspector_node.record_bool("watch_deprecated_v1_drivers", self.watch_deprecated_v1_drivers);
182 }
183}