diff = dest->used - ext_hdr->hdr_size;
buffer_copy(map->hdr_copy_buf, hdr_offset + diff,
map->hdr_copy_buf, hdr_offset, SIZE_MAX);
- map->hdr_base = map->hdr_copy_buf->data;
hdr->header_size += diff;
*offset_p += diff;
buffer_copy(map->hdr_copy_buf, offset,
map->hdr_copy_buf, next_offset, SIZE_MAX);
buffer_set_used_size(map->hdr_copy_buf, hdr->header_size);
- map->hdr_base = map->hdr_copy_buf->data;
}
}
buffer_set_used_size(map->hdr_copy_buf, 0);
buffer_append(map->hdr_copy_buf, rec_map->mmap_base, hdr->header_size);
- map->hdr_base = rec_map->mmap_base;
rec_map->records = PTR_OFFSET(rec_map->mmap_base, map->hdr.header_size);
return 1;
}
map->rec_map->records_count = records_count;
mail_index_map_copy_hdr(map, hdr);
- map->hdr_base = map->hdr_copy_buf->data;
i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
return 1;
}
i_zero(&tmp_map);
mail_index_header_init(index, &tmp_map.hdr);
+ tmp_map.hdr_copy_buf = t_buffer_create(sizeof(tmp_map.hdr));
+ buffer_append(tmp_map.hdr_copy_buf, &tmp_map.hdr, sizeof(tmp_map.hdr));
tmp_map.index = index;
- tmp_map.hdr_base = &tmp_map.hdr;
/* a bit kludgy way to do this, but it initializes everything
nicely and correctly */
MAIL_INDEX_MAP_HDR_OFFSET(src, src->hdr.base_header_size),
src->hdr.header_size - src->hdr.base_header_size);
}
- dest->hdr_base = buffer_get_modifiable_data(dest->hdr_copy_buf, NULL);
i_assert(dest->hdr_copy_buf->used == dest->hdr.header_size);
}
buffer_write(map->hdr_copy_buf, ext->hdr_offset,
&new_modseq_hdr, sizeof(new_modseq_hdr));
- map->hdr_base = map->hdr_copy_buf->data;
i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
}
}
};
#define MAIL_INDEX_MAP_HDR_OFFSET(map, hdr_offset) \
- CONST_PTR_OFFSET((map)->hdr_base, hdr_offset)
+ CONST_PTR_OFFSET((map)->hdr_copy_buf->data, hdr_offset)
struct mail_index_map {
struct mail_index *index;
int refcount;
+ /* Copy of the base header for convenience. Note that base_header_size
+ may be smaller or larger than this struct. If it's smaller, the last
+ fields in the struct are filled with zeroes. */
struct mail_index_header hdr;
- const void *hdr_base;
+ /* Copy of the full header. */
buffer_t *hdr_copy_buf;
pool_t extension_pool;
}
i_assert((map->hdr_copy_buf->used % sizeof(uint64_t)) == 0);
- map->hdr_base = map->hdr_copy_buf->data;
map->hdr.header_size = map->hdr_copy_buf->used;
ext_hdr = get_ext_header(map, ext);
i_assert((hdr_buf->used % sizeof(uint64_t)) == 0);
map->hdr.header_size = hdr_buf->used;
- map->hdr_base = hdr_buf->data;
mail_index_sync_init_handlers(ctx);
sync_ext_reorder(map, ext_map_idx, 0);
memset(buffer_get_space_unsafe(map->hdr_copy_buf, ext->hdr_offset,
ext->hdr_size), 0, ext->hdr_size);
- map->hdr_base = map->hdr_copy_buf->data;
i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
for (seq = 1; seq <= view->map->rec_map->records_count; seq++) {
}
buffer_write(map->hdr_copy_buf, ext->hdr_offset + offset, data, size);
- map->hdr_base = map->hdr_copy_buf->data;
i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
if (ext->index_idx == ctx->view->index->modseq_ext_id)
}
buffer_copy(map->hdr_copy_buf, ext->hdr_offset, buf, 0, buf->used);
- map->hdr_base = map->hdr_copy_buf->data;
i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
if (mail_index_map_parse_keywords(map) < 0)
}
buffer_write(map->hdr_copy_buf, u->offset, u + 1, u->size);
- map->hdr_base = map->hdr_copy_buf->data;
i_assert(map->hdr_copy_buf->used == map->hdr.header_size);
/* @UNSAFE */
if (had_dirty)
map->hdr.flags &= ENUM_NEGATE(MAIL_INDEX_HDR_FLAG_HAVE_DIRTY);
- if (map->hdr_base != map->hdr_copy_buf->data) {
- /* if syncing updates the header, it updates hdr_copy_buf
- and updates hdr_base to hdr_copy_buf. so the buffer must
- initially contain a valid header or we'll break it when
- writing it. */
- buffer_set_used_size(map->hdr_copy_buf, 0);
- buffer_append(map->hdr_copy_buf, map->hdr_base,
- map->hdr.header_size);
- map->hdr_base = map->hdr_copy_buf->data;
- }
-
mail_transaction_log_view_get_prev_pos(view->log_view,
&prev_seq, &prev_offset);
struct mail_index_record_map rec_map = {
.records_count = 0,
};
+ buffer_t hdr_copy;
struct mail_index_map map = {
.hdr = {
.indexid = TEST_INDEXID,
.log_file_tail_offset = 100,
.log_file_head_offset = LOG_FILE1_HEAD_OFFSET,
},
+ .hdr_copy_buf = &hdr_copy,
.rec_map = &rec_map,
};
+ buffer_create_from_data(&hdr_copy, &map.hdr, sizeof(&map.hdr));
struct mail_index index = {
.event = event_create(NULL),
.log = &log,