mail-index-view.c revision bf91bed88d4e294b4577ba2a3b14d87cf35ae135
a82212bd36e1074408974b466798b9966bbaf49bvboxsync/* Copyright (C) 2003-2004 Timo Sirainen */
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncvoid mail_index_view_clone(struct mail_index_view *dest,
a82212bd36e1074408974b466798b9966bbaf49bvboxsync dest->log_file_expunge_seq = src->log_file_expunge_seq;
a82212bd36e1074408974b466798b9966bbaf49bvboxsync dest->log_file_expunge_offset = src->log_file_expunge_offset;
a82212bd36e1074408974b466798b9966bbaf49bvboxsync dest->log_file_head_offset = src->log_file_head_offset;
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncvoid mail_index_view_ref(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstatic void _view_close(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* we're not unlocking the view, because views could be temporarily
a82212bd36e1074408974b466798b9966bbaf49bvboxsync created and closed and the current map should stay locked
a82212bd36e1074408974b466798b9966bbaf49bvboxsync (especially syncing) */
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstatic void mail_index_view_check_nextuid(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsync rec = MAIL_INDEX_MAP_IDX(view->map, view->map->hdr.messages_count-1);
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncvoid mail_index_view_unlock(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* currently this is a no-op. if we unlock any maps, they might get
a82212bd36e1074408974b466798b9966bbaf49bvboxsync changed and then it's unspecified what parts of the memory mapping
a82212bd36e1074408974b466798b9966bbaf49bvboxsync are up-to-date. we could also copy the map to memory always, but
a82212bd36e1074408974b466798b9966bbaf49bvboxsync that kinds of defeats the purpose of mmaps. */
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncbool mail_index_view_is_inconsistent(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstruct mail_index *mail_index_view_get_index(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncvoid mail_index_view_transaction_ref(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncvoid mail_index_view_transaction_unref(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstatic void mail_index_view_ref_map(struct mail_index_view *view,
a82212bd36e1074408974b466798b9966bbaf49bvboxsync unsigned int i, count;
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* if map is already referenced, do nothing */
a82212bd36e1074408974b466798b9966bbaf49bvboxsync for (i = 0; i < count; i++) {
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* reference the given mapping. the reference is dropped when the view
a82212bd36e1074408974b466798b9966bbaf49bvboxsync is synchronized or closed. */
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncvoid mail_index_view_unref_maps(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsync unsigned int i, count;
a82212bd36e1074408974b466798b9966bbaf49bvboxsync maps = array_get_modifiable(&view->map_refs, &count);
a82212bd36e1074408974b466798b9966bbaf49bvboxsync for (i = 0; i < count; i++)
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstatic uint32_t _view_get_messages_count(struct mail_index_view *view)
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstatic const struct mail_index_header *
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstatic int _view_lookup_full(struct mail_index_view *view, uint32_t seq,
a82212bd36e1074408974b466798b9966bbaf49bvboxsync i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(view));
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* look up the record */
a82212bd36e1074408974b466798b9966bbaf49bvboxsync mail_index_set_error(view->index, "Corrupted Index file %s: "
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* view's mapping is latest. we can use it directly. */
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* look up the record from head mapping. it may contain some changes. */
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* start looking up from the same sequence as in the old view.
a82212bd36e1074408974b466798b9966bbaf49bvboxsync if there are no expunges, it's there. otherwise it's somewhere
a82212bd36e1074408974b466798b9966bbaf49bvboxsync before (since records can't be inserted).
a82212bd36e1074408974b466798b9966bbaf49bvboxsync usually there are only a few expunges, so just going downwards from
a82212bd36e1074408974b466798b9966bbaf49bvboxsync our initial sequence position is probably faster than binary
a82212bd36e1074408974b466798b9966bbaf49bvboxsync if (seq == 0) {
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* everything is expunged from head. use the old record. */
a82212bd36e1074408974b466798b9966bbaf49bvboxsync } while (seq > 0);
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* found it. use it. reference the index mapping so that the
a82212bd36e1074408974b466798b9966bbaf49bvboxsync returned record doesn't get invalidated after next sync. */
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* expuned from head. use the old record. */
a82212bd36e1074408974b466798b9966bbaf49bvboxsyncstatic int _view_lookup_uid(struct mail_index_view *view, uint32_t seq,
a82212bd36e1074408974b466798b9966bbaf49bvboxsync i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(view));
a82212bd36e1074408974b466798b9966bbaf49bvboxsync /* UID lookups don't require the view to be locked. only expunges
a82212bd36e1074408974b466798b9966bbaf49bvboxsync change them, and expunges will recreate the file */
a82212bd36e1074408974b466798b9966bbaf49bvboxsync *uid_r = MAIL_INDEX_MAP_IDX(view->map, seq-1)->uid;
int nearest_side)
if (nearest_side > 0) {
if (*first_seq_r == 0 ||
#define LOW_UPDATE(x) \
*seq_r = 0;
if (seq == 0)
const void **data_r)
int ret;
return ret;
return ret;
*data_size_r = 0;
const struct mail_index_header *
const void *data;
const unsigned char *keyword_data;
const unsigned int *keyword_idx_map;
int ret;
if (ret < 0)
return ret;
keyword_count = 0;
if (keyword_data[i] == 0)
return ret;
return ret;
const void **data_r)
*hdr_size_r = 0;
*record_size_r = 0;
*record_align_r = 0;
struct mail_index_view *
return view;
const struct mail_index_ext *