39 #ifndef PSTORE_CORE_FILE_HEADER_HPP 40 #define PSTORE_CORE_FILE_HEADER_HPP 57 template <
typename Archive>
58 static auto write (Archive && archive, value_type
const & r)
59 -> archive_result_type<Archive> {
61 serialize::write (std::forward<Archive> (archive), r.
addr.absolute ());
62 serialize::write (std::forward<Archive> (archive), r.
size);
65 template <
typename Archive>
66 static void read (Archive && archive, value_type & r) {
68 serialize::read<std::uint64_t> (std::forward<Archive> (archive)));
69 auto const size = serialize::read<std::uint64_t> (std::forward<Archive> (archive));
82 bool is_valid ()
const noexcept;
85 std::uint32_t get_crc ()
const noexcept;
90 uuid id () const noexcept {
return a.id; }
91 void set_id (
uuid const &
id) noexcept;
94 std::array<std::uint16_t, 2>
const &
version () const noexcept {
return a.version; }
96 static constexpr std::uint16_t major_version = 1;
97 static constexpr std::uint16_t minor_version = 12;
99 static std::array<std::uint8_t, 4>
const file_signature1;
100 static std::uint32_t
const file_signature2 = 0x0507FFFF;
119 std::uint32_t header_size =
sizeof (
header);
134 std::uint32_t crc = 0;
135 std::uint32_t unused1 = 0;
144 PSTORE_STATIC_ASSERT (offsetof (
header::body, signature1) == 0);
145 PSTORE_STATIC_ASSERT (offsetof (
header::body, signature2) == 4);
146 PSTORE_STATIC_ASSERT (offsetof (
header::body, version) == 8);
147 PSTORE_STATIC_ASSERT (offsetof (
header::body, header_size) == 12);
148 PSTORE_STATIC_ASSERT (offsetof (
header::body,
id) == 16);
151 PSTORE_STATIC_ASSERT (offsetof (
header, a) == 0);
152 PSTORE_STATIC_ASSERT (offsetof (
header, crc) == 32);
153 PSTORE_STATIC_ASSERT (offsetof (
header, footer_pos) == 40);
154 PSTORE_STATIC_ASSERT (
alignof (
header) == 8);
155 PSTORE_STATIC_ASSERT (
sizeof (
header) == 48);
163 std::uint64_t vacuum_lock{chars_to_uint64 (
'V',
'a',
'c',
'u',
'u',
'm',
'L',
'k')};
164 std::uint64_t
transaction_lock{chars_to_uint64 (
'T',
'r',
'n',
's',
'a',
'c',
't',
'L')};
166 static constexpr
auto file_offset = std::uint64_t{
sizeof (
header)};
167 static constexpr std::uint64_t chars_to_uint64 (
char const c1,
char const c2,
char const c3,
168 char const c4,
char const c5,
char const c6,
169 char const c7,
char const c8) noexcept {
170 return static_cast<std::uint64_t
> (c1) | static_cast<std::uint64_t> (c2) << 8U |
171 static_cast<std::uint64_t
> (c3) << 16U | static_cast<std::uint64_t> (c4) << 24U |
172 static_cast<std::uint64_t
> (c5) << 32U | static_cast<std::uint64_t> (c6) << 40U |
173 static_cast<std::uint64_t
> (c7) << 48U | static_cast<std::uint64_t> (c8) << 56U;
179 PSTORE_STATIC_ASSERT (offsetof (
lock_block, vacuum_lock) == 0);
181 PSTORE_STATIC_ASSERT (
alignof (
lock_block) == 8);
182 PSTORE_STATIC_ASSERT (
sizeof (
lock_block) == 16);
190 #define PSTORE_INDICES \ 192 X (debug_line_header) \ 207 static std::array<std::uint8_t, 8>
const default_signature1;
208 static std::array<std::uint8_t, 8>
const default_signature2;
210 bool crc_is_valid ()
const noexcept;
211 bool signature_is_valid ()
const noexcept;
218 std::uint32_t get_crc ()
const noexcept;
224 enum class indices : unsigned { PSTORE_INDICES last };
226 using index_records_array =
227 std::array<typed_address<index::header_block>,
228 static_cast<std::underlying_type<indices>::type
> (indices::last)>;
233 std::array<std::uint8_t, 8> signature1 = default_signature1;
234 std::atomic<std::uint32_t> generation{0};
235 std::uint32_t unused1{0};
239 std::atomic<std::uint64_t> size{0};
242 std::atomic<std::uint64_t> time{0};
249 index_records_array index_records;
250 std::uint32_t unused2{0};
251 std::uint32_t unused3{0};
262 std::uint32_t crc = 0;
263 std::uint32_t unused1 = 0;
264 std::array<std::uint8_t, 8> signature2 = default_signature2;
269 PSTORE_STATIC_ASSERT (offsetof (
trailer::body, signature1) == 0);
270 PSTORE_STATIC_ASSERT (offsetof (
trailer::body, generation) == 8);
271 PSTORE_STATIC_ASSERT (offsetof (
trailer::body, unused1) == 12);
274 PSTORE_STATIC_ASSERT (offsetof (
trailer::body, prev_generation) == 32);
275 PSTORE_STATIC_ASSERT (offsetof (
trailer::body, index_records) == 40);
276 PSTORE_STATIC_ASSERT (offsetof (
trailer::body, unused2) == 88);
277 PSTORE_STATIC_ASSERT (offsetof (
trailer::body, unused3) == 92);
281 PSTORE_STATIC_ASSERT (offsetof (
trailer, a) == 0);
282 PSTORE_STATIC_ASSERT (offsetof (
trailer, crc) == 96);
283 PSTORE_STATIC_ASSERT (offsetof (
trailer, signature2) == 104);
284 PSTORE_STATIC_ASSERT (
alignof (
trailer) == 8);
285 PSTORE_STATIC_ASSERT (
sizeof (
trailer) == 112);
288 #endif // PSTORE_CORE_FILE_HEADER_HPP
lock_guard fills a similar role as a type such as std::scoped_lock<> in that it provides convenient R...
Definition: transaction.hpp:236
Represents the portion of the header structure which is covered by the computed CRC value...
Definition: file_header.hpp:104
The lock-block is a small struct placed immediately after the file header which is used by the transa...
Definition: file_header.hpp:162
typed_address< T > addr
The address of the data associated with this extent.
Definition: address.hpp:456
The primary template for serialization of non standard layout types.
Definition: types.hpp:118
An extent is a contiguous area of storage reserved for a data BLOB, represented as a range...
Definition: address.hpp:441
The transaction footer structure.
Definition: file_header.hpp:206
static auto write(Archive &&archive, Ty const &v) -> archive_result_type< Archive >
Writes an single value of type Ty to an archive.
Definition: types.hpp:133
Represents the portion of the trailer structure which is covered by the computed CRC value...
Definition: file_header.hpp:232
Provides serialization capabilities for trivial and user-defined types.
Definition: address.hpp:231
std::array< std::uint16_t, 2 > version
The file format version number (major, minor).
Definition: file_header.hpp:118
std::uint64_t size
The size of the data associated with this extent.
Definition: address.hpp:461
static void read(Archive &&archive, Ty &v)
Reads a value of type Ty from an archive.
Definition: types.hpp:153
Definition: nonpod2.cpp:40
Definition: database.hpp:40
std::uint32_t signature2
The second half of the file signature.
Definition: file_header.hpp:115
std::array< std::uint8_t, 4 > signature1
The file signature is split into two pieces of four bytes each.
Definition: file_header.hpp:111
The uuid class is used to represent Universally Unique Identifiers (UUID) as defined by RFC 4122...
Definition: uuid.hpp:40
Defines the uuid class which supports RFC4122 UUIDs.