chiark / gitweb /
journal: add native protocol to journald, and client side API to send journal messages
[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 _packed_ struct ObjectHeader {
54         uint8_t type;
55         uint8_t reserved[7];
56         uint64_t size;
57         uint8_t payload[];
58 };
59
60 _packed_ struct DataObject {
61         ObjectHeader object;
62         uint64_t hash;
63         uint64_t next_hash_offset;
64         uint64_t next_field_offset;
65         uint64_t entry_offset; /* the first array entry we store inline */
66         uint64_t entry_array_offset;
67         uint64_t n_entries;
68         uint8_t payload[];
69 };
70
71 _packed_ struct FieldObject {
72         ObjectHeader object;
73         uint64_t hash;
74         uint64_t next_hash_offset;
75         uint64_t head_data_offset;
76         uint64_t tail_data_offset;
77         uint8_t payload[];
78 };
79
80 _packed_ struct EntryItem {
81         uint64_t object_offset;
82         uint64_t hash;
83 };
84
85 _packed_ struct EntryObject {
86         ObjectHeader object;
87         uint64_t seqnum;
88         uint64_t realtime;
89         uint64_t monotonic;
90         sd_id128_t boot_id;
91         uint64_t xor_hash;
92         EntryItem items[];
93 };
94
95 _packed_ struct HashItem {
96         uint64_t head_hash_offset;
97         uint64_t tail_hash_offset;
98 };
99
100 _packed_ struct HashTableObject {
101         ObjectHeader object;
102         HashItem items[];
103 };
104
105 _packed_ struct EntryArrayObject {
106         ObjectHeader object;
107         uint64_t next_entry_array_offset;
108         uint64_t items[];
109 };
110
111 union Object {
112         ObjectHeader object;
113         DataObject data;
114         FieldObject field;
115         EntryObject entry;
116         HashTableObject hash_table;
117         EntryArrayObject entry_array;
118 };
119
120 enum {
121         STATE_OFFLINE,
122         STATE_ONLINE,
123         STATE_ARCHIVED
124 };
125
126 _packed_ struct Header {
127         uint8_t signature[8]; /* "LPKSHHRH" */
128         uint32_t compatible_flags;
129         uint32_t incompatible_flags;
130         uint8_t state;
131         uint8_t reserved[7];
132         sd_id128_t file_id;
133         sd_id128_t machine_id;
134         sd_id128_t boot_id;
135         sd_id128_t seqnum_id;
136         uint64_t arena_offset;
137         uint64_t arena_size;
138         uint64_t arena_max_size;  /* obsolete */
139         uint64_t arena_min_size;  /* obsolete */
140         uint64_t arena_keep_free; /* obsolete */
141         uint64_t data_hash_table_offset;     /* for looking up data objects */
142         uint64_t data_hash_table_size;
143         uint64_t field_hash_table_offset;     /* for looking up field objects */
144         uint64_t field_hash_table_size;
145         uint64_t tail_object_offset;
146         uint64_t n_objects;
147         uint64_t n_entries;
148         uint64_t seqnum;
149         uint64_t first_seqnum;
150         uint64_t entry_array_offset;
151         uint64_t head_entry_realtime;
152         uint64_t tail_entry_realtime;
153         uint64_t tail_entry_monotonic;
154 };
155
156 #endif