chiark / gitweb /
Merge branch 'journal'
[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 General Public License as published by
13   the Free Software Foundation; either version 2 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   General Public License for more details.
20
21   You should have received a copy of the GNU General Public License
22   along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 ***/
24
25 #include <inttypes.h>
26
27 #include "macro.h"
28 #include "sd-id128.h"
29
30 typedef struct Header Header;
31 typedef struct ObjectHeader ObjectHeader;
32 typedef union Object Object;
33 typedef struct DataObject DataObject;
34 typedef struct FieldObject FieldObject;
35 typedef struct EntryObject EntryObject;
36 typedef struct HashTableObject HashTableObject;
37 typedef struct EntryArrayObject EntryArrayObject;
38 typedef struct EntryItem EntryItem;
39 typedef struct HashItem HashItem;
40
41 /* Object types */
42 enum {
43         OBJECT_UNUSED,
44         OBJECT_DATA,
45         OBJECT_FIELD,
46         OBJECT_ENTRY,
47         OBJECT_DATA_HASH_TABLE,
48         OBJECT_FIELD_HASH_TABLE,
49         OBJECT_ENTRY_ARRAY,
50         _OBJECT_TYPE_MAX
51 };
52
53 /* Object flags */
54 enum {
55         OBJECT_COMPRESSED = 1
56 };
57
58 _packed_ struct ObjectHeader {
59         uint8_t type;
60         uint8_t flags;
61         uint8_t reserved[6];
62         uint64_t size;
63         uint8_t payload[];
64 };
65
66 _packed_ struct DataObject {
67         ObjectHeader object;
68         uint64_t hash;
69         uint64_t next_hash_offset;
70         uint64_t next_field_offset;
71         uint64_t entry_offset; /* the first array entry we store inline */
72         uint64_t entry_array_offset;
73         uint64_t n_entries;
74         uint8_t payload[];
75 };
76
77 _packed_ struct FieldObject {
78         ObjectHeader object;
79         uint64_t hash;
80         uint64_t next_hash_offset;
81         uint64_t head_data_offset;
82         uint64_t tail_data_offset;
83         uint8_t payload[];
84 };
85
86 _packed_ struct EntryItem {
87         uint64_t object_offset;
88         uint64_t hash;
89 };
90
91 _packed_ struct EntryObject {
92         ObjectHeader object;
93         uint64_t seqnum;
94         uint64_t realtime;
95         uint64_t monotonic;
96         sd_id128_t boot_id;
97         uint64_t xor_hash;
98         EntryItem items[];
99 };
100
101 _packed_ struct HashItem {
102         uint64_t head_hash_offset;
103         uint64_t tail_hash_offset;
104 };
105
106 _packed_ struct HashTableObject {
107         ObjectHeader object;
108         HashItem items[];
109 };
110
111 _packed_ struct EntryArrayObject {
112         ObjectHeader object;
113         uint64_t next_entry_array_offset;
114         uint64_t items[];
115 };
116
117 union Object {
118         ObjectHeader object;
119         DataObject data;
120         FieldObject field;
121         EntryObject entry;
122         HashTableObject hash_table;
123         EntryArrayObject entry_array;
124 };
125
126 enum {
127         STATE_OFFLINE,
128         STATE_ONLINE,
129         STATE_ARCHIVED
130 };
131
132 /* Header flags */
133 enum {
134         HEADER_INCOMPATIBLE_COMPRESSED = 1
135 };
136
137 _packed_ struct Header {
138         uint8_t signature[8]; /* "LPKSHHRH" */
139         uint32_t compatible_flags;
140         uint32_t incompatible_flags;
141         uint8_t state;
142         uint8_t reserved[7];
143         sd_id128_t file_id;
144         sd_id128_t machine_id;
145         sd_id128_t boot_id;
146         sd_id128_t seqnum_id;
147         uint64_t arena_offset;
148         uint64_t arena_size;
149         uint64_t data_hash_table_offset;     /* for looking up data objects */
150         uint64_t data_hash_table_size;
151         uint64_t field_hash_table_offset;     /* for looking up field objects */
152         uint64_t field_hash_table_size;
153         uint64_t tail_object_offset;
154         uint64_t n_objects;
155         uint64_t n_entries;
156         uint64_t seqnum;
157         uint64_t first_seqnum;
158         uint64_t entry_array_offset;
159         uint64_t head_entry_realtime;
160         uint64_t tail_entry_realtime;
161         uint64_t tail_entry_monotonic;
162 };
163
164 #endif