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