]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
87d2c1ff LP |
3 | |
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2011 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
10 | under the terms of the GNU Lesser General Public License as published by |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
87d2c1ff LP |
12 | (at your option) any later version. |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 17 | Lesser General Public License for more details. |
87d2c1ff | 18 | |
5430f7f2 | 19 | You should have received a copy of the GNU Lesser General Public License |
87d2c1ff LP |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
21 | ***/ | |
22 | ||
3ffd4af2 | 23 | #include "sd-id128.h" |
81527be1 | 24 | |
87d2c1ff | 25 | #include "macro.h" |
3ffd4af2 | 26 | #include "sparse-endian.h" |
87d2c1ff | 27 | |
0962e09e LP |
28 | /* |
29 | * If you change this file you probably should also change its documentation: | |
30 | * | |
31 | * http://www.freedesktop.org/wiki/Software/systemd/journal-files | |
32 | * | |
33 | */ | |
34 | ||
87d2c1ff | 35 | typedef struct Header Header; |
8144056f | 36 | |
87d2c1ff LP |
37 | typedef struct ObjectHeader ObjectHeader; |
38 | typedef union Object Object; | |
8144056f | 39 | |
87d2c1ff | 40 | typedef struct DataObject DataObject; |
de190aef | 41 | typedef struct FieldObject FieldObject; |
87d2c1ff LP |
42 | typedef struct EntryObject EntryObject; |
43 | typedef struct HashTableObject HashTableObject; | |
de190aef | 44 | typedef struct EntryArrayObject EntryArrayObject; |
7560fffc | 45 | typedef struct TagObject TagObject; |
8144056f | 46 | |
87d2c1ff LP |
47 | typedef struct EntryItem EntryItem; |
48 | typedef struct HashItem HashItem; | |
49 | ||
baed47c3 | 50 | typedef struct FSSHeader FSSHeader; |
7560fffc | 51 | |
87d2c1ff | 52 | /* Object types */ |
78519831 | 53 | typedef enum ObjectType { |
d05089d8 | 54 | OBJECT_UNUSED, /* also serves as "any type" or "additional context" */ |
0962e09e | 55 | OBJECT_DATA, |
de190aef | 56 | OBJECT_FIELD, |
87d2c1ff | 57 | OBJECT_ENTRY, |
de190aef LP |
58 | OBJECT_DATA_HASH_TABLE, |
59 | OBJECT_FIELD_HASH_TABLE, | |
0962e09e | 60 | OBJECT_ENTRY_ARRAY, |
7560fffc | 61 | OBJECT_TAG, |
de190aef | 62 | _OBJECT_TYPE_MAX |
78519831 | 63 | } ObjectType; |
87d2c1ff | 64 | |
807e17f0 LP |
65 | /* Object flags */ |
66 | enum { | |
d89c8fdf ZJS |
67 | OBJECT_COMPRESSED_XZ = 1 << 0, |
68 | OBJECT_COMPRESSED_LZ4 = 1 << 1, | |
69 | _OBJECT_COMPRESSED_MAX | |
807e17f0 LP |
70 | }; |
71 | ||
d89c8fdf ZJS |
72 | #define OBJECT_COMPRESSION_MASK (OBJECT_COMPRESSED_XZ | OBJECT_COMPRESSED_LZ4) |
73 | ||
80701564 | 74 | struct ObjectHeader { |
87d2c1ff | 75 | uint8_t type; |
807e17f0 LP |
76 | uint8_t flags; |
77 | uint8_t reserved[6]; | |
4fd052ae | 78 | le64_t size; |
87d2c1ff | 79 | uint8_t payload[]; |
80701564 | 80 | } _packed_; |
87d2c1ff | 81 | |
80701564 | 82 | struct DataObject { |
87d2c1ff | 83 | ObjectHeader object; |
4fd052ae FC |
84 | le64_t hash; |
85 | le64_t next_hash_offset; | |
86 | le64_t next_field_offset; | |
87 | le64_t entry_offset; /* the first array entry we store inline */ | |
88 | le64_t entry_array_offset; | |
89 | le64_t n_entries; | |
de190aef | 90 | uint8_t payload[]; |
80701564 | 91 | } _packed_; |
de190aef | 92 | |
80701564 | 93 | struct FieldObject { |
de190aef | 94 | ObjectHeader object; |
4fd052ae FC |
95 | le64_t hash; |
96 | le64_t next_hash_offset; | |
97 | le64_t head_data_offset; | |
87d2c1ff | 98 | uint8_t payload[]; |
80701564 | 99 | } _packed_; |
87d2c1ff | 100 | |
80701564 | 101 | struct EntryItem { |
4fd052ae FC |
102 | le64_t object_offset; |
103 | le64_t hash; | |
80701564 | 104 | } _packed_; |
87d2c1ff | 105 | |
80701564 | 106 | struct EntryObject { |
87d2c1ff | 107 | ObjectHeader object; |
4fd052ae FC |
108 | le64_t seqnum; |
109 | le64_t realtime; | |
110 | le64_t monotonic; | |
cec736d2 | 111 | sd_id128_t boot_id; |
4fd052ae | 112 | le64_t xor_hash; |
87d2c1ff | 113 | EntryItem items[]; |
80701564 | 114 | } _packed_; |
87d2c1ff | 115 | |
80701564 | 116 | struct HashItem { |
4fd052ae FC |
117 | le64_t head_hash_offset; |
118 | le64_t tail_hash_offset; | |
80701564 | 119 | } _packed_; |
87d2c1ff | 120 | |
80701564 | 121 | struct HashTableObject { |
87d2c1ff | 122 | ObjectHeader object; |
de190aef | 123 | HashItem items[]; |
80701564 | 124 | } _packed_; |
87d2c1ff | 125 | |
80701564 | 126 | struct EntryArrayObject { |
87d2c1ff | 127 | ObjectHeader object; |
4fd052ae FC |
128 | le64_t next_entry_array_offset; |
129 | le64_t items[]; | |
80701564 | 130 | } _packed_; |
87d2c1ff | 131 | |
7560fffc | 132 | #define TAG_LENGTH (256/8) |
8144056f | 133 | |
80701564 | 134 | struct TagObject { |
8144056f | 135 | ObjectHeader object; |
e8c61d7b LP |
136 | le64_t seqnum; |
137 | le64_t epoch; | |
7560fffc | 138 | uint8_t tag[TAG_LENGTH]; /* SHA-256 HMAC */ |
80701564 | 139 | } _packed_; |
8144056f | 140 | |
87d2c1ff LP |
141 | union Object { |
142 | ObjectHeader object; | |
143 | DataObject data; | |
de190aef | 144 | FieldObject field; |
87d2c1ff LP |
145 | EntryObject entry; |
146 | HashTableObject hash_table; | |
de190aef | 147 | EntryArrayObject entry_array; |
7560fffc | 148 | TagObject tag; |
87d2c1ff LP |
149 | }; |
150 | ||
151 | enum { | |
db11ac1a LP |
152 | STATE_OFFLINE = 0, |
153 | STATE_ONLINE = 1, | |
154 | STATE_ARCHIVED = 2, | |
155 | _STATE_MAX | |
87d2c1ff LP |
156 | }; |
157 | ||
807e17f0 LP |
158 | /* Header flags */ |
159 | enum { | |
d89c8fdf ZJS |
160 | HEADER_INCOMPATIBLE_COMPRESSED_XZ = 1 << 0, |
161 | HEADER_INCOMPATIBLE_COMPRESSED_LZ4 = 1 << 1, | |
807e17f0 LP |
162 | }; |
163 | ||
d89c8fdf ZJS |
164 | #define HEADER_INCOMPATIBLE_ANY (HEADER_INCOMPATIBLE_COMPRESSED_XZ|HEADER_INCOMPATIBLE_COMPRESSED_LZ4) |
165 | ||
349cc4a5 | 166 | #if HAVE_XZ && HAVE_LZ4 |
d89c8fdf | 167 | # define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_ANY |
349cc4a5 | 168 | #elif HAVE_XZ |
d89c8fdf | 169 | # define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_COMPRESSED_XZ |
349cc4a5 | 170 | #elif HAVE_LZ4 |
d89c8fdf ZJS |
171 | # define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_COMPRESSED_LZ4 |
172 | #else | |
173 | # define HEADER_INCOMPATIBLE_SUPPORTED 0 | |
174 | #endif | |
175 | ||
8144056f | 176 | enum { |
baed47c3 | 177 | HEADER_COMPATIBLE_SEALED = 1 |
8144056f LP |
178 | }; |
179 | ||
d89c8fdf | 180 | #define HEADER_COMPATIBLE_ANY HEADER_COMPATIBLE_SEALED |
349cc4a5 | 181 | #if HAVE_GCRYPT |
d89c8fdf ZJS |
182 | # define HEADER_COMPATIBLE_SUPPORTED HEADER_COMPATIBLE_SEALED |
183 | #else | |
184 | # define HEADER_COMPATIBLE_SUPPORTED 0 | |
185 | #endif | |
186 | ||
7560fffc LP |
187 | #define HEADER_SIGNATURE ((char[]) { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' }) |
188 | ||
80701564 | 189 | struct Header { |
87d2c1ff | 190 | uint8_t signature[8]; /* "LPKSHHRH" */ |
7560fffc LP |
191 | le32_t compatible_flags; |
192 | le32_t incompatible_flags; | |
de190aef LP |
193 | uint8_t state; |
194 | uint8_t reserved[7]; | |
87d2c1ff | 195 | sd_id128_t file_id; |
7560fffc | 196 | sd_id128_t machine_id; |
08984293 | 197 | sd_id128_t boot_id; /* last writer */ |
cec736d2 | 198 | sd_id128_t seqnum_id; |
23b0b2b2 | 199 | le64_t header_size; |
4fd052ae | 200 | le64_t arena_size; |
0962e09e | 201 | le64_t data_hash_table_offset; |
4fd052ae | 202 | le64_t data_hash_table_size; |
0962e09e | 203 | le64_t field_hash_table_offset; |
4fd052ae FC |
204 | le64_t field_hash_table_size; |
205 | le64_t tail_object_offset; | |
206 | le64_t n_objects; | |
207 | le64_t n_entries; | |
beec0085 LP |
208 | le64_t tail_entry_seqnum; |
209 | le64_t head_entry_seqnum; | |
4fd052ae FC |
210 | le64_t entry_array_offset; |
211 | le64_t head_entry_realtime; | |
212 | le64_t tail_entry_realtime; | |
213 | le64_t tail_entry_monotonic; | |
dca6219e LP |
214 | /* Added in 187 */ |
215 | le64_t n_data; | |
216 | le64_t n_fields; | |
d98cc1f2 LP |
217 | /* Added in 189 */ |
218 | le64_t n_tags; | |
2dee23eb | 219 | le64_t n_entry_arrays; |
fb9a24b6 | 220 | |
b4a855e9 | 221 | /* Size: 240 */ |
80701564 | 222 | } _packed_; |
7560fffc | 223 | |
baed47c3 | 224 | #define FSS_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' }) |
7560fffc | 225 | |
80701564 | 226 | struct FSSHeader { |
7560fffc LP |
227 | uint8_t signature[8]; /* "KSHHRHLP" */ |
228 | le32_t compatible_flags; | |
229 | le32_t incompatible_flags; | |
230 | sd_id128_t machine_id; | |
231 | sd_id128_t boot_id; /* last writer */ | |
232 | le64_t header_size; | |
baed47c3 LP |
233 | le64_t start_usec; |
234 | le64_t interval_usec; | |
235 | le16_t fsprg_secpar; | |
7560fffc | 236 | le16_t reserved[3]; |
baed47c3 | 237 | le64_t fsprg_state_size; |
80701564 | 238 | } _packed_; |