• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include <cstddef>
17 
18 #include "pw_preprocessor/compiler.h"
19 
20 namespace pw::blob_store::internal {
21 
22 enum MetadataVersion : uint32_t {
23   // Original metadata format does not include a version.
24   kVersion1 = 0,
25   kVersion2 = 0x1197851D,
26   kLatest = kVersion2
27 };
28 
29 // Technically the original BlobMetadataV1 was not packed.
PW_PACKED(struct)30 PW_PACKED(struct) BlobMetadataV1 {
31   typedef uint32_t ChecksumValue;
32 
33   // The checksum of the blob data stored in flash.
34   ChecksumValue checksum;
35 
36   // Number of blob data bytes stored in flash.
37   // Technically this was originally size_t, but backwards compatibility for
38   // platform-specific sized types has been dropped.
39   uint32_t data_size_bytes;
40 };
41 
42 // Changes to the metadata format should also get a different key signature to
43 // avoid new code improperly reading old format metadata.
PW_PACKED(struct)44 PW_PACKED(struct) BlobMetadataHeaderV2 {
45   BlobMetadataV1 v1_metadata;
46 
47   // Metadata encoding version stored in flash.
48   MetadataVersion version;
49 
50   // Length of the file name stored in the metadata entry.
51   uint8_t file_name_length;
52 
53   // Following this struct is file_name_length chars of file name. Note that
54   // the string of characters is NOT null terminated.
55 
56   constexpr void reset() {
57     *this = {
58         .v1_metadata =
59             {
60                 .checksum = 0,
61                 .data_size_bytes = 0,
62             },
63         .version = MetadataVersion::kLatest,
64         .file_name_length = 0,
65     };
66   }
67 };
68 
69 using BlobMetadataHeader = BlobMetadataHeaderV2;
70 using ChecksumValue = BlobMetadataV1::ChecksumValue;
71 
72 }  // namespace pw::blob_store::internal
73