chiark / gitweb /
use #pragma once instead of foo*foo #define guards
[elogind.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 SignatureObject SignatureObject;
41
42 typedef struct EntryItem EntryItem;
43 typedef struct HashItem HashItem;
44
45 /* Object types */
46 enum {
47         OBJECT_UNUSED,
48         OBJECT_DATA,
49         OBJECT_FIELD,
50         OBJECT_ENTRY,
51         OBJECT_DATA_HASH_TABLE,
52         OBJECT_FIELD_HASH_TABLE,
53         OBJECT_ENTRY_ARRAY,
54         OBJECT_SIGNATURE,
55         _OBJECT_TYPE_MAX
56 };
57
58 /* Object flags */
59 enum {
60         OBJECT_COMPRESSED = 1
61 };
62
63 _packed_ struct ObjectHeader {
64         uint8_t type;
65         uint8_t flags;
66         uint8_t reserved[6];
67         le64_t size;
68         uint8_t payload[];
69 };
70
71 _packed_ struct DataObject {
72         ObjectHeader object;
73         le64_t hash;
74         le64_t next_hash_offset;
75         le64_t next_field_offset;
76         le64_t entry_offset; /* the first array entry we store inline */
77         le64_t entry_array_offset;
78         le64_t n_entries;
79         uint8_t payload[];
80 };
81
82 _packed_ struct FieldObject {
83         ObjectHeader object;
84         le64_t hash;
85         le64_t next_hash_offset;
86         le64_t head_data_offset;
87         le64_t tail_data_offset;
88         uint8_t payload[];
89 };
90
91 _packed_ struct EntryItem {
92         le64_t object_offset;
93         le64_t hash;
94 };
95
96 _packed_ struct EntryObject {
97         ObjectHeader object;
98         le64_t seqnum;
99         le64_t realtime;
100         le64_t monotonic;
101         sd_id128_t boot_id;
102         le64_t xor_hash;
103         EntryItem items[];
104 };
105
106 _packed_ struct HashItem {
107         le64_t head_hash_offset;
108         le64_t tail_hash_offset;
109 };
110
111 _packed_ struct HashTableObject {
112         ObjectHeader object;
113         HashItem items[];
114 };
115
116 _packed_ struct EntryArrayObject {
117         ObjectHeader object;
118         le64_t next_entry_array_offset;
119         le64_t items[];
120 };
121
122 #define SIGNATURE_LENGTH 160
123
124 _packed_ struct SignatureObject {
125         ObjectHeader object;
126         le64_t from;
127         uint8_t signature[SIGNATURE_LENGTH];
128 };
129
130 union Object {
131         ObjectHeader object;
132         DataObject data;
133         FieldObject field;
134         EntryObject entry;
135         HashTableObject hash_table;
136         EntryArrayObject entry_array;
137         SignatureObject signature;
138 };
139
140 enum {
141         STATE_OFFLINE,
142         STATE_ONLINE,
143         STATE_ARCHIVED
144 };
145
146 /* Header flags */
147 enum {
148         HEADER_INCOMPATIBLE_COMPRESSED = 1
149 };
150
151 enum {
152         HEADER_COMPATIBLE_SIGNED = 1
153 };
154
155 _packed_ struct Header {
156         uint8_t signature[8]; /* "LPKSHHRH" */
157         uint32_t compatible_flags;
158         uint32_t incompatible_flags;
159         uint8_t state;
160         uint8_t reserved[7];
161         sd_id128_t file_id;
162         sd_id128_t machine_id; /* last writer */
163         sd_id128_t boot_id;    /* last writer */
164         sd_id128_t seqnum_id;
165         le64_t header_size;
166         le64_t arena_size;
167         le64_t data_hash_table_offset;     /* for looking up data objects */
168         le64_t data_hash_table_size;
169         le64_t field_hash_table_offset;     /* for looking up field objects */
170         le64_t field_hash_table_size;
171         le64_t tail_object_offset;
172         le64_t n_objects;
173         le64_t n_entries;
174         le64_t tail_seqnum;
175         le64_t head_seqnum;
176         le64_t entry_array_offset;
177         le64_t head_entry_realtime;
178         le64_t tail_entry_realtime;
179         le64_t tail_entry_monotonic;
180         /* Added in 187 */
181         le64_t n_data;
182         le64_t n_fields;
183 };