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