mail-tree.c revision 67950e1843bd879bab73d8752ee54f60bbd21987
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "mmap-util.h"
#include "file-set-size.h"
#include "write-full.h"
#include "mail-index.h"
#include "mail-index-util.h"
#include "mail-tree.h"
#include <unistd.h>
#include <fcntl.h>
#define MAIL_TREE_MIN_SIZE \
(sizeof(MailTreeHeader) + \
INDEX_MIN_RECORDS_COUNT * sizeof(MailTreeNode))
{
return FALSE;
}
{
t_push();
t_pop();
/* make sure we don't get back here */
return FALSE;
}
{
/* make sure we're synced before munmap() */
}
tree->mmap_used_length = 0;
}
return TRUE;
}
{
unsigned int extra;
if (tree->mmap_full_length <
sizeof(MailTreeHeader) + sizeof(MailTreeNode)) {
return FALSE;
}
sizeof(MailTreeNode);
if (extra != 0) {
/* partial write or corrupted -
truncate the file to valid length */
}
"used_file_size larger than real file size "
return FALSE;
}
sizeof(MailTreeNode) != 0) {
return FALSE;
}
sizeof(MailTreeHeader));
return TRUE;
}
{
/* make sure file size hasn't changed */
i_panic("Tree file size was grown without "
"updating sync_id");
}
return TRUE;
}
}
{
const char *path;
int fd;
if (fd == -1) {
return NULL;
}
return tree;
}
{
}
tree->mmap_full_length = 0;
tree->mmap_used_length = 0;
}
}
{
return FALSE;
if (!mail_tree_rebuild(tree)) {
return FALSE;
}
return TRUE;
}
{
return FALSE;
do {
if (!mmap_update(tree))
break;
if (tree->mmap_full_length == 0) {
/* just created it */
if (!mail_tree_rebuild(tree))
break;
} else if (!mmap_verify(tree)) {
/* broken header */
if (!mail_tree_rebuild(tree))
break;
"IndexID mismatch for binary tree file %s",
if (!mail_tree_rebuild(tree))
break;
}
return TRUE;
} while (0);
return FALSE;
}
{
}
{
/* first node is always used, and is the RBNULL node */
}
}
return TRUE;
}
{
return FALSE;
if (!mail_tree_init(tree) ||
return FALSE;
}
return FALSE;
}
}
return TRUE;
}
{
*fsync_fd = -1;
return TRUE;
return TRUE;
}
{
unsigned int grow_count;
void *base;
INDEX_GROW_PERCENTAGE / 100;
if (grow_count < 16)
grow_count = 16;
(grow_count * sizeof(MailTreeNode));
if (base == MAP_FAILED)
return TRUE;
}
}
/* file size changed, let others know about it too by changing
sync_id in header. */
return FALSE;
return TRUE;
}
{
/* pretty much copy&pasted from mail_index_compress() */
return;
if (empty_space > truncate_threshold) {
/* keep the size record-aligned */
tree->mmap_full_length -=
sizeof(MailTreeNode);
}
}