fshost_config/
fshost_config_rust_rust_config_lib_source.rs

1use fidl::unpersist;
2use fidl_cf_sc_internal_fshostconfig::Config as FidlConfig;
3use fuchsia_inspect::Node;
4use fuchsia_runtime::{take_startup_handle, HandleInfo, HandleType};
5#[derive(Debug)]
6pub struct Config {
7    pub blobfs: bool,
8    pub blobfs_cache_eviction_policy: String,
9    pub blobfs_initial_inodes: u64,
10    pub blobfs_max_bytes: u64,
11    pub blobfs_use_deprecated_padded_format: bool,
12    pub blobfs_write_compression_algorithm: String,
13    pub bootpart: bool,
14    pub check_filesystems: bool,
15    pub data: bool,
16    pub data_filesystem_format: String,
17    pub data_max_bytes: u64,
18    pub disable_automount: bool,
19    pub disable_block_watcher: bool,
20    pub factory: bool,
21    pub format_data_on_corruption: bool,
22    pub fvm: bool,
23    pub fvm_slice_size: u64,
24    pub fxfs_blob: bool,
25    pub fxfs_crypt_url: String,
26    pub gpt: bool,
27    pub gpt_all: bool,
28    pub mbr: bool,
29    pub nand: bool,
30    pub netboot: bool,
31    pub no_zxcrypt: bool,
32    pub ramdisk_image: bool,
33    pub starnix_volume_name: String,
34    pub storage_host: bool,
35    pub use_disk_migration: bool,
36}
37impl Config {
38    pub fn take_from_startup_handle() -> Self {
39        let config_vmo: zx::Vmo =
40            take_startup_handle(HandleInfo::new(HandleType::ComponentConfigVmo, 0))
41                .expect("Config VMO handle must be provided and cannot already have been taken.")
42                .into();
43        let config_size =
44            config_vmo.get_content_size().expect("must be able to read config vmo content size");
45        assert_ne!(config_size, 0, "config vmo must be non-empty");
46        let config_bytes =
47            config_vmo.read_to_vec(0, config_size).expect("must be able to read config vmo");
48        let checksum_length = u16::from_le_bytes([config_bytes[0], config_bytes[1]]) as usize;
49        let fidl_start = 2 + checksum_length;
50        let observed_checksum = &config_bytes[2..fidl_start];
51        let expected_checksum = vec![
52            0x63, 0x1f, 0xe3, 0xc7, 0xee, 0x84, 0x00, 0xd4, 0x1d, 0x76, 0xf6, 0x82, 0x0f, 0x9d,
53            0x3d, 0x86, 0xdc, 0x1b, 0x45, 0x0c, 0x06, 0xc7, 0x6b, 0x70, 0x53, 0xd4, 0x82, 0xe8,
54            0x66, 0x7c, 0xf5, 0x44,
55        ];
56        assert_eq!(
57            observed_checksum, expected_checksum,
58            "checksum from config VMO does not match expected checksum"
59        );
60        let fidl_config: FidlConfig = unpersist(&config_bytes[fidl_start..])
61            .expect("must be able to parse bytes as config FIDL");
62        Self {
63            blobfs: fidl_config.blobfs,
64            blobfs_cache_eviction_policy: fidl_config.blobfs_cache_eviction_policy,
65            blobfs_initial_inodes: fidl_config.blobfs_initial_inodes,
66            blobfs_max_bytes: fidl_config.blobfs_max_bytes,
67            blobfs_use_deprecated_padded_format: fidl_config.blobfs_use_deprecated_padded_format,
68            blobfs_write_compression_algorithm: fidl_config.blobfs_write_compression_algorithm,
69            bootpart: fidl_config.bootpart,
70            check_filesystems: fidl_config.check_filesystems,
71            data: fidl_config.data,
72            data_filesystem_format: fidl_config.data_filesystem_format,
73            data_max_bytes: fidl_config.data_max_bytes,
74            disable_automount: fidl_config.disable_automount,
75            disable_block_watcher: fidl_config.disable_block_watcher,
76            factory: fidl_config.factory,
77            format_data_on_corruption: fidl_config.format_data_on_corruption,
78            fvm: fidl_config.fvm,
79            fvm_slice_size: fidl_config.fvm_slice_size,
80            fxfs_blob: fidl_config.fxfs_blob,
81            fxfs_crypt_url: fidl_config.fxfs_crypt_url,
82            gpt: fidl_config.gpt,
83            gpt_all: fidl_config.gpt_all,
84            mbr: fidl_config.mbr,
85            nand: fidl_config.nand,
86            netboot: fidl_config.netboot,
87            no_zxcrypt: fidl_config.no_zxcrypt,
88            ramdisk_image: fidl_config.ramdisk_image,
89            starnix_volume_name: fidl_config.starnix_volume_name,
90            storage_host: fidl_config.storage_host,
91            use_disk_migration: fidl_config.use_disk_migration,
92        }
93    }
94    pub fn record_inspect(&self, inspector_node: &Node) {
95        inspector_node.record_bool("blobfs", self.blobfs);
96        inspector_node
97            .record_string("blobfs_cache_eviction_policy", &self.blobfs_cache_eviction_policy);
98        inspector_node.record_uint("blobfs_initial_inodes", self.blobfs_initial_inodes);
99        inspector_node.record_uint("blobfs_max_bytes", self.blobfs_max_bytes);
100        inspector_node.record_bool(
101            "blobfs_use_deprecated_padded_format",
102            self.blobfs_use_deprecated_padded_format,
103        );
104        inspector_node.record_string(
105            "blobfs_write_compression_algorithm",
106            &self.blobfs_write_compression_algorithm,
107        );
108        inspector_node.record_bool("bootpart", self.bootpart);
109        inspector_node.record_bool("check_filesystems", self.check_filesystems);
110        inspector_node.record_bool("data", self.data);
111        inspector_node.record_string("data_filesystem_format", &self.data_filesystem_format);
112        inspector_node.record_uint("data_max_bytes", self.data_max_bytes);
113        inspector_node.record_bool("disable_automount", self.disable_automount);
114        inspector_node.record_bool("disable_block_watcher", self.disable_block_watcher);
115        inspector_node.record_bool("factory", self.factory);
116        inspector_node.record_bool("format_data_on_corruption", self.format_data_on_corruption);
117        inspector_node.record_bool("fvm", self.fvm);
118        inspector_node.record_uint("fvm_slice_size", self.fvm_slice_size);
119        inspector_node.record_bool("fxfs_blob", self.fxfs_blob);
120        inspector_node.record_string("fxfs_crypt_url", &self.fxfs_crypt_url);
121        inspector_node.record_bool("gpt", self.gpt);
122        inspector_node.record_bool("gpt_all", self.gpt_all);
123        inspector_node.record_bool("mbr", self.mbr);
124        inspector_node.record_bool("nand", self.nand);
125        inspector_node.record_bool("netboot", self.netboot);
126        inspector_node.record_bool("no_zxcrypt", self.no_zxcrypt);
127        inspector_node.record_bool("ramdisk_image", self.ramdisk_image);
128        inspector_node.record_string("starnix_volume_name", &self.starnix_volume_name);
129        inspector_node.record_bool("storage_host", self.storage_host);
130        inspector_node.record_bool("use_disk_migration", self.use_disk_migration);
131    }
132}