2011-10-07 21:06:39 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
|
2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2011-10-07 21:06:39 +02:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2011 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2011-10-07 21:06:39 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2011-10-07 21:06:39 +02:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2011-10-07 21:06:39 +02:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2012-03-16 11:59:04 +01:00
|
|
|
#include "sparse-endian.h"
|
2011-10-07 21:06:39 +02:00
|
|
|
|
2012-01-05 16:01:58 +01:00
|
|
|
#include <systemd/sd-id128.h>
|
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
#include "macro.h"
|
|
|
|
|
|
|
|
typedef struct Header Header;
|
2012-06-05 20:45:54 +02:00
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
typedef struct ObjectHeader ObjectHeader;
|
|
|
|
typedef union Object Object;
|
2012-06-05 20:45:54 +02:00
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
typedef struct DataObject DataObject;
|
2011-11-08 18:20:03 +01:00
|
|
|
typedef struct FieldObject FieldObject;
|
2011-10-07 21:06:39 +02:00
|
|
|
typedef struct EntryObject EntryObject;
|
|
|
|
typedef struct HashTableObject HashTableObject;
|
2011-11-08 18:20:03 +01:00
|
|
|
typedef struct EntryArrayObject EntryArrayObject;
|
2012-08-13 20:31:10 +02:00
|
|
|
typedef struct TagObject TagObject;
|
2012-06-05 20:45:54 +02:00
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
typedef struct EntryItem EntryItem;
|
|
|
|
typedef struct HashItem HashItem;
|
|
|
|
|
2012-08-13 20:31:10 +02:00
|
|
|
typedef struct FSPRGHeader FSPRGHeader;
|
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
/* Object types */
|
|
|
|
enum {
|
|
|
|
OBJECT_UNUSED,
|
2012-08-16 17:09:53 +02:00
|
|
|
OBJECT_DATA, /* !!! */
|
2011-11-08 18:20:03 +01:00
|
|
|
OBJECT_FIELD,
|
2011-10-07 21:06:39 +02:00
|
|
|
OBJECT_ENTRY,
|
2011-11-08 18:20:03 +01:00
|
|
|
OBJECT_DATA_HASH_TABLE,
|
|
|
|
OBJECT_FIELD_HASH_TABLE,
|
2012-08-16 17:09:53 +02:00
|
|
|
OBJECT_ENTRY_ARRAY, /* !!! */
|
2012-08-13 20:31:10 +02:00
|
|
|
OBJECT_TAG,
|
2011-11-08 18:20:03 +01:00
|
|
|
_OBJECT_TYPE_MAX
|
2011-10-07 21:06:39 +02:00
|
|
|
};
|
|
|
|
|
2011-12-21 02:40:59 +01:00
|
|
|
/* Object flags */
|
|
|
|
enum {
|
|
|
|
OBJECT_COMPRESSED = 1
|
|
|
|
};
|
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
_packed_ struct ObjectHeader {
|
|
|
|
uint8_t type;
|
2011-12-21 02:40:59 +01:00
|
|
|
uint8_t flags;
|
|
|
|
uint8_t reserved[6];
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t size;
|
2011-10-07 21:06:39 +02:00
|
|
|
uint8_t payload[];
|
|
|
|
};
|
|
|
|
|
|
|
|
_packed_ struct DataObject {
|
|
|
|
ObjectHeader object;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t hash;
|
|
|
|
le64_t next_hash_offset;
|
|
|
|
le64_t next_field_offset;
|
|
|
|
le64_t entry_offset; /* the first array entry we store inline */
|
|
|
|
le64_t entry_array_offset;
|
|
|
|
le64_t n_entries;
|
2011-11-08 18:20:03 +01:00
|
|
|
uint8_t payload[];
|
|
|
|
};
|
|
|
|
|
|
|
|
_packed_ struct FieldObject {
|
|
|
|
ObjectHeader object;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t hash;
|
|
|
|
le64_t next_hash_offset;
|
|
|
|
le64_t head_data_offset;
|
2011-10-07 21:06:39 +02:00
|
|
|
uint8_t payload[];
|
|
|
|
};
|
|
|
|
|
|
|
|
_packed_ struct EntryItem {
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t object_offset;
|
|
|
|
le64_t hash;
|
2011-10-07 21:06:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
_packed_ struct EntryObject {
|
|
|
|
ObjectHeader object;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t seqnum;
|
|
|
|
le64_t realtime;
|
|
|
|
le64_t monotonic;
|
2011-10-08 02:20:44 +02:00
|
|
|
sd_id128_t boot_id;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t xor_hash;
|
2011-10-07 21:06:39 +02:00
|
|
|
EntryItem items[];
|
|
|
|
};
|
|
|
|
|
|
|
|
_packed_ struct HashItem {
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t head_hash_offset;
|
|
|
|
le64_t tail_hash_offset;
|
2011-10-07 21:06:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
_packed_ struct HashTableObject {
|
|
|
|
ObjectHeader object;
|
2011-11-08 18:20:03 +01:00
|
|
|
HashItem items[];
|
2011-10-07 21:06:39 +02:00
|
|
|
};
|
|
|
|
|
2011-11-08 18:20:03 +01:00
|
|
|
_packed_ struct EntryArrayObject {
|
2011-10-07 21:06:39 +02:00
|
|
|
ObjectHeader object;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t next_entry_array_offset;
|
|
|
|
le64_t items[];
|
2011-10-07 21:06:39 +02:00
|
|
|
};
|
|
|
|
|
2012-08-13 20:31:10 +02:00
|
|
|
#define TAG_LENGTH (256/8)
|
2012-06-05 20:45:54 +02:00
|
|
|
|
2012-08-13 20:31:10 +02:00
|
|
|
_packed_ struct TagObject {
|
2012-06-05 20:45:54 +02:00
|
|
|
ObjectHeader object;
|
2012-08-13 21:52:58 +02:00
|
|
|
uint64_t seqnum;
|
2012-08-13 20:31:10 +02:00
|
|
|
uint8_t tag[TAG_LENGTH]; /* SHA-256 HMAC */
|
2012-06-05 20:45:54 +02:00
|
|
|
};
|
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
union Object {
|
|
|
|
ObjectHeader object;
|
|
|
|
DataObject data;
|
2011-11-08 18:20:03 +01:00
|
|
|
FieldObject field;
|
2011-10-07 21:06:39 +02:00
|
|
|
EntryObject entry;
|
|
|
|
HashTableObject hash_table;
|
2011-11-08 18:20:03 +01:00
|
|
|
EntryArrayObject entry_array;
|
2012-08-13 20:31:10 +02:00
|
|
|
TagObject tag;
|
2011-10-07 21:06:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
STATE_OFFLINE,
|
|
|
|
STATE_ONLINE,
|
|
|
|
STATE_ARCHIVED
|
|
|
|
};
|
|
|
|
|
2011-12-21 02:40:59 +01:00
|
|
|
/* Header flags */
|
|
|
|
enum {
|
|
|
|
HEADER_INCOMPATIBLE_COMPRESSED = 1
|
|
|
|
};
|
|
|
|
|
2012-06-05 20:45:54 +02:00
|
|
|
enum {
|
2012-08-13 20:31:10 +02:00
|
|
|
HEADER_COMPATIBLE_AUTHENTICATED = 1
|
2012-06-05 20:45:54 +02:00
|
|
|
};
|
|
|
|
|
2012-08-13 20:31:10 +02:00
|
|
|
#define HEADER_SIGNATURE ((char[]) { 'L', 'P', 'K', 'S', 'H', 'H', 'R', 'H' })
|
|
|
|
|
2011-10-07 21:06:39 +02:00
|
|
|
_packed_ struct Header {
|
|
|
|
uint8_t signature[8]; /* "LPKSHHRH" */
|
2012-08-13 20:31:10 +02:00
|
|
|
le32_t compatible_flags;
|
|
|
|
le32_t incompatible_flags;
|
2011-11-08 18:20:03 +01:00
|
|
|
uint8_t state;
|
|
|
|
uint8_t reserved[7];
|
2011-10-07 21:06:39 +02:00
|
|
|
sd_id128_t file_id;
|
2012-08-13 20:31:10 +02:00
|
|
|
sd_id128_t machine_id;
|
2012-06-09 10:32:38 +02:00
|
|
|
sd_id128_t boot_id; /* last writer */
|
2011-10-08 02:20:44 +02:00
|
|
|
sd_id128_t seqnum_id;
|
2012-06-05 20:32:55 +02:00
|
|
|
le64_t header_size;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t arena_size;
|
|
|
|
le64_t data_hash_table_offset; /* for looking up data objects */
|
|
|
|
le64_t data_hash_table_size;
|
|
|
|
le64_t field_hash_table_offset; /* for looking up field objects */
|
|
|
|
le64_t field_hash_table_size;
|
|
|
|
le64_t tail_object_offset;
|
|
|
|
le64_t n_objects;
|
|
|
|
le64_t n_entries;
|
2012-08-15 01:54:09 +02:00
|
|
|
le64_t tail_entry_seqnum;
|
|
|
|
le64_t head_entry_seqnum;
|
2012-03-16 11:59:04 +01:00
|
|
|
le64_t entry_array_offset;
|
|
|
|
le64_t head_entry_realtime;
|
|
|
|
le64_t tail_entry_realtime;
|
|
|
|
le64_t tail_entry_monotonic;
|
2012-07-16 22:24:02 +02:00
|
|
|
/* Added in 187 */
|
|
|
|
le64_t n_data;
|
|
|
|
le64_t n_fields;
|
2012-08-13 21:52:58 +02:00
|
|
|
/* Added in 189 */
|
|
|
|
le64_t n_tags;
|
2011-10-07 21:06:39 +02:00
|
|
|
};
|
2012-08-13 20:31:10 +02:00
|
|
|
|
|
|
|
#define FSPRG_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' })
|
|
|
|
|
|
|
|
_packed_ struct FSPRGHeader {
|
|
|
|
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 fsprg_start_usec;
|
|
|
|
le64_t fsprg_interval_usec;
|
|
|
|
le16_t secpar;
|
|
|
|
le16_t reserved[3];
|
|
|
|
le64_t state_size;
|
|
|
|
};
|