mail-cache.c revision da5d50534cfca45d0aaaf0bdac17b287b4588809
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "buffer.h"
#include "byteorder.h"
#include "file-lock.h"
#include "file-set-size.h"
#include "mmap-util.h"
#include "write-full.h"
#include "mail-cache-private.h"
#include <stddef.h>
#include <unistd.h>
unsigned int mail_cache_field_sizes[32] = {
sizeof(enum mail_cache_record_flag),
sizeof(uoff_t),
16,
sizeof(struct mail_sent_date),
sizeof(time_t),
sizeof(uoff_t),
sizeof(uoff_t),
0, 0, 0, 0, 0,
/* variable sized */
(unsigned int)-1, (unsigned int)-1, (unsigned int)-1, (unsigned int)-1,
(unsigned int)-1, (unsigned int)-1, (unsigned int)-1, (unsigned int)-1,
(unsigned int)-1, (unsigned int)-1, (unsigned int)-1, (unsigned int)-1,
(unsigned int)-1, (unsigned int)-1, (unsigned int)-1, (unsigned int)-1,
(unsigned int)-1, (unsigned int)-1, (unsigned int)-1, (unsigned int)-1
};
};
{
unsigned char buf[4];
offset >>= 2;
}
{
return 0;
}
const char *function)
{
return;
}
"%s failed with index cache file %s: %m",
}
{
(void)mail_cache_reset(cache);
return;
t_push();
t_pop();
}
{
}
cache->mmap_length = 0;
}
}
{
int fd;
if (fd == -1) {
return -1;
}
return 0;
}
{
struct mail_cache_header *hdr;
/* check that the header is still ok */
return 0;
}
/* index id changed */
return 0;
}
/* we've updated used_file_size, do nothing */
return 1;
}
/* only check the header if we're locked */
return 1;
return 0;
}
return 0;
}
/* maybe a crash truncated the file - just fix it */
return -1;
}
}
return 1;
}
{
#if 0 // FIXME
/* if sequence has changed, the file has to be reopened.
note that if main index isn't locked, it may change again */
if (mail_cache_file_reopen(cache) < 0)
return -1;
}
#endif
!cache->mmap_refresh) {
/* already mapped */
if (size != 0)
return 1;
/* requesting the whole file - see if we need to
re-mmap */
return -1;
}
return 1;
}
/* in the middle of transaction - write the changes */
MS_SYNC) < 0) {
return -1;
}
}
}
/* map the whole file */
cache->mmap_length = 0;
return -1;
}
/* re-mmaped, check header */
return 0;
}
{
if (ret > 0)
return 0;
if (ret < 0)
return -1;
if (mmap_verify_header(cache) <= 0)
return -1;
#if 0 // FIXME
/* see if cache file was rebuilt - do it only once to avoid
infinite looping */
break;
if (mail_cache_file_reopen(cache) < 0)
return -1;
#endif
}
return 0;
}
{
int ret;
return 0;
return -1;
}
return -1;
}
return 0;
return -1;
/* verify that this really is the cache for wanted index */
return ret;
}
return 1;
}
struct mail_cache_header *hdr)
{
if (ret != 0)
return ret < 0 ? -1 : 0;
/* maybe a rebuild.. */
if (fd == -1) {
return -1;
}
/* see if someone else just created the cache file */
if (ret != 0) {
return ret < 0 ? -1 : 0;
}
/* rebuild then */
return -1;
}
return -1;
}
// FIXME: clear cache_offsets in index file
}
return -1;
}
if (mail_cache_mmap_update(cache, 0,
sizeof(struct mail_cache_header)) < 0)
return -1;
return 0;
}
{
struct mail_cache_header hdr;
struct mail_cache *cache;
/* we'll do anon-mmaping only if initially requested. if we fail
because of out of disk space, we'll just let the main index code
know it and fail. */
return NULL;
}
return cache;
}
{
}
{
}
{
struct mail_cache_header hdr;
int fd;
// FIXME: update cache_offsets in index
if (fd == -1) {
return -1;
}
return -1;
}
return -1;
}
return -1;
}
if (mail_cache_mmap_update(cache, 0,
sizeof(struct mail_cache_header)) < 0)
return -1;
return 0;
}
{
int ret;
return 1;
if (nonblock) {
if (ret < 0)
} else {
if (ret <= 0)
}
if (ret > 0) {
if (mail_cache_mmap_update(cache, 0, 0) < 0) {
(void)mail_cache_unlock(cache);
return -1;
}
#if 0 // FIXME
/* we have the cache file locked and sync_id still
doesn't match. it means we crashed between updating
cache file and updating sync_id in index header.
just update the sync_ids so they match. */
i_warning("Updating broken sync_id in cache file %s",
}
#endif
}
return ret;
}
{
return 0;
return -1;
}
return 0;
}
{
}
struct mail_cache_view *
{
struct mail_cache_view *view;
return view;
}
{
}
enum mail_cache_field fields)
{
// FIXME
}