fshost_config/
fshost_config_rust_rust_config_lib_source.rs

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