mail-index.c revision 18398a5d21c88cbb34c601c6b6c1f9dea502e1ca
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "file-lock.h"
#include "mmap-util.h"
#include "read-full.h"
#include "write-full.h"
#include "mail-index-private.h"
#include "mail-transaction-log.h"
#include <stdio.h>
#include <stddef.h>
#include <time.h>
{
struct mail_index *index;
return index;
}
{
}
struct mail_index_map *map)
{
/* either a crash or we've already complained about it */
return -1;
}
map->records_count =
sizeof(struct mail_index_record);
"messages_count too large (%u > %u)",
map->records_count);
return 0;
}
return 1;
}
struct mail_index_map *map)
{
unsigned char compat_data[3];
int ret;
#ifndef WORDS_BIGENDIAN
#else
compat_data[0] = 0;
#endif
/* major version change - handle silently(?) */
return -1;
}
/* architecture change - handle silently(?) */
return -1;
}
return ret;
/* following some extra checks that only take a bit of CPU */
if (hdr->uid_validity == 0) {
return -1;
}
return 0;
return 0;
return 0;
return 1;
}
struct mail_index_map *map)
{
}
map->file_used_size = 0;
map->records_count = 0;
}
}
{
return;
}
struct mail_index_map *map)
{
}
struct mail_index_map *map)
{
void *data;
int ret;
return 0;
return -1;
}
}
/* @UNSAFE */
if (ret < 0) {
return 0;
return -1;
}
if (ret == 0) {
"Unexpected EOF while reading index file");
return -1;
}
return 1;
}
struct mail_index_map *map)
{
int i, ret;
for (i = 0; i < INDEX_ESTALE_RETRY_COUNT; i++) {
if (ret != 0)
return ret;
/* ESTALE - reopen index file */
if (ret <= 0) {
if (ret == 0) {
/* the file was lost */
}
return -1;
}
}
/* Too many ESTALE retries */
return -1;
}
{
struct mail_index_map *map;
void *base;
int ret;
/* see if re-mmaping is needed (file has grown) */
sizeof(struct mail_index_record);
/* update log file position in case it has changed */
return 1;
}
}
} else {
}
/* make sure if we fail we don't try to access anything outside the
buffer */
map->file_used_size = 0;
if (!index->mmap_disable) {
return -1;
}
} else {
return -1;
}
}
return 0;
}
/* header smaller than ours, make a copy so our newer headers
won't have garbage in them */
}
if (ret < 0) {
return 0;
}
if (ret == 0)
return 1;
}
{
const struct mail_index_header *hdr;
struct mail_index_map *mem_map;
if (MAIL_INDEX_MAP_IS_IN_MEMORY(map)) {
return map;
}
return mem_map;
}
{
#ifndef WORDS_BIGENDIAN
#endif
}
const struct mail_index_header *hdr)
{
} else {
return -1;
}
}
return 0;
}
{
const char *path;
int fd;
if (fd == -1)
return -1;
}
return fd;
}
{
const char *path;
int ret;
/* log file lock protects index creation */
return -1;
if (ret != 0) {
return ret;
}
/* create it fully in index.tmp first */
ret = -1;
ret = -1;
} else {
}
if (ret == 0) {
/* it's corrupted even while we just created it,
should never happen unless someone pokes the file directly */
"Newly created index file is corrupted: %s", path);
ret = -1;
}
if (ret < 0) {
"unlink()");
}
return -1;
}
/* make it visible to others */
return -1;
}
return 1;
}
{
int i;
for (i = 0; i < 3; i++) {
}
break;
/* May happen with some OSes with NFS. Try again, although
there's still a race condition with another computer
creating the index file again. However, we can't try forever
as ESTALE happens also if index directory has been deleted
from server.. */
}
/* have to create it */
return 0;
}
return 1;
}
{
unsigned int lock_id;
int ret;
*lock_id_r = 0;
if (ret <= 0)
return ret;
return -1;
if (ret == 0) {
/* it's corrupted - recreate it */
*lock_id_r = 0;
} else {
else
}
return ret;
}
static int
{
struct mail_index_header hdr;
unsigned int lock_id = 0;
int ret;
if (ret > 0)
else if (ret == 0) {
/* doesn't exist, or corrupted */
if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0)
return 0;
} else if (ret < 0)
return -1;
return -1;
if (lock_id != 0)
}
{
int i = 0, ret;
return 0;
do {
index->shared_lock_count = 0;
index->excl_lock_count = 0;
(flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) != 0;
(flags & MAIL_INDEX_OPEN_FLAG_MMAP_NO_WRITE) != 0;
if (ret <= 0)
break;
if (ret == 0) {
/* completely broken, reopen */
if (i++ < 3)
continue;
/* too many tries */
ret = -1;
}
}
break;
} while (1);
if (ret <= 0)
return ret;
}
{
}
}
}
{
}
{
else {
}
return -1;
}
{
}
{
struct mail_index_header hdr;
return 0;
/* make sure we can write the header */
PROT_READ | PROT_WRITE) < 0) {
return -1;
}
}
return -1;
return 0;
}
const char *function)
{
return -1;
}
}
const char *filepath,
const char *function)
{
return -1;
}
}
{
if (index->nodiskspace)
return MAIL_INDEX_ERROR_DISKSPACE;
return MAIL_INDEX_ERROR_INTERNAL;
return MAIL_INDEX_ERROR_NONE;
}
{
}
{
}
}
{
return FALSE; // FIXME
}