mail-cache.c revision d565eaa943f29a49b97230ced57eec40ee65b4f9
/* 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;
if (used_file_size < sizeof(struct mail_cache_header)) {
return 0;
}
if ((used_file_size % sizeof(uint32_t)) != 0) {
return 0;
}
return 0;
}
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;
}
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;
/* failed for some reason - doesn't really matter,
just disable caching. */
}
return cache;
}
{
}
{
}
{
struct mail_cache_header hdr;
int fd;
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;
}
return 0;
}
}
return ret;
}
{
return 0;
return -1;
}
return 0;
}
{
}
{
return TRUE;
}
}
return FALSE;
}
struct mail_cache_view *
{
struct mail_cache_view *view;
return view;
}
{
}
enum mail_cache_field fields)
{
// FIXME
}