mail-cache.c revision da985034a708db2f61394b30d117050ae6829ee5
/* Copyright (C) 2003-2004 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "buffer.h"
#include "hash.h"
#include "nfs-workarounds.h"
#include "file-cache.h"
#include "mmap-util.h"
#include "write-full.h"
#include "mail-cache-private.h"
#include <unistd.h>
const char *function)
{
return;
}
"%s failed with index cache file %s: %m",
}
{
/* mark the cache as unusable */
t_push();
t_pop();
}
{
}
cache->mmap_length = 0;
}
}
{
struct mail_index_view *view;
const struct mail_index_ext *ext;
if (MAIL_CACHE_IS_UNUSABLE(cache) &&
(cache->need_compress_file_seq != 0 ||
/* reopening does no good */
return 0;
}
else
return -1;
}
if (mail_cache_map(cache, 0, 0) < 0)
return -1;
if (mail_cache_header_fields_read(cache) < 0)
return -1;
/* still different - maybe a race condition or maybe the
file_seq really is corrupted. either way, this shouldn't
happen often so we'll just mark cache to be compressed
later which fixes this. */
return 0;
}
return 1;
}
{
/* check that the header is still ok */
return FALSE;
}
/* version changed - upgrade silently */
return FALSE;
}
if (hdr->compat_sizeof_uoff_t == 0 &&
hdr->compat_sizeof_time_t == 0) {
/* FIXME: keep backwards compatibility for a while.
set hdr_modified=TRUE so header gets fixed the next
time cache is locked. */
} else {
/* architecture change - handle silently(?) */
return -1;
}
}
/* index id changed */
return FALSE;
}
/* only check the header if we're locked */
return TRUE;
return FALSE;
}
return FALSE;
}
return FALSE;
}
return TRUE;
}
{
if (size == 0)
size = sizeof(struct mail_cache_header);
if (ret < 0) {
/* In case of ESTALE we'll simply fail without error
messages. The caller will then just have to
fallback to generating the value itself.
We can't simply reopen the cache flie, because
using it requires also having updated file
offsets. */
return -1;
}
&cache->mmap_length);
return -1;
}
return 0;
}
/* already mapped */
return 0;
}
} else {
/* unusable, waiting for compression or
index is in memory */
return -1;
}
}
/* map the whole file */
cache->mmap_length = 0;
return -1;
}
if (!mail_cache_verify_header(cache)) {
return -1;
}
return 0;
}
{
return 0;
return 0;
}
return -1;
}
return -1;
return mail_cache_header_fields_read(cache);
}
{
struct mail_cache *cache;
if (!MAIL_INDEX_IS_IN_MEMORY(index)) {
}
}
return cache;
}
{
struct mail_cache *cache;
if (mail_cache_open_and_verify(cache) < 0) {
/* failed for some reason - doesn't really matter,
it's disabled for now. */
}
return cache;
}
{
struct mail_cache *cache;
return cache;
}
{
}
}
{
}
} else
}
{
struct mail_index_view *view;
const struct mail_index_ext *ext;
int i, ret;
if (MAIL_CACHE_IS_UNUSABLE(cache) ||
return 0;
/* cache not used */
return 0;
}
/* we want the latest cache file */
return ret;
}
}
for (i = 0; i < 3; i++) {
if (ret <= 0)
break;
/* got it */
break;
}
/* okay, so it was just compressed. try again. */
(void)mail_cache_unlock(cache);
break;
ret = 0;
}
if (ret > 0) {
/* make sure our header is up to date */
sizeof(struct mail_cache_header));
}
if (mail_cache_map(cache, 0, 0) == 0)
else {
(void)mail_cache_unlock(cache);
ret = -1;
}
}
return ret;
}
{
unsigned int cont_percentage;
if (cont_percentage >= COMPRESS_CONTINUED_PERCENTAGE &&
/* too many continued rows, compress */
}
/* see if we've reached the max. deleted space in file */
}
{
int ret = 0;
if (MAIL_CACHE_IS_UNUSABLE(cache)) {
/* we found it to be broken during the lock. just clean up. */
return -1;
}
if (cache->hdr_modified) {
/* FIXME: for backwards compatibility - keep them for a while */
ret = -1;
}
return ret;
}
{
return -1;
}
&cache->mmap_length);
}
return 0;
}
struct mail_cache_view *
{
struct mail_cache_view *view;
return view;
}
{
}