journal-internal.h revision a3eb665e0c12df35e807611582e7332ebed325b1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#pragma once
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/***
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2011 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek***/
0dae31d468b1a0e22d98921f7b0dbd92fd217167Zbigniew Jędrzejewski-Szmek
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek#include <sys/types.h>
2e276efc7b0398a3086629a52970bdd4ab7252f9Zbigniew Jędrzejewski-Szmek#include <inttypes.h>
322345fdb9865ef2477fba8e4bdde0e1183ef505Lennart Poettering#include <stdbool.h>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include <systemd/sd-id128.h>
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering#include "journal-def.h"
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering#include "list.h"
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering#include "hashmap.h"
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering#include "journal-file.h"
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringtypedef struct Match Match;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringtypedef struct Location Location;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringtypedef struct Directory Directory;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringtypedef enum MatchType {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering MATCH_DISCRETE,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering MATCH_OR_TERM,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering MATCH_AND_TERM
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering} MatchType;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstruct Match {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering MatchType type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Match *parent;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LIST_FIELDS(Match, matches);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* For concrete matches */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering char *data;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering size_t size;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering le64_t le_hash;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* For terms */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LIST_HEAD(Match, matches);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering};
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringtypedef enum LocationType {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* The first and last entries, resp. */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LOCATION_HEAD,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LOCATION_TAIL,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* We already read the entry we currently point to, and the
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * next one to read should probably not be this one again. */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LOCATION_DISCRETE,
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering /* We should seek to the precise location specified, and
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering * return it, as we haven't read it yet. */
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LOCATION_SEEK
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering} LocationType;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstruct Location {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering LocationType type;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering uint64_t seqnum;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering sd_id128_t seqnum_id;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering bool seqnum_set;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering uint64_t realtime;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering bool realtime_set;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering uint64_t monotonic;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering sd_id128_t boot_id;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering bool monotonic_set;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering uint64_t xor_hash;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering bool xor_hash_set;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering};
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstruct Directory {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering char *path;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering int wd;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering bool is_root;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering};
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringstruct sd_journal {
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering int flags;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering char *path;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Hashmap *files;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering MMapCache *mmap;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Location current_location;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering JournalFile *current_file;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering uint64_t current_field;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Hashmap *directories_by_path;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Hashmap *directories_by_wd;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering int inotify_fd;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering Match *level0, *level1;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering unsigned current_invalidate_counter, last_invalidate_counter;
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering};
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringchar *journal_make_match_string(sd_journal *j);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poetteringvoid journal_print_header(sd_journal *j);
faa133f3aa7a18f26563dc5d6b95898cb315c37aLennart Poettering