mail-cache-private.h revision 9a583c7a827f7a4d89ee43774f2d51ea6a214543
#ifndef __MAIL_CACHE_PRIVATE_H
#define __MAIL_CACHE_PRIVATE_H
#include "file-dotlock.h"
#include "mail-index-private.h"
#include "mail-cache.h"
#define MAIL_CACHE_VERSION 1
/* Drop fields that haven't been accessed for n seconds */
/* Never compress the file if it's smaller than this */
/* Don't bother remembering holes smaller than this */
#define MAIL_CACHE_MIN_HOLE_SIZE 1024
/* Compress the file when deleted space reaches n% of total size */
#define MAIL_CACHE_COMPRESS_PERCENTAGE 20
/* Compress the file when n% of rows contain continued rows.
200% means that there's 2 continued rows per record. */
#define MAIL_CACHE_COMPRESS_CONTINUED_PERCENTAGE 200
/* Initial size for the file */
/* When more space is needed, grow the file n% larger than the previous size */
#define MAIL_CACHE_GROW_PERCENTAGE 10
/* When allocating space for transactions, don't use blocks larger than this. */
#define MAIL_CACHE_LOCK_TIMEOUT 120
#define MAIL_CACHE_LOCK_CHANGE_TIMEOUT 60
((const struct mail_cache_record *) \
#define MAIL_CACHE_IS_UNUSABLE(cache) \
struct mail_cache_header {
/* version is increased only when you can't have backwards
compatibility. */
};
struct mail_cache_header_fields {
#if 0
/* last time the field was accessed. not updated more often than
once a day. */
/* (uint32_t)-1 for variable sized fields */
/* enum mail_cache_field_type */
/* enum mail_cache_decision_type */
/* NUL-separated list of field names */
char name[fields_count][];
#endif
};
#define MAIL_CACHE_FIELD_LAST_USED() \
(sizeof(uint32_t) * 3)
#define MAIL_CACHE_FIELD_SIZE(count) \
#define MAIL_CACHE_FIELD_TYPE(count) \
#define MAIL_CACHE_FIELD_DECISION(count) \
#define MAIL_CACHE_FIELD_NAMES(count) \
struct mail_cache_record {
/* array of { uint32_t field; [ uint32_t size; ] { .. } } */
};
struct mail_cache_hole_header {
/* make sure we notice if we're treating hole as mail_cache_record.
magic is a large number so if it's treated as size field, it'll
point outside the file */
#define MAIL_CACHE_HOLE_HEADER_MAGIC 0xffeedeff
};
struct mail_cache_field_private {
struct mail_cache_field field;
/* Unused fields aren't written to cache file */
unsigned int used:1;
unsigned int decision_dirty:1;
};
struct mail_cache {
struct mail_index *index;
char *filepath;
int fd;
void *mmap_base;
const void *data;
struct file_cache *file_cache;
/* mail_cache_map() increases this always. */
unsigned int remap_counter;
struct dotlock_settings dotlock_settings;
const struct mail_cache_header *hdr;
struct mail_cache_header hdr_copy;
struct mail_cache_field_private *fields;
unsigned int fields_count;
/* 0 is no need for compression, otherwise the file sequence number
which we want compressed. */
unsigned int *file_field_map;
unsigned int file_fields_count;
unsigned int opened:1;
unsigned int locked:1;
unsigned int hdr_modified:1;
unsigned int field_header_write_pending:1;
};
struct mail_cache_view {
struct mail_cache *cache;
struct mail_cache_transaction_ctx *transaction;
/* temporary array, just to avoid mallocs. */
/* if cached_exists_buf[field] == cached_exists_value, it's cached.
this allows us to avoid constantly clearing the whole buffer.
it needs to be cleared only when cached_exists_value is wrapped. */
};
struct mail_cache_iterate_field {
unsigned int field_idx;
const void *data;
unsigned int size;
};
struct mail_cache_lookup_iterate_ctx {
struct mail_cache_view *view;
unsigned int remap_counter;
const struct mail_cache_record *rec;
unsigned int stop:1;
unsigned int failed:1;
unsigned int appends_checked:1;
};
/* Explicitly lock the cache file. Returns -1 if error, 1 if ok, 0 if we
couldn't lock */
/* Returns -1 if cache is / just got corrupted, 0 if ok. */
const struct mail_cache_record **rec_r);
/* Returns TRUE if offset is already in given array. Otherwise return FALSE
and add the offset to the array. */
/* Iterate through a message's cached fields. */
struct mail_cache_lookup_iterate_ctx *ctx_r);
/* Returns 1 if field was returned, 0 if end of fields, or -1 if error */
struct mail_cache_iterate_field *field_r);
/* Update new_offset's prev_offset field to old_offset. */
/* Mark record in given offset to be deleted. */
/* Notify the decision handling code that field was looked up for seq */
unsigned int field);
void **sync_context, void *context);
void **context);
const char *function);
#endif