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 0x9b, 0xce, 0x7a, 0x77, 0xf1, 0x44, 0xd5, 0x19, 0x26, 0xfc, 0x29, 0x00, 0xed, 0xbe, 0x9b, 0xfa,
8 0x37, 0xa3, 0x52, 0x65, 0xb4, 0x72, 0x48, 0xac, 0x1f, 0x94, 0xa8, 0x94, 0xb3, 0x4b, 0x39, 0x75,
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 nand: bool,
36 pub netboot: bool,
37 pub no_zxcrypt: bool,
38 pub ramdisk_image: bool,
39 pub starnix_volume_name: String,
40 pub storage_host: bool,
41 pub use_disk_migration: bool,
42}
43impl Config {
44 #[doc = r" Take the config startup handle and parse its contents."]
45 #[doc = r""]
46 #[doc = r" # Panics"]
47 #[doc = r""]
48 #[doc = r" If the config startup handle was already taken or if it is not valid."]
49 pub fn take_from_startup_handle() -> Self {
50 <Self as ComponentConfig>::take_from_startup_handle()
51 }
52 #[doc = r" Parse `Self` from `vmo`."]
53 pub fn from_vmo(vmo: &zx::Vmo) -> Result<Self, Error> {
54 <Self as ComponentConfig>::from_vmo(vmo)
55 }
56 #[doc = r" Parse `Self` from `bytes`."]
57 pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
58 <Self as ComponentConfig>::from_bytes(bytes)
59 }
60 pub fn record_inspect(&self, inspector_node: &Node) {
61 <Self as ComponentConfig>::record_inspect(self, inspector_node)
62 }
63}
64impl ComponentConfig for Config {
65 #[doc = r" Parse `Self` from `bytes`."]
66 fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
67 let (checksum_len_bytes, bytes) = bytes.split_at_checked(2).ok_or(Error::TooFewBytes)?;
68 let checksum_len_bytes: [u8; 2] =
69 checksum_len_bytes.try_into().expect("previous call guaranteed 2 element slice");
70 let checksum_length = u16::from_le_bytes(checksum_len_bytes) as usize;
71 let (observed_checksum, bytes) =
72 bytes.split_at_checked(checksum_length).ok_or(Error::TooFewBytes)?;
73 if observed_checksum != EXPECTED_CHECKSUM {
74 return Err(Error::ChecksumMismatch {
75 expected_checksum: EXPECTED_CHECKSUM.to_vec(),
76 observed_checksum: observed_checksum.to_vec(),
77 });
78 }
79 let fidl_config: FidlConfig = unpersist(bytes).map_err(Error::Unpersist)?;
80 Ok(Self {
81 blobfs: fidl_config.blobfs,
82 blobfs_cache_eviction_policy: fidl_config.blobfs_cache_eviction_policy,
83 blobfs_initial_inodes: fidl_config.blobfs_initial_inodes,
84 blobfs_max_bytes: fidl_config.blobfs_max_bytes,
85 blobfs_use_deprecated_padded_format: fidl_config.blobfs_use_deprecated_padded_format,
86 blobfs_write_compression_algorithm: fidl_config.blobfs_write_compression_algorithm,
87 bootpart: fidl_config.bootpart,
88 check_filesystems: fidl_config.check_filesystems,
89 data: fidl_config.data,
90 data_filesystem_format: fidl_config.data_filesystem_format,
91 data_max_bytes: fidl_config.data_max_bytes,
92 disable_automount: fidl_config.disable_automount,
93 disable_block_watcher: fidl_config.disable_block_watcher,
94 factory: fidl_config.factory,
95 format_data_on_corruption: fidl_config.format_data_on_corruption,
96 fvm: fidl_config.fvm,
97 fvm_slice_size: fidl_config.fvm_slice_size,
98 fxfs_blob: fidl_config.fxfs_blob,
99 fxfs_crypt_url: fidl_config.fxfs_crypt_url,
100 gpt: fidl_config.gpt,
101 gpt_all: fidl_config.gpt_all,
102 inline_crypto: fidl_config.inline_crypto,
103 mbr: fidl_config.mbr,
104 nand: fidl_config.nand,
105 netboot: fidl_config.netboot,
106 no_zxcrypt: fidl_config.no_zxcrypt,
107 ramdisk_image: fidl_config.ramdisk_image,
108 starnix_volume_name: fidl_config.starnix_volume_name,
109 storage_host: fidl_config.storage_host,
110 use_disk_migration: fidl_config.use_disk_migration,
111 })
112 }
113 fn record_inspect(&self, inspector_node: &Node) {
114 inspector_node.record_bool("blobfs", self.blobfs);
115 inspector_node
116 .record_string("blobfs_cache_eviction_policy", &self.blobfs_cache_eviction_policy);
117 inspector_node.record_uint("blobfs_initial_inodes", self.blobfs_initial_inodes);
118 inspector_node.record_uint("blobfs_max_bytes", self.blobfs_max_bytes);
119 inspector_node.record_bool(
120 "blobfs_use_deprecated_padded_format",
121 self.blobfs_use_deprecated_padded_format,
122 );
123 inspector_node.record_string(
124 "blobfs_write_compression_algorithm",
125 &self.blobfs_write_compression_algorithm,
126 );
127 inspector_node.record_bool("bootpart", self.bootpart);
128 inspector_node.record_bool("check_filesystems", self.check_filesystems);
129 inspector_node.record_bool("data", self.data);
130 inspector_node.record_string("data_filesystem_format", &self.data_filesystem_format);
131 inspector_node.record_uint("data_max_bytes", self.data_max_bytes);
132 inspector_node.record_bool("disable_automount", self.disable_automount);
133 inspector_node.record_bool("disable_block_watcher", self.disable_block_watcher);
134 inspector_node.record_bool("factory", self.factory);
135 inspector_node.record_bool("format_data_on_corruption", self.format_data_on_corruption);
136 inspector_node.record_bool("fvm", self.fvm);
137 inspector_node.record_uint("fvm_slice_size", self.fvm_slice_size);
138 inspector_node.record_bool("fxfs_blob", self.fxfs_blob);
139 inspector_node.record_string("fxfs_crypt_url", &self.fxfs_crypt_url);
140 inspector_node.record_bool("gpt", self.gpt);
141 inspector_node.record_bool("gpt_all", self.gpt_all);
142 inspector_node.record_bool("inline_crypto", self.inline_crypto);
143 inspector_node.record_bool("mbr", self.mbr);
144 inspector_node.record_bool("nand", self.nand);
145 inspector_node.record_bool("netboot", self.netboot);
146 inspector_node.record_bool("no_zxcrypt", self.no_zxcrypt);
147 inspector_node.record_bool("ramdisk_image", self.ramdisk_image);
148 inspector_node.record_string("starnix_volume_name", &self.starnix_volume_name);
149 inspector_node.record_bool("storage_host", self.storage_host);
150 inspector_node.record_bool("use_disk_migration", self.use_disk_migration);
151 }
152}