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 0x33, 0x90, 0xb1, 0xbf, 0x4b, 0x80, 0x77, 0xe5, 0x5f, 0x5e, 0x6e, 0xd2, 0x29, 0xff, 0x14, 0x3f,
8 0x7f, 0xa7, 0xf9, 0xaa, 0x77, 0x46, 0x23, 0x60, 0x9c, 0x60, 0x2a, 0x32, 0x1b, 0x9f, 0x7d, 0x1e,
9];
10#[derive(Debug)]
11pub struct Config {
12 pub blobfs: bool,
13 pub blobfs_cache_eviction_policy: String,
14 pub blobfs_initial_inodes: u64,
15 pub blobfs_max_bytes: u64,
16 pub blobfs_use_deprecated_padded_format: bool,
17 pub blobfs_write_compression_algorithm: String,
18 pub bootpart: bool,
19 pub check_filesystems: bool,
20 pub data: bool,
21 pub data_filesystem_format: String,
22 pub data_max_bytes: u64,
23 pub disable_automount: bool,
24 pub disable_block_watcher: bool,
25 pub factory: bool,
26 pub format_data_on_corruption: bool,
27 pub fvm: bool,
28 pub fvm_slice_size: u64,
29 pub fxfs_blob: bool,
30 pub fxfs_crypt_url: String,
31 pub gpt: bool,
32 pub gpt_all: bool,
33 pub inline_crypto: bool,
34 pub mbr: bool,
35 pub merge_super_and_userdata: bool,
36 pub no_zxcrypt: bool,
37 pub provision_fxfs: bool,
38 pub ramdisk_image: bool,
39 pub starnix_volume_name: String,
40 pub storage_host: bool,
41 pub use_disk_migration: bool,
42 pub watch_deprecated_v1_drivers: bool,
43}
44impl Config {
45 #[doc = r" Take the config startup handle and parse its contents."]
46 #[doc = r""]
47 #[doc = r" # Panics"]
48 #[doc = r""]
49 #[doc = r" If the config startup handle was already taken or if it is not valid."]
50 pub fn take_from_startup_handle() -> Self {
51 <Self as ComponentConfig>::take_from_startup_handle()
52 }
53 #[doc = r" Parse `Self` from `vmo`."]
54 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
55 <Self as ComponentConfig>::from_vmo(vmo)
56 }
57 #[doc = r" Parse `Self` from `bytes`."]
58 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
59 <Self as ComponentConfig>::from_bytes(bytes)
60 }
61 pub fn record_inspect(&self, inspector_node: &Node) {
62 <Self as ComponentConfig>::record_inspect(self, inspector_node)
63 }
64}
65impl ComponentConfig for Config {
66 #[doc = r" Parse `Self` from `bytes`."]
67 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
68 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
69 let checksum_len_bytes: [u8; 2] =
70 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
71 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
72 let (observed_checksum, bytes) =
73 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
74 if observed_checksum != EXPECTED_CHECKSUM {
75 return Err(Error::ChecksumMismatch {
76 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
77 observed_checksum: observed_checksum.to_vec(),
78 });
79 }
80 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
81 Ok(Self {
82 blobfs: fidl_config.blobfs,
83 blobfs_cache_eviction_policy: fidl_config.blobfs_cache_eviction_policy,
84 blobfs_initial_inodes: fidl_config.blobfs_initial_inodes,
85 blobfs_max_bytes: fidl_config.blobfs_max_bytes,
86 blobfs_use_deprecated_padded_format: fidl_config.blobfs_use_deprecated_padded_format,
87 blobfs_write_compression_algorithm: fidl_config.blobfs_write_compression_algorithm,
88 bootpart: fidl_config.bootpart,
89 check_filesystems: fidl_config.check_filesystems,
90 data: fidl_config.data,
91 data_filesystem_format: fidl_config.data_filesystem_format,
92 data_max_bytes: fidl_config.data_max_bytes,
93 disable_automount: fidl_config.disable_automount,
94 disable_block_watcher: fidl_config.disable_block_watcher,
95 factory: fidl_config.factory,
96 format_data_on_corruption: fidl_config.format_data_on_corruption,
97 fvm: fidl_config.fvm,
98 fvm_slice_size: fidl_config.fvm_slice_size,
99 fxfs_blob: fidl_config.fxfs_blob,
100 fxfs_crypt_url: fidl_config.fxfs_crypt_url,
101 gpt: fidl_config.gpt,
102 gpt_all: fidl_config.gpt_all,
103 inline_crypto: fidl_config.inline_crypto,
104 mbr: fidl_config.mbr,
105 merge_super_and_userdata: fidl_config.merge_super_and_userdata,
106 no_zxcrypt: fidl_config.no_zxcrypt,
107 provision_fxfs: fidl_config.provision_fxfs,
108 ramdisk_image: fidl_config.ramdisk_image,
109 starnix_volume_name: fidl_config.starnix_volume_name,
110 storage_host: fidl_config.storage_host,
111 use_disk_migration: fidl_config.use_disk_migration,
112 watch_deprecated_v1_drivers: fidl_config.watch_deprecated_v1_drivers,
113 })
114 }
115 fn record_inspect(&self, inspector_node: &Node) {
116 inspector_node.record_bool("blobfs", self.blobfs);
117 inspector_node
118 .record_string("blobfs_cache_eviction_policy", &self.blobfs_cache_eviction_policy);
119 inspector_node.record_uint("blobfs_initial_inodes", self.blobfs_initial_inodes);
120 inspector_node.record_uint("blobfs_max_bytes", self.blobfs_max_bytes);
121 inspector_node.record_bool(
122 "blobfs_use_deprecated_padded_format",
123 self.blobfs_use_deprecated_padded_format,
124 );
125 inspector_node.record_string(
126 "blobfs_write_compression_algorithm",
127 &self.blobfs_write_compression_algorithm,
128 );
129 inspector_node.record_bool("bootpart", self.bootpart);
130 inspector_node.record_bool("check_filesystems", self.check_filesystems);
131 inspector_node.record_bool("data", self.data);
132 inspector_node.record_string("data_filesystem_format", &self.data_filesystem_format);
133 inspector_node.record_uint("data_max_bytes", self.data_max_bytes);
134 inspector_node.record_bool("disable_automount", self.disable_automount);
135 inspector_node.record_bool("disable_block_watcher", self.disable_block_watcher);
136 inspector_node.record_bool("factory", self.factory);
137 inspector_node.record_bool("format_data_on_corruption", self.format_data_on_corruption);
138 inspector_node.record_bool("fvm", self.fvm);
139 inspector_node.record_uint("fvm_slice_size", self.fvm_slice_size);
140 inspector_node.record_bool("fxfs_blob", self.fxfs_blob);
141 inspector_node.record_string("fxfs_crypt_url", &self.fxfs_crypt_url);
142 inspector_node.record_bool("gpt", self.gpt);
143 inspector_node.record_bool("gpt_all", self.gpt_all);
144 inspector_node.record_bool("inline_crypto", self.inline_crypto);
145 inspector_node.record_bool("mbr", self.mbr);
146 inspector_node.record_bool("merge_super_and_userdata", self.merge_super_and_userdata);
147 inspector_node.record_bool("no_zxcrypt", self.no_zxcrypt);
148 inspector_node.record_bool("provision_fxfs", self.provision_fxfs);
149 inspector_node.record_bool("ramdisk_image", self.ramdisk_image);
150 inspector_node.record_string("starnix_volume_name", &self.starnix_volume_name);
151 inspector_node.record_bool("storage_host", self.storage_host);
152 inspector_node.record_bool("use_disk_migration", self.use_disk_migration);
153 inspector_node.record_bool("watch_deprecated_v1_drivers", self.watch_deprecated_v1_drivers);
154 }
155}