mail-index-private.h revision da985034a708db2f61394b30d117050ae6829ee5
#ifndef __MAIL_INDEX_PRIVATE_H
#define __MAIL_INDEX_PRIVATE_H
/* Make sure F_RDLCK, F_WRLCK and F_UNLCK get defined */
#include <unistd.h>
#include <fcntl.h>
#include "mail-index.h"
#include "mail-index-view-private.h"
#include "mail-index-transaction-private.h"
struct mail_transaction_header;
struct mail_transaction_log_view;
struct mail_index_sync_map_ctx;
/* How many seconds to wait a lock for index file. */
#define MAIL_INDEX_LOCK_SECS 120
/* Index file is grown exponentially when we're adding less than this many
records. */
This happens with NFS when the file has been deleted (ie. index file was
rewritten by another computer than us). */
#define MAIL_INDEX_IS_IN_MEMORY(index) \
#define MAIL_INDEX_MAP_IS_IN_MEMORY(map) \
((struct mail_index_record *) \
void **sync_context, void *context);
#define MAIL_INDEX_HEADER_SIZE_ALIGN(size) \
struct mail_index_ext {
const char *name;
};
struct mail_index_ext_header {
/* unsigned char name[name_size] */
/* unsigned char data[hdr_size] (starting 64bit aligned) */
};
struct mail_index_keyword_header {
/* struct mail_index_keyword_header_rec[] */
/* char name[][] */
};
struct mail_index_keyword_header_rec {
};
enum mail_index_sync_handler_type {
MAIL_INDEX_SYNC_HANDLER_FILE = 0x01,
MAIL_INDEX_SYNC_HANDLER_HEAD = 0x02,
MAIL_INDEX_SYNC_HANDLER_VIEW = 0x04
};
struct mail_index_sync_handler {
};
struct mail_index_registered_ext {
const char *name;
struct mail_index_sync_handler sync_handler;
void *expunge_context;
unsigned int expunge_handler_call_always:1;
};
struct mail_index_map {
int refcount;
struct mail_index_header hdr;
const void *hdr_base;
void *records; /* struct mail_index_record[] */
unsigned int records_count;
void *mmap_base;
/* If write_to_disk=TRUE and write_atomic=FALSE, these sequences
specify the range that needs to be written. Header should always
be rewritten. */
unsigned int write_to_disk:1;
};
struct mail_index {
struct mail_cache *cache;
struct mail_transaction_log *log;
char *filepath;
int fd;
struct mail_index_map *map;
const struct mail_index_header *hdr;
unsigned int lock_id;
char *copy_lock_path;
/* These are typically same as map->hdr->log_file_*, but with
mmap_disable we may have synced more than index */
unsigned int last_grow_count;
/* Module-specific contexts. See mail_index_module_id. */
char *error;
unsigned int nodiskspace:1;
unsigned int index_lock_timeout:1;
unsigned int opened:1;
unsigned int log_locked:1;
unsigned int mmap_disable:1;
unsigned int mmap_no_write:1;
unsigned int readonly:1;
unsigned int fsck:1;
unsigned int sync_update:1;
unsigned int mapping:1;
};
void *context, bool call_always);
enum mail_index_sync_handler_type type);
const struct mail_index_header *hdr);
/* Returns 0 = ok, -1 = error. If update_index is TRUE, reopens the index
file if needed to get later version of it (not necessarily latest due to
races, unless transaction log is exclusively locked). */
unsigned int *lock_id_r);
/* Returns 0 = ok, -1 = error. */
unsigned int *lock_id_r);
/* Returns TRUE if given lock_id is valid. */
int lock_type, unsigned int timeout_secs);
/* Reopen index file if it has changed. */
/* Map index file to memory, replacing the previous mapping for index.
Returns 1 = ok, 0 = corrupted, -1 = error. If index needs fscking, it
returns 1 but sets index->fsck = TRUE. */
/* Read the latest available header. Normally this is pretty much the same as
calling mail_index_map(), but with mmap_disable the header can be generated
by reading just log files, so eg. log_file_*_offset values can be wrong.
Returns 1 = ok, 0 = EOF, -1 = error. */
struct mail_index_header *hdr_r);
/* Unreference given mapping and unmap it if it's dropped to zero. */
struct mail_index_map *
const char *name);
const struct mail_index_ext *
struct mail_index_map *map);
struct mail_index_map *map);
/* "%s failed with index file %s: %m" */
const char *function);
/* "%s failed with file %s: %m" */
const char *filepath,
const char *function);
#endif