mail-modifylog.c revision 10ffe25023df7de97803cd94cc3ad97ff1c986a7
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "file-lock.h"
#include "file-set-size.h"
#include "mmap-util.h"
#include "write-full.h"
#include "mail-index.h"
#include "mail-index-util.h"
#include "mail-modifylog.h"
#include <stdlib.h>
#include <fcntl.h>
/* Maximum size for modify log (isn't exact) */
#define MAX_MODIFYLOG_SIZE 10240
struct _MailModifyLog {
int fd;
char *filepath;
void *mmap_base;
unsigned int synced_id;
unsigned int anon_mmap:1;
unsigned int modified:1;
unsigned int second_log:1;
};
static const unsigned int no_expunges[] = { 0 };
const char *function)
{
return FALSE;
}
{
t_push();
t_pop();
/* make sure we don't get back here */
return FALSE;
}
/* returns 1 = yes, 0 = no, -1 = error */
{
int ret;
return 0;
/* try grabbing exclusive lock */
if (ret <= 0) {
if (ret < 0)
}
/* revert back to shared lock */
if (ret < 0) {
return -1;
}
if (ret == 0) {
/* shouldn't happen */
return -1;
}
return 0;
}
{
unsigned int extra;
return TRUE;
}
/* make sure we're synced before munmap() */
}
log->mmap_used_length = 0;
}
return FALSE;
}
sizeof(ModifyLogRecord);
if (extra != 0) {
/* partial write or corrupted -
truncate the file to valid length */
}
"used_file_size larger than real file size "
return FALSE;
}
sizeof(ModifyLogRecord) != 0) {
return FALSE;
}
return TRUE;
}
{
return log;
}
{
}
log->mmap_full_length = 0;
log->mmap_used_length = 0;
}
}
{
}
const char *path)
{
return FALSE;
}
"file_set_size()");
return FALSE;
}
return TRUE;
}
{
return TRUE;
}
{
return FALSE;
if (fd == -1) {
}
/* if we can't get the lock, we fail. it shouldn't happen. */
if (ret < 0) {
"file_wait_lock()");
} else if (ret == 0) {
"created modify log %s", path);
}
/* drop back to read lock */
ret = -1;
}
modifylog_mark_full(log))) {
return TRUE;
}
}
return FALSE;
}
{
const char *path;
if (index->nodiskspace) {
} else {
/* fatal failure */
return FALSE;
}
}
return TRUE;
}
/* Returns 1 = ok, 0 = full, -1 = error */
{
int fd;
if (fd == -1) {
"open()");
}
return -1;
}
return -1;
}
if (ret < 0)
ret = -1;
}
"file %s", path);
ret = -1;
/* we have to rebuild it, make sure it's deleted. */
}
/* full */
ret = 0;
}
if (ret > 0) {
} else {
}
return ret > 0;
}
{
int i, ret;
for (i = 0; i < 2; i++) {
/* first try <index>.log */
if (ret == 1)
return TRUE;
if (ret == 0) {
/* then <index>.log.2 */
return TRUE;
}
return TRUE;
return TRUE;
/* maybe the file was just switched, check the logs again */
}
"the modify log for index %s",
}
return FALSE;
}
{
if (!mail_modifylog_find_or_create(log) ||
/* fatal failure */
return FALSE;
}
return TRUE;
}
{
}
{
return TRUE;
}
return TRUE;
}
{
void *base;
if (base == MAP_FAILED) {
return FALSE;
}
return TRUE;
}
}
return FALSE;
return TRUE;
}
int external_change)
{
if (!external_change) {
switch (mail_modifylog_have_other_users(log)) {
case 0:
/* we're the only one having this log open,
no need for modify log. */
return TRUE;
case -1:
return FALSE;
}
}
return FALSE;
if (!mail_modifylog_grow(log))
return FALSE;
}
}
return TRUE;
}
unsigned int uid, int external_change)
{
/* expunges must not be added when log isn't synced */
}
unsigned int uid, int external_change)
{
}
unsigned int *count)
{
*count = 0;
return NULL;
return rec;
}
{
return mail_modifylog_open_or_create(index);
}
{
const char *path;
return TRUE;
/* old log file is still open */
return TRUE;
}
return FALSE;
return TRUE;
}
{
return FALSE;
/* log file is full, switch to next one */
return mail_modifylog_switch_file(log);
}
/* we are already synced */
return TRUE;
}
/* if the other file isn't locked, switch to it */
return mail_modifylog_try_switch_file(log);
}
return TRUE;
}
{
}
const unsigned int *
unsigned int first_seq,
unsigned int last_seq,
unsigned int *expunges_before)
{
*expunges_before = 0;
return NULL;
/* find the first expunged message that affects our range */
break;
rec++;
}
/* none found */
return no_expunges;
}
/* allocate memory for the returned array. the file size - synced
position should be quite near the amount of memory we need, unless
there's lots of FLAGS_CHANGED records which is why there's the
second check to make sure it's not unneededly large. */
sizeof(ModifyLogRecord);
/* last_pos_seq is updated all the time to contain the last_seq
comparable to current record's seq. number */
before = 0;
continue;
/* before our range */
before++;
last_pos_seq--;
/* within our range */
last_pos_seq--;
if (max_records-- == 0) {
/* log contains more data than it should
have - must be corrupted. */
"Contains more data than expected");
return NULL;
}
}
}
*arr = 0;
/* sort the UID array, not including the terminating 0 */
return expunges;
}
const unsigned int *
unsigned int first_uid,
unsigned int last_uid,
unsigned int *expunges_before)
{
/* pretty much copy&pasted from sequence code above ..
kind of annoying */
*expunges_before = 0;
return NULL;
/* find the first expunged message that affects our range */
break;
rec++;
}
/* none found */
return no_expunges;
}
/* allocate memory for the returned array. the file size - synced
position should be quite near the amount of memory we need, unless
there's lots of FLAGS_CHANGED records which is why there's the
second check to make sure it's not unneededly large. */
sizeof(ModifyLogRecord);
before = 0;
continue;
/* within our range */
if (max_records-- == 0) {
/* log contains more data than it should
have - must be corrupted. */
"Contains more data than expected");
return NULL;
}
/* before our range */
before++;
}
}
*arr = 0;
/* sort the UID array, not including the terminating 0 */
return expunges;
}
{
unsigned int expunges;
return 0;
/* find the first expunged message that affects our range */
expunges = 0;
expunges++;
rec++;
}
return expunges;
}