journal-def.h revision 92261977d81fd6a5bfb1418eddd86582d8a57fcd
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack#pragma once
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack/***
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack This file is part of systemd.
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack Copyright 2011 Lennart Poettering
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack systemd is free software; you can redistribute it and/or modify it
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack under the terms of the GNU Lesser General Public License as published by
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack the Free Software Foundation; either version 2.1 of the License, or
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack (at your option) any later version.
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack systemd is distributed in the hope that it will be useful, but
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack WITHOUT ANY WARRANTY; without even the implied warranty of
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack Lesser General Public License for more details.
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack You should have received a copy of the GNU Lesser General Public License
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack along with systemd; If not, see <http://www.gnu.org/licenses/>.
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack***/
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack#include "sparse-endian.h"
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack#include <systemd/sd-id128.h>
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack#include "macro.h"
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack/*
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack * If you change this file you probably should also change its documentation:
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack *
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack * http://www.freedesktop.org/wiki/Software/systemd/journal-files
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack *
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack */
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct Header Header;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct ObjectHeader ObjectHeader;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef union Object Object;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct DataObject DataObject;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct FieldObject FieldObject;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct EntryObject EntryObject;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct HashTableObject HashTableObject;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct EntryArrayObject EntryArrayObject;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct TagObject TagObject;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct EntryItem EntryItem;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct HashItem HashItem;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Macktypedef struct FSSHeader FSSHeader;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack/* Object types */
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mackenum {
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_UNUSED,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_DATA,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_FIELD,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_ENTRY,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_DATA_HASH_TABLE,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_FIELD_HASH_TABLE,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_ENTRY_ARRAY,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_TAG,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack _OBJECT_TYPE_MAX
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack};
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack/* Object flags */
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mackenum {
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_COMPRESSED_XZ = 1 << 0,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack OBJECT_COMPRESSED_LZ4 = 1 << 1,
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack _OBJECT_COMPRESSED_MAX
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack};
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack#define OBJECT_COMPRESSION_MASK (OBJECT_COMPRESSED_XZ | OBJECT_COMPRESSED_LZ4)
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mackstruct ObjectHeader {
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack uint8_t type;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack uint8_t flags;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack uint8_t reserved[6];
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack le64_t size;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack uint8_t payload[];
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack} _packed_;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mackstruct DataObject {
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack ObjectHeader object;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack le64_t hash;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack le64_t next_hash_offset;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack le64_t next_field_offset;
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack le64_t entry_offset; /* the first array entry we store inline */
bb7dd0b04a6e89674100476eed0bbd05c6a4cbd8Daniel Mack le64_t entry_array_offset;
le64_t n_entries;
uint8_t payload[];
} _packed_;
struct FieldObject {
ObjectHeader object;
le64_t hash;
le64_t next_hash_offset;
le64_t head_data_offset;
uint8_t payload[];
} _packed_;
struct EntryItem {
le64_t object_offset;
le64_t hash;
} _packed_;
struct EntryObject {
ObjectHeader object;
le64_t seqnum;
le64_t realtime;
le64_t monotonic;
sd_id128_t boot_id;
le64_t xor_hash;
EntryItem items[];
} _packed_;
struct HashItem {
le64_t head_hash_offset;
le64_t tail_hash_offset;
} _packed_;
struct HashTableObject {
ObjectHeader object;
HashItem items[];
} _packed_;
struct EntryArrayObject {
ObjectHeader object;
le64_t next_entry_array_offset;
le64_t items[];
} _packed_;
#define TAG_LENGTH (256/8)
struct TagObject {
ObjectHeader object;
le64_t seqnum;
le64_t epoch;
uint8_t tag[TAG_LENGTH]; /* SHA-256 HMAC */
} _packed_;
union Object {
ObjectHeader object;
DataObject data;
FieldObject field;
EntryObject entry;
HashTableObject hash_table;
EntryArrayObject entry_array;
TagObject tag;
};
enum {
STATE_OFFLINE = 0,
STATE_ONLINE = 1,
STATE_ARCHIVED = 2,
_STATE_MAX
};
/* Header flags */
enum {
HEADER_INCOMPATIBLE_COMPRESSED_XZ = 1 << 0,
HEADER_INCOMPATIBLE_COMPRESSED_LZ4 = 1 << 1,
};
#define HEADER_INCOMPATIBLE_ANY (HEADER_INCOMPATIBLE_COMPRESSED_XZ|HEADER_INCOMPATIBLE_COMPRESSED_LZ4)
#if defined(HAVE_XZ) && defined(HAVE_LZ4)
# define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_ANY
#elif defined(HAVE_XZ)
# define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_COMPRESSED_XZ
#elif defined(HAVE_LZ4)
# define HEADER_INCOMPATIBLE_SUPPORTED HEADER_INCOMPATIBLE_COMPRESSED_LZ4
#else
# define HEADER_INCOMPATIBLE_SUPPORTED 0
#endif
enum {
HEADER_COMPATIBLE_SEALED = 1
};
#define HEADER_COMPATIBLE_ANY HEADER_COMPATIBLE_SEALED
#ifdef HAVE_GCRYPT
# define HEADER_COMPATIBLE_SUPPORTED HEADER_COMPATIBLE_SEALED
#else
# define HEADER_COMPATIBLE_SUPPORTED 0
#endif
#define HEADER_SIGNATURE ((char[]) { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' })
struct Header {
uint8_t signature[8]; /* "LPKSHHRH" */
le32_t compatible_flags;
le32_t incompatible_flags;
uint8_t state;
uint8_t reserved[7];
sd_id128_t file_id;
sd_id128_t machine_id;
sd_id128_t boot_id; /* last writer */
sd_id128_t seqnum_id;
le64_t header_size;
le64_t arena_size;
le64_t data_hash_table_offset;
le64_t data_hash_table_size;
le64_t field_hash_table_offset;
le64_t field_hash_table_size;
le64_t tail_object_offset;
le64_t n_objects;
le64_t n_entries;
le64_t tail_entry_seqnum;
le64_t head_entry_seqnum;
le64_t entry_array_offset;
le64_t head_entry_realtime;
le64_t tail_entry_realtime;
le64_t tail_entry_monotonic;
/* Added in 187 */
le64_t n_data;
le64_t n_fields;
/* Added in 189 */
le64_t n_tags;
le64_t n_entry_arrays;
/* Size: 224 */
} _packed_;
#define FSS_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' })
struct FSSHeader {
uint8_t signature[8]; /* "KSHHRHLP" */
le32_t compatible_flags;
le32_t incompatible_flags;
sd_id128_t machine_id;
sd_id128_t boot_id; /* last writer */
le64_t header_size;
le64_t start_usec;
le64_t interval_usec;
le16_t fsprg_secpar;
le16_t reserved[3];
le64_t fsprg_state_size;
} _packed_;