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 0x66, 0x22, 0x1e, 0xa0, 0xbf, 0x7d, 0x8a, 0x79, 0x0b, 0x31, 0x14, 0xef, 0xb2, 0xe1, 0x2b, 0x86,
8 0x70, 0x52, 0xaf, 0xd2, 0x8b, 0x99, 0x91, 0x89, 0x87, 0x2c, 0x22, 0xfe, 0x11, 0xb4, 0x21, 0xec,
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 merge_super_and_userdata: bool,
33 pub no_zxcrypt: bool,
34 pub provision_fxfs: bool,
35 pub ramdisk_image: bool,
36 pub starnix_volume_name: String,
37 pub watch_deprecated_v1_drivers: bool,
38}
39impl Config {
40 #[doc = r" Take the config startup handle and parse its contents."]
41 #[doc = r""]
42 #[doc = r" # Panics"]
43 #[doc = r""]
44 #[doc = r" If the config startup handle was already taken or if it is not valid."]
45 pub fn take_from_startup_handle() -> Self {
46 <Self as ComponentConfig>::take_from_startup_handle()
47 }
48 #[doc = r" Parse `Self` from `vmo`."]
49 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
50 <Self as ComponentConfig>::from_vmo(vmo)
51 }
52 #[doc = r" Parse `Self` from `bytes`."]
53 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
54 <Self as ComponentConfig>::from_bytes(bytes)
55 }
56 pub fn record_inspect(&self, inspector_node: &Node) {
57 <Self as ComponentConfig>::record_inspect(self, inspector_node)
58 }
59}
60impl ComponentConfig for Config {
61 #[doc = r" Parse `Self` from `bytes`."]
62 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
63 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
64 let checksum_len_bytes: [u8; 2] =
65 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
66 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
67 let (observed_checksum, bytes) =
68 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
69 if observed_checksum != EXPECTED_CHECKSUM {
70 return Err(Error::ChecksumMismatch {
71 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
72 observed_checksum: observed_checksum.to_vec(),
73 });
74 }
75 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
76 Ok(Self {
77 blob_max_bytes: fidl_config.blob_max_bytes,
78 blobfs: fidl_config.blobfs,
79 blobfs_initial_inodes: fidl_config.blobfs_initial_inodes,
80 blobfs_use_deprecated_padded_format: fidl_config.blobfs_use_deprecated_padded_format,
81 check_filesystems: fidl_config.check_filesystems,
82 data: fidl_config.data,
83 data_filesystem_format: fidl_config.data_filesystem_format,
84 data_max_bytes: fidl_config.data_max_bytes,
85 disable_automount: fidl_config.disable_automount,
86 disable_block_watcher: fidl_config.disable_block_watcher,
87 factory: fidl_config.factory,
88 format_data_on_corruption: fidl_config.format_data_on_corruption,
89 fvm: fidl_config.fvm,
90 fvm_slice_size: fidl_config.fvm_slice_size,
91 fxfs_blob: fidl_config.fxfs_blob,
92 fxfs_crypt_url: fidl_config.fxfs_crypt_url,
93 gpt: fidl_config.gpt,
94 gpt_all: fidl_config.gpt_all,
95 inline_crypto: fidl_config.inline_crypto,
96 merge_super_and_userdata: fidl_config.merge_super_and_userdata,
97 no_zxcrypt: fidl_config.no_zxcrypt,
98 provision_fxfs: fidl_config.provision_fxfs,
99 ramdisk_image: fidl_config.ramdisk_image,
100 starnix_volume_name: fidl_config.starnix_volume_name,
101 watch_deprecated_v1_drivers: fidl_config.watch_deprecated_v1_drivers,
102 })
103 }
104 fn to_bytes(&self) -> Result<Vec<u8>, Error> {
105 let fidl_config = FidlConfig {
106 blob_max_bytes: self.blob_max_bytes.clone(),
107 blobfs: self.blobfs.clone(),
108 blobfs_initial_inodes: self.blobfs_initial_inodes.clone(),
109 blobfs_use_deprecated_padded_format: self.blobfs_use_deprecated_padded_format.clone(),
110 check_filesystems: self.check_filesystems.clone(),
111 data: self.data.clone(),
112 data_filesystem_format: self.data_filesystem_format.clone(),
113 data_max_bytes: self.data_max_bytes.clone(),
114 disable_automount: self.disable_automount.clone(),
115 disable_block_watcher: self.disable_block_watcher.clone(),
116 factory: self.factory.clone(),
117 format_data_on_corruption: self.format_data_on_corruption.clone(),
118 fvm: self.fvm.clone(),
119 fvm_slice_size: self.fvm_slice_size.clone(),
120 fxfs_blob: self.fxfs_blob.clone(),
121 fxfs_crypt_url: self.fxfs_crypt_url.clone(),
122 gpt: self.gpt.clone(),
123 gpt_all: self.gpt_all.clone(),
124 inline_crypto: self.inline_crypto.clone(),
125 merge_super_and_userdata: self.merge_super_and_userdata.clone(),
126 no_zxcrypt: self.no_zxcrypt.clone(),
127 provision_fxfs: self.provision_fxfs.clone(),
128 ramdisk_image: self.ramdisk_image.clone(),
129 starnix_volume_name: self.starnix_volume_name.clone(),
130 watch_deprecated_v1_drivers: self.watch_deprecated_v1_drivers.clone(),
131 };
132 let mut fidl_bytes = fidl::persist(&fidl_config).map_err(Error::Persist)?;
133 let mut bytes = Vec::with_capacity(
134 EXPECTED_CHECKSUM_LENGTH.len() + EXPECTED_CHECKSUM.len() + fidl_bytes.len(),
135 );
136 bytes.extend_from_slice(&EXPECTED_CHECKSUM_LENGTH);
137 bytes.extend_from_slice(EXPECTED_CHECKSUM);
138 bytes.append(&mut fidl_bytes);
139 Ok(bytes)
140 }
141 fn record_inspect(&self, inspector_node: &Node) {
142 inspector_node.record_uint("blob_max_bytes", self.blob_max_bytes);
143 inspector_node.record_bool("blobfs", self.blobfs);
144 inspector_node.record_uint("blobfs_initial_inodes", self.blobfs_initial_inodes);
145 inspector_node.record_bool(
146 "blobfs_use_deprecated_padded_format",
147 self.blobfs_use_deprecated_padded_format,
148 );
149 inspector_node.record_bool("check_filesystems", self.check_filesystems);
150 inspector_node.record_bool("data", self.data);
151 inspector_node.record_string("data_filesystem_format", &self.data_filesystem_format);
152 inspector_node.record_uint("data_max_bytes", self.data_max_bytes);
153 inspector_node.record_bool("disable_automount", self.disable_automount);
154 inspector_node.record_bool("disable_block_watcher", self.disable_block_watcher);
155 inspector_node.record_bool("factory", self.factory);
156 inspector_node.record_bool("format_data_on_corruption", self.format_data_on_corruption);
157 inspector_node.record_bool("fvm", self.fvm);
158 inspector_node.record_uint("fvm_slice_size", self.fvm_slice_size);
159 inspector_node.record_bool("fxfs_blob", self.fxfs_blob);
160 inspector_node.record_string("fxfs_crypt_url", &self.fxfs_crypt_url);
161 inspector_node.record_bool("gpt", self.gpt);
162 inspector_node.record_bool("gpt_all", self.gpt_all);
163 inspector_node.record_bool("inline_crypto", self.inline_crypto);
164 inspector_node.record_bool("merge_super_and_userdata", self.merge_super_and_userdata);
165 inspector_node.record_bool("no_zxcrypt", self.no_zxcrypt);
166 inspector_node.record_bool("provision_fxfs", self.provision_fxfs);
167 inspector_node.record_bool("ramdisk_image", self.ramdisk_image);
168 inspector_node.record_string("starnix_volume_name", &self.starnix_volume_name);
169 inspector_node.record_bool("watch_deprecated_v1_drivers", self.watch_deprecated_v1_drivers);
170 }
171}