mail-transaction-log-file.c revision c0d1bfc45e224251cb549de8d8804861e8acb517
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen/* Copyright (c) 2003-2016 Dovecot authors, see the included COPYING file */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#define MEMORY_LOG_NAME "(in-memory transaction log file)"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenmail_transaction_log_file_sync(struct mail_transaction_log_file *file);
2271d1a3dfc7191e610f039e86b9245bbc5dfb8cTimo Sirainenlog_file_set_syscall_error(struct mail_transaction_log_file *file,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen mail_index_file_set_syscall_error(file->log->index,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainenmail_transaction_log_mark_corrupted(struct mail_transaction_log_file *file)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen unsigned int offset =
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen offsetof(struct mail_transaction_log_header, indexid);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file) ||
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* indexid=0 marks the log file as corrupted. we opened the file with
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen O_APPEND, and now we need to drop it for pwrite() to work (at least
dd4f30895ebbddd77e000472fbadcb3128ae2883Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Sirainen if (fcntl(file->fd, F_SETFL, flags & ~O_APPEND) < 0) {
57bf90f66f393c2807b2fc543655013f61d1d9e4Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mail_index_file_set_syscall_error(file->log->index,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenmail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const char *fmt, ...)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen "Corrupted transaction log file %s seq %u: %s "
48d8312488089dc1a8360991f0881d91095c21eaTimo Sirainen t_strdup_vprintf(fmt, va), file->sync_offset);
const char *path)
return file;
struct mail_transaction_log_file **p;
if (*p == file) {
struct mail_transaction_log_file **p;
*p = file;
#if !WORDS_BIGENDIAN
MAIL_INDEX_SYNC_HANDLER_HEAD) <= 0)
struct mail_transaction_log_file *
return NULL;
return file;
int ret;
if (ret > 0) {
if (ret < 0) {
int ret;
if (ret < 0) {
if (ret == 0) {
unsigned int lock_timeout_secs;
int ret;
if (ret > 0) {
if (ret < 0) {
const char *lock_reason)
unsigned int lock_time;
static ssize_t
void *dest;
yet (hdr.size=0), the buffer must be truncated later */
pos = 0;
if (ret > 0)
int ret;
ret = 0;
return ret;
bool ignore_estale)
struct mail_transaction_log_file *f;
int ret;
if (ret < 0) {
#if !WORDS_BIGENDIAN
return mail_transaction_log_file_fail_dupe(f);
bool ignore_estale)
return TRUE;
return FALSE;
unsigned int hdr_offset;
const char *path2;
if (reset)
FALSE) > 0 &&
if (reset) {
if (need_lock) {
if (ret < 0)
if (rename_existing) {
bool reset)
if (ret < 0) {
return ret;
const char **reason_r)
bool ignore_estale;
int ret;
if (ret > 0) {
if (ret == 0) {
i == MAIL_INDEX_ESTALE_RETRY_COUNT) {
const unsigned int offset_pos =
sizeof(tail_offset));
if (*cur_modseq != 0) {
const unsigned int modseq_ext_len =
modseq_ext_len) == 0) {
case MAIL_TRANSACTION_APPEND:
case MAIL_TRANSACTION_MODSEQ_UPDATE: {
static struct modseq_cache *
if (idx > 0) {
static struct modseq_cache *
return NULL;
best = i;
return NULL;
static struct modseq_cache *
return NULL;
best = i;
return NULL;
int ret;
if (ret <= 0) {
if (ret < 0)
int ret;
if (ret <= 0) {
if (ret < 0)
unsigned int trans_size)
int ret;
if (ret != 0)
case MAIL_TRANSACTION_BOUNDARY: {
const void *data;
int ret;
if (trans_size == 0) {
if (ret < 0)
void *data;
if (ret > 0) {
if (ret == 0) {
void *data;
if (ret > 0)
if (ret < 0) {
return TRUE;
return TRUE;
return FALSE;
int ret;
if (ret <= 0)
return ret;
return ret;
MADV_SEQUENTIAL) < 0)
int ret;
if (ret > 0)
FALSE);
} while (ret == 0);
int ret;
end_offset) == 0)
if (ret <= 0)
return ret;
*file)