mail-transaction-log-file.c revision 6f90ce01176bd920609d9d12e6419b9ba27c1359
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina/* Copyright (c) 2003-2009 Dovecot authors, see the included COPYING file */
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina#define MEMORY_LOG_NAME "(in-memory transaction log file)"
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březinamail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina const char *fmt, ...)
b0abb3bfdfd95951a23c9fc223c735805ffd2969Pavel Březina if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina /* indexid=0 marks the log file as corrupted */
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina mail_index_file_set_syscall_error(file->log->index,
76db25eab9010a33657f35e5afc8477c996df7a3Pavel Březina "Corrupted transaction log file %s seq %u: %s "
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina t_strdup_vprintf(fmt, va), file->sync_offset);
c9aab1c04c399ca2d1abef74f6df22ced34983dcPavel Březinamail_transaction_log_file_alloc(struct mail_transaction_log *log,
41ef946f3f74a46b9e26118116e4811e259b30efPavel Březina file = i_new(struct mail_transaction_log_file, 1);
b0abb3bfdfd95951a23c9fc223c735805ffd2969Pavel Březinavoid mail_transaction_log_file_free(struct mail_transaction_log_file **_file)
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina struct mail_transaction_log_file *file = *_file;
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina for (p = &file->log->files; *p != NULL; p = &(*p)->next) {
b0abb3bfdfd95951a23c9fc223c735805ffd2969Pavel Březina if (munmap(file->mmap_base, file->mmap_size) < 0) {
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina mail_index_file_set_syscall_error(file->log->index,
d38ffc9c92daeb62de7d28c409bdaeff98f82775Pavel Březina mail_index_file_set_syscall_error(file->log->index,
710472d946f6c337a095699dfd79134fa8b9eab9Pavel Březinamail_transaction_log_file_skip_to_head(struct mail_transaction_log_file *file)
3b09b74bf65867d882af87ec60e2a517b15264a6Jakub Hrozek const struct mail_index_modseq_header *modseq_hdr;
3d55c65fbe50074f6a63dcb8ae866c038a9e6b2bStephen Gallagher if (map == NULL || file->hdr.file_seq != map->hdr.log_file_seq ||
3b09b74bf65867d882af87ec60e2a517b15264a6Jakub Hrozek /* we can get a valid log offset from index file. initialize
3b09b74bf65867d882af87ec60e2a517b15264a6Jakub Hrozek sync_offset from it so we don't have to read the whole log
3b09b74bf65867d882af87ec60e2a517b15264a6Jakub Hrozek file from beginning. */
3b09b74bf65867d882af87ec60e2a517b15264a6Jakub Hrozek modseq_hdr = mail_index_map_get_modseq_header(map);
2827b0d03f7b6bafa504d22a5d7ca39cbda048b3Pavel Březina "%s: log_file_head_offset too small",
struct mail_transaction_log_file **p;
*p = file;
#ifndef 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) {
int ret;
if (ret > 0) {
if (ret < 0) {
static ssize_t
int ret;
pos = 0;
if (ret > 0)
bool ignore_estale)
struct mail_transaction_log_file *f;
int ret;
if (ret < 0) {
#ifndef WORDS_BIGENDIAN
bool ignore_estale)
return TRUE;
return FALSE;
const char *path2;
bool rename_existing;
if (reset)
FALSE) > 0 &&
if (reset) {
if (ret < 0)
if (rename_existing) {
path2);
bool reset)
int fd;
bool check_existing)
bool ignore_estale;
int ret;
else if (check_existing &&
if (ret > 0) {
if (ret == 0) {
i == MAIL_INDEX_ESTALE_RETRY_COUNT) {
const unsigned int offset_pos =
sizeof(tail_offset));
const void *data,
if (cur_modseq != 0) {
const unsigned int modseq_ext_len =
modseq_ext_len) == 0) {
return TRUE;
return FALSE;
case MAIL_TRANSACTION_APPEND:
return TRUE;
return FALSE;
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)
cur_modseq++;
int ret;
if (ret <= 0) {
if (ret < 0)
cur_modseq)) {
unsigned int trans_size)
int ret;
sizeof(*hdr));
if (ret != 0)
const void *data;
if (trans_size == 0) {
trans_size = 0;
if (trans_size != 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)
*file)