mail-index-private.h revision 3675a7e9bd3775ba13fe8bc93915902513a0f1a4
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* How large index files to mmap() instead of reading to memory. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* How many times to retry opening index files if read/fstat returns ESTALE.
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen This happens with NFS when the file has been deleted (ie. index file was
6ec925f52d04ec8700e47cb005bd7ddc65ac5614Timo Sirainen rewritten by another computer than us). */
c60178b2610a9b193ff72aa18448398ef72529a1Timo Sirainen#define MAIL_INDEX_ESTALE_RETRY_COUNT NFS_ESTALE_RETRY_COUNT
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen PTR_OFFSET((map)->rec_map->records, (idx) * (map)->hdr.record_size))
617e13833c798435e2be425b99c27ecaad1b8393Timo Sirainentypedef int mail_index_expunge_handler_t(struct mail_index_sync_map_ctx *ctx,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainentypedef int mail_index_sync_handler_t(struct mail_index_sync_map_ctx *ctx,
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainentypedef void mail_index_sync_lost_handler_t(struct mail_index *index);
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen uint32_t ext_offset; /* points to beginning of mail_index_ext_header */
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen uint32_t hdr_offset; /* points to mail_index_ext_header.data[] */
5d4c793b4e3dbc07f08daa4465594b1857f80725Timo Sirainen uint32_t hdr_size; /* size of mail_index_ext_header.data[] */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* unsigned char name[name_size] */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* unsigned char data[hdr_size] (starting 64bit aligned) */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* struct mail_index_keyword_header_rec[] */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* char name[][] */
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen uint32_t unused; /* for backwards compatibility */
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen uint32_t name_offset; /* relative to beginning of name[] */
78fa3c578c14ee8a612f86cf73b6181c7f16463fTimo Sirainen uint32_t hdr_size; /* size of mail_index_ext_header.data[] */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen mail_index_expunge_handler_t *expunge_handler;
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen unsigned int lock_id;
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen void *records; /* struct mail_index_record[] */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* If this mapping is written to disk and write_atomic=FALSE,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen write_seq_* specify the message sequence range that needs to be
efc5c69c572e83db7bf7eab5d4698c0ab0d3d886Timo Sirainen ARRAY_DEFINE(extensions, struct mail_index_ext);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen ARRAY_DEFINE(ext_id_map, uint32_t); /* index -> file */
29f32cdcf44cda9688576bfdc7450a8a15e90e86Timo Sirainen ARRAY_DEFINE(keyword_idx_map, unsigned int); /* file -> index */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int write_atomic:1; /* write to a new file and rename() */
b955a1c1b6d466977d971c029a9305bee492f73cTimo Sirainen unsigned int id;
601b455f4d5e780044b9e4fac5f687c1b07ae145Timo Sirainen ARRAY_DEFINE(extensions, struct mail_index_registered_ext);
e9ac518aaf49a06d976bf7f24ab14a3e2d6d86abTimo Sirainen ARRAY_DEFINE(sync_lost_handlers, mail_index_sync_lost_handler_t *);
e1f866daa1bd1a5cd7516f3b19c6f197bcf6cc8aTimo Sirainen /* last_read_log_file_* contains the seq/offsets we last read from
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen the main index file's headers. these are used to figure out when
614529ee060755c0b282102b70daf56bcd64222dTimo Sirainen the main index file should be updated, and if we can update it
9ebd0c59de5f8240c0dbc58773fe5679391199dbTimo Sirainen by writing on top of it or if we need to recreate it. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* transaction log head seq/offset when we last fscked */
e1f866daa1bd1a5cd7516f3b19c6f197bcf6cc8aTimo Sirainen int lock_type, shared_lock_count, excl_lock_count;
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen struct hash_table *keywords_hash; /* name -> idx */
9e291f6a7ca67b86d1d65a730ffb71fb9a334fb0Timo Sirainen /* Module-specific contexts. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_index_module_context *);
f2880c3c3de56ec757ffc393363bb863efd7bcbeTimo Sirainenextern struct mail_index_module_register mail_index_module_register;
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Add/replace sync handler for specified extra record. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid mail_index_register_expunge_handler(struct mail_index *index,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid mail_index_unregister_expunge_handler(struct mail_index *index,
5d46f4d076fc13ae2779c365cf4bd9bda3a5bc69Timo Sirainenvoid mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id,
28482afc8139462ff9bcc6cedc4936129e8763efTimo Sirainenvoid mail_index_unregister_sync_handler(struct mail_index *index,
5d46f4d076fc13ae2779c365cf4bd9bda3a5bc69Timo Sirainenvoid mail_index_register_sync_lost_handler(struct mail_index *index,
d482079eb385cd071bbc9637cacee225e4aff968Timo Sirainenvoid mail_index_unregister_sync_lost_handler(struct mail_index *index,
3a0f9aa9504497e4e47f32df54fbf47fdc7423b6Timo Sirainenint mail_index_create_tmp_file(struct mail_index *index, const char **path_r);
1ffb2afe6d7e8860a2231a4827078cf2ef9c22cdTimo Sirainenint mail_index_try_open_only(struct mail_index *index);
d4845c4245638fd6f02dc0cb92c3465fae763cbbTimo Sirainenvoid mail_index_close_file(struct mail_index *index);
d4845c4245638fd6f02dc0cb92c3465fae763cbbTimo Sirainenint mail_index_reopen_if_changed(struct mail_index *index);
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainen/* Update/rewrite the main index file from index->map */
0161376aac025266d8654577c4b9ce371ffc87eaTimo Sirainenvoid mail_index_write(struct mail_index *index, bool want_rotate);
788f275469ad9ed530e440d6690d0e4381a323b2Timo Sirainenvoid mail_index_flush_read_cache(struct mail_index *index, const char *path,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Returns 0 = ok, -1 = error. */
a8aec60b5359e5ea7fc7a9464217ae3626df8785Timo Sirainenint mail_index_lock_shared(struct mail_index *index, unsigned int *lock_id_r);
28482afc8139462ff9bcc6cedc4936129e8763efTimo Sirainen/* Returns 1 = ok, 0 = already locked, -1 = error. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenint mail_index_try_lock_exclusive(struct mail_index *index,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int *lock_id_r);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid mail_index_unlock(struct mail_index *index, unsigned int *lock_id);
43d7e7ce608f5451e4907b5f5c48c00beb265802Timo Sirainen/* Returns TRUE if given lock_id is valid. */
0547a828ee9647fc5fd2e359b145774740a697feTimo Sirainenbool mail_index_is_locked(struct mail_index *index, unsigned int lock_id);
43d7e7ce608f5451e4907b5f5c48c00beb265802Timo Sirainenint mail_index_lock_fd(struct mail_index *index, const char *path, int fd,
5d46f4d076fc13ae2779c365cf4bd9bda3a5bc69Timo Sirainen/* Allocate a new empty map. */
5d46f4d076fc13ae2779c365cf4bd9bda3a5bc69Timo Sirainenstruct mail_index_map *mail_index_map_alloc(struct mail_index *index);
5d46f4d076fc13ae2779c365cf4bd9bda3a5bc69Timo Sirainen/* Replace index->map with the latest index changes. This may reopen the index
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen file and/or it may read the latest changes from transaction log. The log is
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen read up to EOF, but non-synced expunges are skipped.
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen If we mmap()ed the index file, the map is returned locked.
55bc6a7a0940ec48a68558ef70838991c5d301d2Timo Sirainen Returns 1 = ok, 0 = corrupted, -1 = error. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Unreference given mapping and unmap it if it's dropped to zero. */
55bc6a7a0940ec48a68558ef70838991c5d301d2Timo Sirainenvoid mail_index_unmap(struct mail_index_map **map);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Clone a map. The returned map is always in memory. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenstruct mail_index_map *mail_index_map_clone(const struct mail_index_map *map);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid mail_index_record_map_move_to_private(struct mail_index_map *map);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Move a mmaped map to memory. */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainenvoid mail_index_map_move_to_memory(struct mail_index_map *map);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenbool mail_index_map_lookup_ext(struct mail_index_map *map, const char *name,
28482afc8139462ff9bcc6cedc4936129e8763efTimo Sirainenmail_index_map_register_ext(struct mail_index_map *map,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenbool mail_index_map_get_ext_idx(struct mail_index_map *map,
cdc8485491045d82bb98405d4b995f277d12838eTimo Sirainenmail_index_view_get_ext(struct mail_index_view *view, uint32_t ext_id);
b2ed2b25c4c457ec1c99ebe5e9bd66a2e2f89cfdTimo Sirainenint mail_index_map_check_header(struct mail_index_map *map);
b2ed2b25c4c457ec1c99ebe5e9bd66a2e2f89cfdTimo Sirainenint mail_index_map_parse_keywords(struct mail_index_map *map);
e5097d2c8efecdd274272b222cf2b30a8ae4ca2aTimo Sirainenint mail_index_map_ext_get_next(struct mail_index_map *map,
e5097d2c8efecdd274272b222cf2b30a8ae4ca2aTimo Sirainen unsigned int *offset,
e5097d2c8efecdd274272b222cf2b30a8ae4ca2aTimo Sirainen const struct mail_index_ext_header **ext_hdr_r,
e5097d2c8efecdd274272b222cf2b30a8ae4ca2aTimo Sirainen const char **name_r);
28482afc8139462ff9bcc6cedc4936129e8763efTimo Sirainenint mail_index_map_ext_hdr_check(const struct mail_index_header *hdr,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenunsigned int mail_index_map_ext_hdr_offset(unsigned int name_len);
4f4943f6ef1bc45c23de73eebe83779712b3c8cbTimo Sirainenvoid mail_index_view_transaction_ref(struct mail_index_view *view);
4f4943f6ef1bc45c23de73eebe83779712b3c8cbTimo Sirainenvoid mail_index_view_transaction_unref(struct mail_index_view *view);
4f4943f6ef1bc45c23de73eebe83779712b3c8cbTimo Sirainenvoid mail_index_fsck_locked(struct mail_index *index);
4f4943f6ef1bc45c23de73eebe83779712b3c8cbTimo Sirainenint mail_index_set_error(struct mail_index *index, const char *fmt, ...)
e7a4c77db3a37224b91e16d139fa80ce67dc37ffTimo Sirainen/* "%s failed with index file %s: %m" */
4f4943f6ef1bc45c23de73eebe83779712b3c8cbTimo Sirainenint mail_index_set_syscall_error(struct mail_index *index,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* "%s failed with file %s: %m" */
55bc6a7a0940ec48a68558ef70838991c5d301d2Timo Sirainenint mail_index_file_set_syscall_error(struct mail_index *index,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenuint32_t mail_index_uint32_to_offset(uint32_t offset);