chiark / gitweb /
journal: add basic object definition for signatures
[elogind.git] / src / journal / journal-def.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #ifndef foojournaldefhfoo
4 #define foojournaldefhfoo
5
6 /***
7   This file is part of systemd.
8
9   Copyright 2011 Lennart Poettering
10
11   systemd is free software; you can redistribute it and/or modify it
12   under the terms of the GNU Lesser General Public License as published by
13   the Free Software Foundation; either version 2.1 of the License, or
14   (at your option) any later version.
15
16   systemd is distributed in the hope that it will be useful, but
17   WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   Lesser General Public License for more details.
20
21   You should have received a copy of the GNU Lesser General Public License
22   along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 ***/
24
25 #include "sparse-endian.h"
26
27 #include <systemd/sd-id128.h>
28
29 #include "macro.h"
30
31 typedef struct Header Header;
32
33 typedef struct ObjectHeader ObjectHeader;
34 typedef union Object Object;
35
36 typedef struct DataObject DataObject;
37 typedef struct FieldObject FieldObject;
38 typedef struct EntryObject EntryObject;
39 typedef struct HashTableObject HashTableObject;
40 typedef struct EntryArrayObject EntryArrayObject;
41 typedef struct SignatureObject SignatureObject;
42
43 typedef struct EntryItem EntryItem;
44 typedef struct HashItem HashItem;
45
46 /* Object types */
47 enum {
48         OBJECT_UNUSED,
49         OBJECT_DATA,
50         OBJECT_FIELD,
51         OBJECT_ENTRY,
52         OBJECT_DATA_HASH_TABLE,
53         OBJECT_FIELD_HASH_TABLE,
54         OBJECT_ENTRY_ARRAY,
55         OBJECT_SIGNATURE,
56         _OBJECT_TYPE_MAX
57 };
58
59 /* Object flags */
60 enum {
61         OBJECT_COMPRESSED = 1
62 };
63
64 _packed_ struct ObjectHeader {
65         uint8_t type;
66         uint8_t flags;
67         uint8_t reserved[6];
68         le64_t size;
69         uint8_t payload[];
70 };
71
72 _packed_ struct DataObject {
73         ObjectHeader object;
74         le64_t hash;
75         le64_t next_hash_offset;
76         le64_t next_field_offset;
77         le64_t entry_offset; /* the first array entry we store inline */
78         le64_t entry_array_offset;
79         le64_t n_entries;
80         uint8_t payload[];
81 };
82
83 _packed_ struct FieldObject {
84         ObjectHeader object;
85         le64_t hash;
86         le64_t next_hash_offset;
87         le64_t head_data_offset;
88         le64_t tail_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 SIGNATURE_LENGTH 160
124
125 _packed_ struct SignatureObject {
126         ObjectHeader object;
127         le64_t from;
128         uint8_t signature[SIGNATURE_LENGTH];
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         SignatureObject signature;
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_SIGNED = 1
154 };
155
156 _packed_ struct Header {
157         uint8_t signature[8]; /* "LPKSHHRH" */
158         uint32_t compatible_flags;
159         uint32_t incompatible_flags;
160         uint8_t state;
161         uint8_t reserved[7];
162         sd_id128_t file_id;
163         sd_id128_t machine_id;
164         sd_id128_t boot_id;
165         sd_id128_t seqnum_id;
166         le64_t header_size;
167         le64_t arena_size;
168         le64_t data_hash_table_offset;     /* for looking up data objects */
169         le64_t data_hash_table_size;
170         le64_t field_hash_table_offset;     /* for looking up field objects */
171         le64_t field_hash_table_size;
172         le64_t tail_object_offset;
173         le64_t n_objects;
174         le64_t n_entries;
175         le64_t seqnum;
176         le64_t first_seqnum;
177         le64_t entry_array_offset;
178         le64_t head_entry_realtime;
179         le64_t tail_entry_realtime;
180         le64_t tail_entry_monotonic;
181 };
182
183 #endif