]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-def.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / journal / journal-def.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
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
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
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
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #include "sd-id128.h"
24
25 #include "macro.h"
26 #include "sparse-endian.h"
27
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
35 typedef struct Header Header;
36
37 typedef struct ObjectHeader ObjectHeader;
38 typedef union Object Object;
39
40 typedef struct DataObject DataObject;
41 typedef struct FieldObject FieldObject;
42 typedef struct EntryObject EntryObject;
43 typedef struct HashTableObject HashTableObject;
44 typedef struct EntryArrayObject EntryArrayObject;
45 typedef struct TagObject TagObject;
46
47 typedef struct EntryItem EntryItem;
48 typedef struct HashItem HashItem;
49
50 typedef struct FSSHeader FSSHeader;
51
52 /* Object types */
53 typedef enum ObjectType {
54 OBJECT_UNUSED, /* also serves as "any type" or "additional context" */
55 OBJECT_DATA,
56 OBJECT_FIELD,
57 OBJECT_ENTRY,
58 OBJECT_DATA_HASH_TABLE,
59 OBJECT_FIELD_HASH_TABLE,
60 OBJECT_ENTRY_ARRAY,
61 OBJECT_TAG,
62 _OBJECT_TYPE_MAX
63 } ObjectType;
64
65 /* Object flags */
66 enum {
67 OBJECT_COMPRESSED_XZ = 1 << 0,
68 OBJECT_COMPRESSED_LZ4 = 1 << 1,
69 _OBJECT_COMPRESSED_MAX
70 };
71
72 #define OBJECT_COMPRESSION_MASK (OBJECT_COMPRESSED_XZ | OBJECT_COMPRESSED_LZ4)
73
74 struct ObjectHeader {
75 uint8_t type;
76 uint8_t flags;
77 uint8_t reserved[6];
78 le64_t size;
79 uint8_t payload[];
80 } _packed_;
81
82 struct DataObject {
83 ObjectHeader object;
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;
90 uint8_t payload[];
91 } _packed_;
92
93 struct FieldObject {
94 ObjectHeader object;
95 le64_t hash;
96 le64_t next_hash_offset;
97 le64_t head_data_offset;
98 uint8_t payload[];
99 } _packed_;
100
101 struct EntryItem {
102 le64_t object_offset;
103 le64_t hash;
104 } _packed_;
105
106 struct EntryObject {
107 ObjectHeader object;
108 le64_t seqnum;
109 le64_t realtime;
110 le64_t monotonic;
111 sd_id128_t boot_id;
112 le64_t xor_hash;
113 EntryItem items[];
114 } _packed_;
115
116 struct HashItem {
117 le64_t head_hash_offset;
118 le64_t tail_hash_offset;
119 } _packed_;
120
121 struct HashTableObject {
122 ObjectHeader object;
123 HashItem items[];
124 } _packed_;
125
126 struct EntryArrayObject {
127 ObjectHeader object;
128 le64_t next_entry_array_offset;
129 le64_t items[];
130 } _packed_;
131
132 #define TAG_LENGTH (256/8)
133
134 struct TagObject {
135 ObjectHeader object;
136 le64_t seqnum;
137 le64_t epoch;
138 uint8_t tag[TAG_LENGTH]; /* SHA-256 HMAC */
139 } _packed_;
140
141 union Object {
142 ObjectHeader object;
143 DataObject data;
144 FieldObject field;
145 EntryObject entry;
146 HashTableObject hash_table;
147 EntryArrayObject entry_array;
148 TagObject tag;
149 };
150
151 enum {
152 STATE_OFFLINE = 0,
153 STATE_ONLINE = 1,
154 STATE_ARCHIVED = 2,
155 _STATE_MAX
156 };
157
158 /* Header flags */
159 enum {
160 HEADER_INCOMPATIBLE_COMPRESSED_XZ = 1 << 0,
161 HEADER_INCOMPATIBLE_COMPRESSED_LZ4 = 1 << 1,
162 };
163
164 #define HEADER_INCOMPATIBLE_ANY (HEADER_INCOMPATIBLE_COMPRESSED_XZ|HEADER_INCOMPATIBLE_COMPRESSED_LZ4)
165
166 #if HAVE_XZ && HAVE_LZ4
167 # define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_ANY
168 #elif HAVE_XZ
169 # define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_COMPRESSED_XZ
170 #elif HAVE_LZ4
171 # define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_COMPRESSED_LZ4
172 #else
173 # define HEADER_INCOMPATIBLE_SUPPORTED 0
174 #endif
175
176 enum {
177 HEADER_COMPATIBLE_SEALED = 1
178 };
179
180 #define HEADER_COMPATIBLE_ANY HEADER_COMPATIBLE_SEALED
181 #if HAVE_GCRYPT
182 # define HEADER_COMPATIBLE_SUPPORTED HEADER_COMPATIBLE_SEALED
183 #else
184 # define HEADER_COMPATIBLE_SUPPORTED 0
185 #endif
186
187 #define HEADER_SIGNATURE ((char[]) { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' })
188
189 struct Header {
190 uint8_t signature[8]; /* "LPKSHHRH" */
191 le32_t compatible_flags;
192 le32_t incompatible_flags;
193 uint8_t state;
194 uint8_t reserved[7];
195 sd_id128_t file_id;
196 sd_id128_t machine_id;
197 sd_id128_t boot_id; /* last writer */
198 sd_id128_t seqnum_id;
199 le64_t header_size;
200 le64_t arena_size;
201 le64_t data_hash_table_offset;
202 le64_t data_hash_table_size;
203 le64_t field_hash_table_offset;
204 le64_t field_hash_table_size;
205 le64_t tail_object_offset;
206 le64_t n_objects;
207 le64_t n_entries;
208 le64_t tail_entry_seqnum;
209 le64_t head_entry_seqnum;
210 le64_t entry_array_offset;
211 le64_t head_entry_realtime;
212 le64_t tail_entry_realtime;
213 le64_t tail_entry_monotonic;
214 /* Added in 187 */
215 le64_t n_data;
216 le64_t n_fields;
217 /* Added in 189 */
218 le64_t n_tags;
219 le64_t n_entry_arrays;
220
221 /* Size: 240 */
222 } _packed_;
223
224 #define FSS_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' })
225
226 struct FSSHeader {
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;
233 le64_t start_usec;
234 le64_t interval_usec;
235 le16_t fsprg_secpar;
236 le16_t reserved[3];
237 le64_t fsprg_state_size;
238 } _packed_;