fxfs/serialized_types/
types.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::lsm_tree::{
6    PersistentLayerHeader, PersistentLayerHeaderV39, PersistentLayerInfo, PersistentLayerInfoV39,
7};
8use crate::object_store::allocator::{
9    AllocatorInfo, AllocatorInfoV32, AllocatorKey, AllocatorKeyV32, AllocatorValue,
10    AllocatorValueV32,
11};
12use crate::object_store::journal::super_block::{
13    SuperBlockHeader, SuperBlockHeaderV32, SuperBlockRecord, SuperBlockRecordV40,
14    SuperBlockRecordV41, SuperBlockRecordV43, SuperBlockRecordV46, SuperBlockRecordV47,
15    SuperBlockRecordV49, SuperBlockRecordV50,
16};
17use crate::object_store::journal::{
18    JournalRecord, JournalRecordV40, JournalRecordV41, JournalRecordV42, JournalRecordV43,
19    JournalRecordV46, JournalRecordV47, JournalRecordV49, JournalRecordV50,
20};
21use crate::object_store::object_record::{
22    FsverityMetadata, FsverityMetadataV33, FsverityMetadataV50, ObjectKey, ObjectKeyV40,
23    ObjectKeyV43, ObjectValue, ObjectValueV40, ObjectValueV41, ObjectValueV46, ObjectValueV47,
24    ObjectValueV49, ObjectValueV50,
25};
26use crate::object_store::transaction::{
27    Mutation, MutationV40, MutationV41, MutationV43, MutationV46, MutationV47, MutationV49,
28    MutationV50,
29};
30use crate::object_store::{
31    EncryptedMutations, EncryptedMutationsV40, EncryptedMutationsV49, StoreInfo, StoreInfoV40,
32    StoreInfoV49,
33};
34use crate::serialized_types::{Version, Versioned, VersionedLatest, versioned_type};
35use std::collections::BTreeMap;
36
37/// The latest version of on-disk filesystem format.
38///
39/// If all layer files are compacted the the journal flushed, and super-block
40/// both rewritten, all versions should match this value.
41///
42/// If making a breaking change, please see EARLIEST_SUPPORTED_VERSION (below).
43///
44/// IMPORTANT: When changing this (major or minor), update the list of possible versions at
45/// https://cs.opensource.google/fuchsia/fuchsia/+/main:third_party/cobalt_config/fuchsia/local_storage/versions.txt.
46pub const LATEST_VERSION: Version = Version { major: 50, minor: 0 };
47
48/// The earliest supported version of the on-disk filesystem format.
49///
50/// When a breaking change is made:
51/// 1) LATEST_VERSION should have it's major component increased (see above).
52/// 2) EARLIEST_SUPPORTED_VERSION should be set to the new LATEST_VERSION.
53/// 3) The SuperBlockHeader version (below) should also be set to the new LATEST_VERSION.
54///
55/// Also check the constant version numbers above for any code cleanup that can happen.
56pub const EARLIEST_SUPPORTED_VERSION: Version = Version { major: 40, minor: 0 };
57
58/// From this version of the filesystem, we shrink the size of the extents that are reserved for
59/// the superblock and root-parent store to a single block.
60pub const SMALL_SUPERBLOCK_VERSION: Version = Version { major: 44, minor: 0 };
61
62/// From this version of the filesystem, the superblock explicitly includes a record for it's
63/// first extent. Prior to this, the first extent was assumed based on hard-coded location.
64pub const FIRST_EXTENT_IN_SUPERBLOCK_VERSION: Version = Version { major: 45, minor: 0 };
65
66macro_rules! versioned_types {
67    ( $( $name:ident { $latest:literal.. => $latest_type:ty $(, $major:literal.. => $type:ty )* $(,)? } )+ ) => {
68        $(
69            static_assertions::assert_type_eq_all!($name, $latest_type);
70
71            versioned_type! {
72                $latest.. => $latest_type,
73                $( $major.. => $type ),*
74            }
75        )+
76
77        pub fn get_type_fingerprints(version: Version) -> BTreeMap<String, String> {
78            let mut map = BTreeMap::new();
79            $(
80                let fingerprint = {
81                    let mut fp = None;
82                    const FINGERPRINTS: &[(u32, fn() -> String)] = &[
83                        ($latest, <$latest_type as fprint::TypeFingerprint>::fingerprint),
84                        $( ($major, <$type as fprint::TypeFingerprint>::fingerprint) ),*
85                    ];
86                    for (major, type_fp) in FINGERPRINTS {
87                        if version.major >= *major {
88                            fp = Some(type_fp());
89                            break;
90                        }
91                    }
92                    fp
93                };
94                if let Some(fp) = fingerprint {
95                    map.insert(stringify!($name).to_string(), fp.to_string());
96                }
97            )+
98            map
99        }
100    };
101}
102
103versioned_types! {
104    AllocatorInfo {
105        32.. => AllocatorInfoV32,
106    }
107    AllocatorKey {
108        32.. => AllocatorKeyV32,
109    }
110    AllocatorValue {
111        32.. => AllocatorValueV32,
112    }
113    EncryptedMutations {
114        49.. => EncryptedMutationsV49,
115        40.. => EncryptedMutationsV40,
116    }
117    FsverityMetadata {
118        50.. => FsverityMetadataV50,
119        33.. => FsverityMetadataV33,
120    }
121    JournalRecord {
122        50.. => JournalRecordV50,
123        49.. => JournalRecordV49,
124        47.. => JournalRecordV47,
125        46.. => JournalRecordV46,
126        43.. => JournalRecordV43,
127        42.. => JournalRecordV42,
128        41.. => JournalRecordV41,
129        40.. => JournalRecordV40,
130    }
131    Mutation {
132        50.. => MutationV50,
133        49.. => MutationV49,
134        47.. => MutationV47,
135        46.. => MutationV46,
136        43.. => MutationV43,
137        41.. => MutationV41,
138        40.. => MutationV40,
139    }
140    ObjectKey {
141        43.. => ObjectKeyV43,
142        40.. => ObjectKeyV40,
143    }
144    ObjectValue {
145        50.. => ObjectValueV50,
146        49.. => ObjectValueV49,
147        47.. => ObjectValueV47,
148        46.. => ObjectValueV46,
149        41.. => ObjectValueV41,
150        40.. => ObjectValueV40,
151    }
152    PersistentLayerHeader {
153        39.. => PersistentLayerHeaderV39,
154    }
155    PersistentLayerInfo {
156        39.. => PersistentLayerInfoV39,
157    }
158    StoreInfo {
159        49.. => StoreInfoV49,
160        40.. => StoreInfoV40,
161    }
162    SuperBlockHeader {
163        32.. => SuperBlockHeaderV32,
164    }
165    SuperBlockRecord {
166        50.. => SuperBlockRecordV50,
167        49.. => SuperBlockRecordV49,
168        47.. => SuperBlockRecordV47,
169        46.. => SuperBlockRecordV46,
170        43.. => SuperBlockRecordV43,
171        41.. => SuperBlockRecordV41,
172        40.. => SuperBlockRecordV40,
173    }
174}