mail-index.c revision 9a3633bc52d15b54d6bc55648aca6fa2815232cb
25757faf029c369a8318349dafe952e2358df1d8Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen unsigned int extra;
0a00890f8ec34ee08d0d391441fca36ed42d7a0cTimo Sirainen if (index->mmap_full_length < sizeof(MailIndexHeader)) {
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen extra = (index->mmap_full_length - sizeof(MailIndexHeader)) %
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen /* partial write or corrupted -
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen truncate the file to valid length */
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen (void)ftruncate(index->fd, (off_t)index->mmap_full_length);
137ea7ca34005345aa2304a940149b7f3774d727Timo Sirainen if (hdr->used_file_size > index->mmap_full_length) {
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen index_set_corrupted(index, "used_file_size larger than real "
49e513d090753ccbf95560b2f3a21f081a5b6c51Timo Sirainen if ((hdr->used_file_size - sizeof(MailIndexHeader)) %
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen sizeof(MailIndexRecord) != 0) {
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen index_set_corrupted(index, "Invalid used_file_size in header "
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen if (hdr->messages_count < hdr->seen_messages_count) {
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen index_set_corrupted(index, "Invalid seen messages count "
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen if (hdr->messages_count < hdr->deleted_messages_count) {
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen index_set_corrupted(index, "Invalid deleted messages count "
12aad74464367f7e8be11eafe1af985bf7b1adecTimo Sirainen index->mmap_used_length = hdr->used_file_size;
965ed6ea3fc8f7637bd0d159d2fdb283a191ce34Timo Sirainen index->header = (MailIndexHeader *) index->mmap_base;
0727e38ac12efb8963a339daf56255e2be1f29fcTimo Sirainen /* make sure file size hasn't changed */
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen if (index->header->sync_id == index->sync_id) {
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen index->mmap_used_length = index->header->used_file_size;
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen if (index->mmap_used_length > index->mmap_full_length) {
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen "updating sync_id");
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen (void)munmap(index->mmap_base, index->mmap_full_length);
1f1e81aab38d833d1c9cdc244c91fd762e0080d4Timo Sirainen index->mmap_base = mmap_rw_file(index->fd, &index->mmap_full_length);
int failed;
return TRUE;
return FALSE;
return !failed;
return TRUE;
int ret;
return TRUE;
return TRUE;
if (ret < 0)
return ret > 0;
int failed;
if (failed)
return !failed;
return TRUE;
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
return TRUE;
return TRUE;
MS_SYNC) < 0) {
return TRUE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
unsigned int rec_seq;
return NULL;
return NULL;
return NULL;
sizeof(MailIndexHeader));
sizeof(MailIndexRecord));
return NULL;
return rec;
rec_seq++;
rec++;
return NULL;
return rec;
return NULL;
unsigned int first_uid,
unsigned int last_uid)
return NULL;
sizeof(MailIndexHeader));
sizeof(MailIndexRecord));
return NULL;
return NULL;
if (pos == 0)
return rec;
return NULL;
sizeof(MailIndexHeader));
return NULL;
return rec;
rec++;
return NULL;
static MailIndexDataRecord *
return NULL;
return NULL;
return NULL;
*size = 0;
return NULL;
unsigned int seq;
return INDEX_POSITION_INDEX(
return INDEX_POSITION_INDEX(
seq++;
return seq;
rec++;
return FALSE;
return FALSE;
return TRUE;
return FALSE;
if (seq != 0) {
return FALSE;
return FALSE;
return TRUE;
int external_change)
void *base;
return TRUE;
return FALSE;
return TRUE;
return FALSE;
return TRUE;
return TRUE;