mail-index-private.h revision 3bf14402b7ec0795fbe5721b31b7e98e883d98c0
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* How large index files to mmap() instead of reading to memory. */
a53cb86b4d733d9c48ee4d285bed477c80825804Timo Sirainen/* How many seconds to wait a lock for index file. */
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen/* How many times to retry opening index files if read/fstat returns ESTALE.
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen This happens with NFS when the file has been deleted (ie. index file was
31ddc75584c5cde53d2e78a737587f2e7fdcb0d2Timo Sirainen rewritten by another computer than us). */
89b548af722113acb5d63dfffb44423cb60f91e4Timo Sirainen#define MAIL_INDEX_ESTALE_RETRY_COUNT NFS_ESTALE_RETRY_COUNT
3697080532ccd9f51fac108be6079b616c7a2ddfTimo Sirainen PTR_OFFSET((map)->rec_map->records, (idx) * (map)->hdr.record_size))
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainentypedef int mail_index_expunge_handler_t(struct mail_index_sync_map_ctx *ctx,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainentypedef int mail_index_sync_handler_t(struct mail_index_sync_map_ctx *ctx,
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainentypedef void mail_index_sync_lost_handler_t(struct mail_index *index);
cfa9359fbd6a967ccdcd553c5e483a093885ab6fTimo Sirainen uint32_t ext_offset; /* points to beginning of mail_index_ext_header */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen uint32_t hdr_offset; /* points to mail_index_ext_header.data[] */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen uint32_t hdr_size; /* size of mail_index_ext_header.data[] */
d74899545d913eac91c82b692927b32c3bf36abaTimo Sirainen /* unsigned char name[name_size] */
d74899545d913eac91c82b692927b32c3bf36abaTimo Sirainen /* unsigned char data[hdr_size] (starting 64bit aligned) */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen /* struct mail_index_keyword_header_rec[] */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen /* char name[][] */
625101600b8c05f72f79b13604de0c751a73e959Timo Sirainen uint32_t unused; /* for backwards compatibility */
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen uint32_t name_offset; /* relative to beginning of name[] */
c27f03fa8fd2ef4acd1db814fae7d90e0eb9d3aeTimo Sirainen uint32_t hdr_size; /* size of mail_index_ext_header.data[] */
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen mail_index_expunge_handler_t *expunge_handler;
3697080532ccd9f51fac108be6079b616c7a2ddfTimo Sirainen unsigned int lock_id;
3697080532ccd9f51fac108be6079b616c7a2ddfTimo Sirainen void *records; /* struct mail_index_record[] */
3697080532ccd9f51fac108be6079b616c7a2ddfTimo Sirainen /* If this mapping is written to disk and write_atomic=FALSE,
3697080532ccd9f51fac108be6079b616c7a2ddfTimo Sirainen write_seq_* specify the message sequence range that needs to be
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ARRAY_DEFINE(extensions, struct mail_index_ext);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ARRAY_DEFINE(ext_id_map, uint32_t); /* index -> file */
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ARRAY_DEFINE(keyword_idx_map, unsigned int); /* file -> index */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen unsigned int write_atomic:1; /* write to a new file and rename() */
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen unsigned int id;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ARRAY_DEFINE(extensions, struct mail_index_registered_ext);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ARRAY_DEFINE(sync_lost_handlers, mail_index_sync_lost_handler_t *);
8e57335924f5ff57cbd1929ec99764dc267c3312Timo Sirainen /* last_read_log_file_* contains the seq/offsets we last read from
e3689d0f073341e844638f34e1e4d0b7bb053cc8Timo Sirainen the main index file's headers. these are used to figure out when
8e57335924f5ff57cbd1929ec99764dc267c3312Timo Sirainen the main index file should be updated, and if we can update it
8e57335924f5ff57cbd1929ec99764dc267c3312Timo Sirainen by writing on top of it or if we need to recreate it. */
e3689d0f073341e844638f34e1e4d0b7bb053cc8Timo Sirainen /* transaction log head seq/offset when we last fscked */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen int lock_type, shared_lock_count, excl_lock_count;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen struct hash_table *keywords_hash; /* name -> idx */
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen /* Module-specific contexts. */
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainen ARRAY_DEFINE(module_contexts, union mail_index_module_context *);
46c31f64b9f0949f00b7819f45b22f2d64b2ea27Timo Sirainenextern struct mail_index_module_register mail_index_module_register;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen/* Add/replace sync handler for specified extra record. */
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid mail_index_register_expunge_handler(struct mail_index *index,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenvoid mail_index_unregister_expunge_handler(struct mail_index *index,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid mail_index_register_sync_handler(struct mail_index *index, uint32_t ext_id,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenvoid mail_index_unregister_sync_handler(struct mail_index *index,
f23298fea47eecbeded985ee2537a34c4c4ef56bTimo Sirainenvoid mail_index_register_sync_lost_handler(struct mail_index *index,
519e0a461271843833a2b42626ad93f6e7ddc497Timo Sirainenvoid mail_index_unregister_sync_lost_handler(struct mail_index *index,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_create_tmp_file(struct mail_index *index, const char **path_r);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenint mail_index_try_open_only(struct mail_index *index);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenint mail_index_reopen_if_changed(struct mail_index *index);
10a97b15c34119ffe2d2eab9b975252fed631df2Timo Sirainen/* Update/rewrite the main index file from index->map */
10a97b15c34119ffe2d2eab9b975252fed631df2Timo Sirainenvoid mail_index_write(struct mail_index *index, bool want_rotate);
5c1a8aee989af87bddefd71e2aa83aa2bd695155Timo Sirainen/* Returns 0 = ok, -1 = error. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenint mail_index_lock_shared(struct mail_index *index, unsigned int *lock_id_r);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Returns 1 = ok, 0 = already locked, -1 = error. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenint mail_index_try_lock_exclusive(struct mail_index *index,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen unsigned int *lock_id_r);
14c474d9f4591c397ed0b5206af6537c7b52c924Timo Sirainenvoid mail_index_unlock(struct mail_index *index, unsigned int *lock_id);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen/* Returns TRUE if given lock_id is valid. */
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainenbool mail_index_is_locked(struct mail_index *index, unsigned int lock_id);
2af769daebd83719ac696a440e06f6020471cec0Timo Sirainenint mail_index_lock_fd(struct mail_index *index, const char *path, int fd,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Allocate a new empty map. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstruct mail_index_map *mail_index_map_alloc(struct mail_index *index);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen/* Replace index->map with the latest index changes. This may reopen the index
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen file and/or it may read the latest changes from transaction log. The log is
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen read up to EOF, but non-synced expunges are skipped.
14c474d9f4591c397ed0b5206af6537c7b52c924Timo Sirainen If we mmap()ed the index file, the map is returned locked.
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen Returns 1 = ok, 0 = corrupted, -1 = error. If non-fatal problems were found,
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen 1 is returned but index->fsck=TRUE is set. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Unreference given mapping and unmap it if it's dropped to zero. */
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainenvoid mail_index_unmap(struct mail_index_map **map);
14c474d9f4591c397ed0b5206af6537c7b52c924Timo Sirainen/* Clone a map. The returned map is always in memory. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstruct mail_index_map *mail_index_map_clone(const struct mail_index_map *map);
a28a6267f48971117dec958b160deefd14ebb7a6Timo Sirainenvoid mail_index_record_map_move_to_private(struct mail_index_map *map);
14c474d9f4591c397ed0b5206af6537c7b52c924Timo Sirainen/* Move a mmaped map to memory. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid mail_index_map_move_to_memory(struct mail_index_map *map);
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainenuint32_t mail_index_map_lookup_ext(struct mail_index_map *map,
bbf796c17f02538058d7559bfe96d677e5b55015Timo Sirainen const char *name);
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainenmail_index_map_register_ext(struct mail_index_map *map, const char *name,
12053b7b4b57dbd2790057426d1633988eedad56Timo Sirainenbool mail_index_map_get_ext_idx(struct mail_index_map *map,
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenmail_index_view_get_ext(struct mail_index_view *view, uint32_t ext_id);
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainenint mail_index_map_parse_keywords(struct mail_index_map *map);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_view_transaction_ref(struct mail_index_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mail_index_view_transaction_unref(struct mail_index_view *view);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_set_error(struct mail_index *index, const char *fmt, ...)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* "%s failed with index file %s: %m" */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_set_syscall_error(struct mail_index *index,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* "%s failed with file %s: %m" */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint mail_index_file_set_syscall_error(struct mail_index *index,
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainenuint32_t mail_index_uint32_to_offset(uint32_t offset);