mail-transaction-log.h revision 0c909e3461607eadcd66f4eac69b7f34e37fccf1
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#ifndef MAIL_TRANSACTION_LOG_H
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define MAIL_TRANSACTION_LOG_H
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#include "mail-index.h"
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define MAIL_TRANSACTION_LOG_SUFFIX ".log"
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define MAIL_TRANSACTION_LOG_MAJOR_VERSION 1
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define MAIL_TRANSACTION_LOG_MINOR_VERSION 2
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE 24
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_log_header {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t major_version;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t minor_version;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t hdr_size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t indexid;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t file_seq;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t prev_file_seq;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t prev_file_offset;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t create_stamp;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint64_t initial_modseq; /* v1.1+ (note: log's major/minor version) */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t compat_flags; /* enum mail_index_header_compat_flags, v1.2+ */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t unused[3];
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t unused2; /* so that this struct is 64bit aligned */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschenum mail_transaction_type {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXPUNGE = 0x00000001,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_APPEND = 0x00000002,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_FLAG_UPDATE = 0x00000004,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_HEADER_UPDATE = 0x00000020,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_INTRO = 0x00000040,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_RESET = 0x00000080,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_HDR_UPDATE = 0x00000100,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_REC_UPDATE = 0x00000200,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_KEYWORD_UPDATE = 0x00000400,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_KEYWORD_RESET = 0x00000800,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_ATOMIC_INC = 0x00001000,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXPUNGE_GUID = 0x00002000,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_TYPE_MASK = 0x0000ffff,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define MAIL_TRANSACTION_EXT_MASK \
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch (MAIL_TRANSACTION_EXT_INTRO | MAIL_TRANSACTION_EXT_RESET | \
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_HDR_UPDATE | MAIL_TRANSACTION_EXT_REC_UPDATE | \
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_ATOMIC_INC)
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* since we'll expunge mails based on data read from transaction log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch try to avoid the possibility of corrupted transaction log expunging
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch messages. this value is ORed to the actual MAIL_TRANSACTION_EXPUNGE*
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch flag. if it's not present, assume corrupted log. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXPUNGE_PROT = 0x0000cd90,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* Mailbox synchronization noticed this change. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXTERNAL = 0x10000000
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_header {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t type; /* enum mail_transaction_type */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_expunge {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t uid1, uid2;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_expunge_guid {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t uid;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t guid_128[MAIL_GUID_128_SIZE];
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_flag_update {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t uid1, uid2;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t add_flags;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t remove_flags;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t padding;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_keyword_update {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t modify_type; /* enum modify_type : MODIFY_ADD / MODIFY_REMOVE */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t padding;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t name_size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char name[];
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch array of { uint32_t uid1, uid2; }
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_keyword_reset {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t uid1, uid2;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_header_update {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t offset;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char data[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschenum {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* Don't shrink hdr_size, record_size or record_align but grow them
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch if necessary. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch MAIL_TRANSACTION_EXT_INTRO_FLAG_NO_SHRINK = 0x01
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_ext_intro {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* old extension: set ext_id. don't set name.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch new extension: ext_id = (uint32_t)-1. give name. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t ext_id;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t reset_id;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t hdr_size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t record_size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t record_align;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t flags;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t name_size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char name[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_ext_reset {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t new_reset_id;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t preserve_data;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint8_t unused_padding[3];
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* these are set for the last ext_intro */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_ext_hdr_update {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t offset;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint16_t size;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char data[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_ext_rec_update {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t uid;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* unsigned char data[]; */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_ext_atomic_inc {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t uid;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch int32_t diff;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_log_append_ctx {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct mail_transaction_log *log;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch buffer_t *output;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint64_t new_highest_modseq;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch unsigned int external:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch unsigned int append_sync_offset:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch unsigned int sync_includes_this:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch unsigned int want_fsync:1;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch};
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#define LOG_IS_BEFORE(seq1, offset1, seq2, offset2) \
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch (((offset1) < (offset2) && (seq1) == (seq2)) || (seq1) < (seq2))
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_log *
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_alloc(struct mail_index *index);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_free(struct mail_transaction_log **log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Open the transaction log. Returns 1 if ok, 0 if file doesn't exist or it's
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch is corrupted, -1 if there was some I/O error. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_open(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Create, or recreate, the transaction log. Returns 0 if ok, -1 if error. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_create(struct mail_transaction_log *log, bool reset);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Close all the open transactions log files. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_close(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Notify of indexid change */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns the file seq/offset where the mailbox is currently synced at.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch Since the log is rotated only when mailbox is fully synced, the sequence
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch points always to the latest file. This function doesn't actually find the
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch latest sync position, so you'll need to use eg. log_view_set() before
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch calling this. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_get_mailbox_sync_pos(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t *file_seq_r,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uoff_t *file_offset_r);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Set the current mailbox sync position. file_seq must always be the latest
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch log file's sequence. The offset written automatically to the log when
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch other transactions are being written. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_set_mailbox_sync_pos(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t file_seq,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uoff_t file_offset);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschstruct mail_transaction_log_view *
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_open(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_close(struct mail_transaction_log_view **view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Set view boundaries. Returns -1 if error, 0 if files are lost, 1 if ok.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch reset_r=TRUE if the whole index should be reset before applying any
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch changes. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_view_set(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t min_file_seq, uoff_t min_file_offset,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t max_file_seq, uoff_t max_file_offset,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch bool *reset_r);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Clear the view. Keep oldest_file_seq and newer log files referenced so we
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch don't get desynced. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_clear(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t oldest_file_seq);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Read next transaction record from current position. The position is updated.
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch Returns -1 if error, 0 if we're at end of the view, 1 if ok. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_view_next(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const struct mail_transaction_header **hdr_r,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const void **data_r);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Mark the current view's position to the record returned previously with
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch _log_view_next(). */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_mark(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Seek to previously marked position. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_view_rewind(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
0afd9a9acab584e770ffcd6a0e1e02e2d18d360aJosef 'Jeff' Sipek/* Returns the position of the record returned previously with
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch mail_transaction_log_view_next() */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t *file_seq_r,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uoff_t *file_offset_r);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Return the modseq of the change returned previously with _view_next(). */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschuint64_t
c4588e66e80482994cf0fbc45251cb8e9db6404dJosef 'Jeff' Sipekmail_transaction_log_view_get_prev_modseq(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns TRUE if we're at the end of the view window. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschbool mail_transaction_log_view_is_last(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Marks the log file in current position to be corrupted. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *fmt, ...)
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch ATTR_FORMAT(2, 3);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschbool
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschmail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_views_close(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_append_begin(struct mail_index *index, bool external,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct mail_transaction_log_append_ctx **ctx_r);
4a1af46c8ed806fbc51bedfaf79c019b0afa3aa6Stephan Boschvoid mail_transaction_log_append_add(struct mail_transaction_log_append_ctx *ctx,
4a1af46c8ed806fbc51bedfaf79c019b0afa3aa6Stephan Bosch enum mail_transaction_type type,
a46221f25bbaf310f73f77bec24f2d3f0c80d4feStephan Bosch const void *data, size_t size);
a46221f25bbaf310f73f77bec24f2d3f0c80d4feStephan Boschint mail_transaction_log_append_commit(struct mail_transaction_log_append_ctx **ctx);
a46221f25bbaf310f73f77bec24f2d3f0c80d4feStephan Bosch
a46221f25bbaf310f73f77bec24f2d3f0c80d4feStephan Bosch/* Lock transaction log for index synchronization. Log cannot be read or
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch written to while it's locked. Returns end offset. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschint mail_transaction_log_sync_lock(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t *file_seq_r, uoff_t *file_offset_r);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_sync_unlock(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns the current head. Works only when log is locked. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_get_head(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t *file_seq_r, uoff_t *file_offset_r);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Returns TRUE if given seq/offset is current head log's rotate point. */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschbool mail_transaction_log_is_head_prev(struct mail_transaction_log *log,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch uint32_t file_seq, uoff_t file_offset);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Move currently opened log head file to memory (called by
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch mail_index_move_to_memory()) */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#endif
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch