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