mail-cache-transaction.c revision 4bbee99b3aef449a9a2a11a5b5cf1ca486915c49
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi/* Copyright (C) 2003-2004 Timo Sirainen */
1d980e5489836e977ba59b419e27b0ec875c4bd3takashistatic const unsigned char *null4[] = { 0, 0, 0, 0 };
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi buffer_create_dynamic(system_pool, 256, (size_t)-1);
1d980e5489836e977ba59b419e27b0ec875c4bd3takashistatic void mail_cache_transaction_free(struct mail_cache_transaction_ctx *ctx)
1d980e5489836e977ba59b419e27b0ec875c4bd3takashistatic int mail_cache_grow_file(struct mail_cache *cache, size_t size)
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi /* grow the file */
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi grow_size = new_fsize / 100 * MAIL_CACHE_GROW_PERCENTAGE;
b2a930a0c94e9fd25f8d2b3a2c53573235db3f06nilgun mail_cache_set_syscall_error(cache, "file_set_size()");
1d980e5489836e977ba59b419e27b0ec875c4bd3takashistatic int mail_cache_unlink_hole(struct mail_cache *cache, size_t size,
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi while (offset != 0) {
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi if (pread_full(cache->fd, &hole, sizeof(hole), offset) <= 0) {
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi mail_cache_set_syscall_error(cache, "pread_full()");
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi "Invalid magic in hole header");
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi mail_cache_set_syscall_error(cache, "pwrite_full()");
b2a930a0c94e9fd25f8d2b3a2c53573235db3f06nilgunmail_cache_transaction_add_reservation(struct mail_cache_transaction_ctx *ctx)
b2a930a0c94e9fd25f8d2b3a2c53573235db3f06nilgun buffer_append(ctx->reservations, &ctx->reserved_space_offset,
b2a930a0c94e9fd25f8d2b3a2c53573235db3f06nilgun buffer_append(ctx->reservations, &ctx->reserved_space,
b2a930a0c94e9fd25f8d2b3a2c53573235db3f06nilgunmail_cache_transaction_reserve_more(struct mail_cache_transaction_ctx *ctx,
b2a930a0c94e9fd25f8d2b3a2c53573235db3f06nilgun /* found a large enough hole. */
11495c9f0bd33e51a25b4d532beadfbcf9b944a3nilgun /* mail_cache_unlink_hole() could have noticed corruption */
727872d18412fc021f03969b8641810d8896820bhumbedooh if ((uoff_t)hdr->used_file_size + size > (uint32_t)-1) {
0d0ba3a410038e179b695446bb149cce6264e0abnd mail_index_set_error(cache->index, "Cache file too large: %s",
205f749042ed530040a4f0080dbcb47ceae8a374rjung /* we can simply grow it */
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd /* grow reservation. it's probably the last one in the buffer,
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd but it's not guarateed because we might have used holes
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd as well */
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi buf = buffer_get_modifyable_data(ctx->reservations, &size);
if (!locked) {
if (!locked)
static uint32_t
int ret;
if (!locked) {
commit);
if (!locked)
if (ret < 0)
return offset;
int commit;
if (commit) {
seq_limit = 0;
&max_size,
commit);
if (write_offset == 0) {
seq_limit++;
if (old_offset != 0) {
write_offset) < 0)
void *data;
int ret = 0;
return ret;
if (size > 0) {
} while (size > 0);
const void *data;
int ret = 0;
t_push();
if (offset == 0)
&hdr_offset) < 0)
hdr_offset) < 0) {
t_pop();
return ret;
unsigned int fixed_size;
sizeof(data_size32));