mail-index-data.c revision 473fe584efcfc0471401ec9cb914c5b089a3a7c9
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "mmap-util.h"
#include "write-full.h"
#include "mail-index.h"
#include "mail-index-data.h"
#include "mail-index-util.h"
#include <stdio.h>
#include <fcntl.h>
/* Never compress the file if it's smaller than this (50kB) */
/* Compress the file when deleted space reaches 20% of total size */
#define COMPRESS_PERCENTAGE 20
struct _MailIndexData {
int fd;
char *filepath;
void *mmap_base;
unsigned int dirty_mmap:1;
};
{
return TRUE;
return FALSE;
return FALSE;
} else {
return TRUE;
}
}
{
const char *path;
int fd;
if (fd == -1) {
/* doesn't exist, rebuild the index */
}
return FALSE;
}
return FALSE;
}
/* verify that this really is the data file for wanted index */
path);
return FALSE;
}
return TRUE;
}
const char *temppath)
{
const char *realpath;
/* write header */
"%s: %m", temppath);
return NULL;
}
/* move temp file into .data file, deleting old one
if it already exists */
return NULL;
}
return realpath;
}
{
int fd;
if (fd == -1)
return FALSE;
return FALSE;
}
return TRUE;
}
{
}
}
{
return FALSE;
}
hdr.deleted_space = 0;
return FALSE;
}
return FALSE;
}
return TRUE;
}
{
}
{
if (pos == -1) {
return 0;
}
if (pos < (int)sizeof(MailIndexDataHeader)) {
return 0;
}
return 0;
}
}
unsigned int data_size)
{
/* make sure the whole file is mmaped */
if (!mmap_update(data, 0, 0))
return FALSE;
/* see if we've reached the max. deleted space in file */
}
return TRUE;
}
{
return FALSE;
}
}
return FALSE;
}
return TRUE;
}
{
if (index_rec->data_position == 0) {
/* data not yet written to record */
return NULL;
}
return NULL;
(data->mmap_length -
"Given data size larger than file size "
(unsigned long) index_rec->data_position,
(unsigned long) data->mmap_length);
return NULL;
}
do {
/* pos + DATA_RECORD_SIZE() may actually overflow, but it
points to beginning of file then. Don't bother checking
this as it won't crash and is quite likely noticed later. */
"Field size points outside file "
(unsigned long) pos,
(unsigned long) max_pos);
break;
}
/* match */
return rec;
/* jump to next record */
} else {
/* the fields are sorted by field type, so it's not
possible the wanted field could come after this. */
break;
}
return NULL;
}
{
return NULL;
/* get position to next record */
/* make sure it's within range */
return NULL;
"Field size points outside file "
(unsigned long) pos,
(unsigned long) max_pos);
return NULL;
}
return rec;
}
{
int i;
return FALSE;
}
/* make sure the data actually contains \0 */
/* yes, everything ok */
return TRUE;
}
}
"Missing \\0 with field %u (%lu)",
return FALSE;
}
{
return NULL;
}