]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journal-def.h
journal: count number of entry arrays in header
[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 typedef struct Header Header;
31
32 typedef struct ObjectHeader ObjectHeader;
33 typedef union Object Object;
34
35 typedef struct DataObject DataObject;
36 typedef struct FieldObject FieldObject;
37 typedef struct EntryObject EntryObject;
38 typedef struct HashTableObject HashTableObject;
39 typedef struct EntryArrayObject EntryArrayObject;
40 typedef struct TagObject TagObject;
41
42 typedef struct EntryItem EntryItem;
43 typedef struct HashItem HashItem;
44
45 typedef struct FSPRGHeader FSPRGHeader;
46
47 /* Object types */
48 enum {
49 OBJECT_UNUSED,
50 OBJECT_DATA, /* !!! */
51 OBJECT_FIELD,
52 OBJECT_ENTRY,
53 OBJECT_DATA_HASH_TABLE,
54 OBJECT_FIELD_HASH_TABLE,
55 OBJECT_ENTRY_ARRAY, /* !!! */
56 OBJECT_TAG,
57 _OBJECT_TYPE_MAX
58 };
59
60 /* Object flags */
61 enum {
62 OBJECT_COMPRESSED = 1
63 };
64
65 _packed_ struct ObjectHeader {
66 uint8_t type;
67 uint8_t flags;
68 uint8_t reserved[6];
69 le64_t size;
70 uint8_t payload[];
71 };
72
73 _packed_ struct DataObject {
74 ObjectHeader object;
75 le64_t hash;
76 le64_t next_hash_offset;
77 le64_t next_field_offset;
78 le64_t entry_offset; /* the first array entry we store inline */
79 le64_t entry_array_offset;
80 le64_t n_entries;
81 uint8_t payload[];
82 };
83
84 _packed_ struct FieldObject {
85 ObjectHeader object;
86 le64_t hash;
87 le64_t next_hash_offset;
88 le64_t head_data_offset;
89 uint8_t payload[];
90 };
91
92 _packed_ struct EntryItem {
93 le64_t object_offset;
94 le64_t hash;
95 };
96
97 _packed_ struct EntryObject {
98 ObjectHeader object;
99 le64_t seqnum;
100 le64_t realtime;
101 le64_t monotonic;
102 sd_id128_t boot_id;
103 le64_t xor_hash;
104 EntryItem items[];
105 };
106
107 _packed_ struct HashItem {
108 le64_t head_hash_offset;
109 le64_t tail_hash_offset;
110 };
111
112 _packed_ struct HashTableObject {
113 ObjectHeader object;
114 HashItem items[];
115 };
116
117 _packed_ struct EntryArrayObject {
118 ObjectHeader object;
119 le64_t next_entry_array_offset;
120 le64_t items[];
121 };
122
123 #define TAG_LENGTH (256/8)
124
125 _packed_ struct TagObject {
126 ObjectHeader object;
127 uint64_t seqnum;
128 uint8_t tag[TAG_LENGTH]; /* SHA-256 HMAC */
129 };
130
131 union Object {
132 ObjectHeader object;
133 DataObject data;
134 FieldObject field;
135 EntryObject entry;
136 HashTableObject hash_table;
137 EntryArrayObject entry_array;
138 TagObject tag;
139 };
140
141 enum {
142 STATE_OFFLINE,
143 STATE_ONLINE,
144 STATE_ARCHIVED
145 };
146
147 /* Header flags */
148 enum {
149 HEADER_INCOMPATIBLE_COMPRESSED = 1
150 };
151
152 enum {
153 HEADER_COMPATIBLE_AUTHENTICATED = 1
154 };
155
156 #define HEADER_SIGNATURE ((char[]) { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' })
157
158 _packed_ struct Header {
159 uint8_t signature[8]; /* "LPKSHHRH" */
160 le32_t compatible_flags;
161 le32_t incompatible_flags;
162 uint8_t state;
163 uint8_t reserved[7];
164 sd_id128_t file_id;
165 sd_id128_t machine_id;
166 sd_id128_t boot_id; /* last writer */
167 sd_id128_t seqnum_id;
168 le64_t header_size;
169 le64_t arena_size;
170 le64_t data_hash_table_offset; /* for looking up data objects */
171 le64_t data_hash_table_size;
172 le64_t field_hash_table_offset; /* for looking up field objects */
173 le64_t field_hash_table_size;
174 le64_t tail_object_offset;
175 le64_t n_objects;
176 le64_t n_entries;
177 le64_t tail_entry_seqnum;
178 le64_t head_entry_seqnum;
179 le64_t entry_array_offset;
180 le64_t head_entry_realtime;
181 le64_t tail_entry_realtime;
182 le64_t tail_entry_monotonic;
183 /* Added in 187 */
184 le64_t n_data;
185 le64_t n_fields;
186 /* Added in 189 */
187 le64_t n_tags;
188 le64_t n_entry_arrays;
189 };
190
191 #define FSPRG_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' })
192
193 _packed_ struct FSPRGHeader {
194 uint8_t signature[8]; /* "KSHHRHLP" */
195 le32_t compatible_flags;
196 le32_t incompatible_flags;
197 sd_id128_t machine_id;
198 sd_id128_t boot_id; /* last writer */
199 le64_t header_size;
200 le64_t fsprg_start_usec;
201 le64_t fsprg_interval_usec;
202 le16_t secpar;
203 le16_t reserved[3];
204 le64_t state_size;
205 };