mail-tree.c revision 742111fa99a5b852c9645080573d5853be3907a7
/* 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(struct mail_tree_header) + \
INDEX_MIN_RECORDS_COUNT * sizeof(struct mail_tree_node))
{
return FALSE;
}
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;
}
{
struct mail_tree_header *hdr;
unsigned int extra;
if (tree->mmap_full_length <
sizeof(struct mail_tree_header) + sizeof(struct mail_tree_node)) {
return FALSE;
}
sizeof(struct mail_tree_node);
if (extra != 0) {
/* partial write or corrupted -
truncate the file to valid length */
}
"used_file_size larger than real file size "
return FALSE;
}
sizeof(struct mail_tree_node) != 0) {
return FALSE;
}
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;
}
{
return tree;
}
{
return FALSE;
if (!mail_tree_rebuild(tree)) {
return FALSE;
}
return TRUE;
}
{
if (!mmap_update(tree))
return FALSE;
if (tree->mmap_full_length == 0) {
/* just created it */
return FALSE;
}
if (!mmap_verify(tree)) {
/* broken header */
return FALSE;
}
"IndexID mismatch for binary tree file %s",
return FALSE;
}
return TRUE;
}
{
return FALSE;
if (!mail_tree_open_init(tree)) {
/* lock and check again, just to avoid rebuilding it twice
if two processes notice the error at the same time */
return FALSE;
}
if (!mail_tree_open_init(tree)) {
if (!mail_tree_rebuild(tree)) {
return FALSE;
}
}
}
return TRUE;
}
{
}
tree->mmap_full_length = 0;
tree->mmap_used_length = 0;
}
}
{
}
{
struct mail_tree_header hdr;
/* first node is always used, and is the RBNULL node */
sizeof(struct mail_tree_node);
return mmap_verify(tree);
}
return TRUE;
}
{
struct mail_index_record *rec;
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(struct mail_tree_node));
if (base == MAP_FAILED)
return mmap_verify(tree);
}
/* 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 */
sizeof(struct mail_tree_header)) %
sizeof(struct mail_tree_node);
}
}