From: Timo Sirainen Date: Sun, 24 Aug 2003 07:06:06 +0000 (+0300) Subject: Added back compat_data[]. It wasn't so simple to access data portably in X-Git-Tag: 1.1.alpha1~4384 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21334f6ca1d3f4e7ef0c9920e81c15b4c5485c45;p=thirdparty%2Fdovecot%2Fcore.git Added back compat_data[]. It wasn't so simple to access data portably in index files after all.. --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-open.c b/src/lib-index/mail-index-open.c index 7af82bb2c1..de946d76b7 100644 --- a/src/lib-index/mail-index-open.c +++ b/src/lib-index/mail-index-open.c @@ -196,6 +196,16 @@ static int mail_index_init_file(struct mail_index *index, return TRUE; } +static void get_compat_data(unsigned char compat_data[4]) +{ +#ifndef WORDS_BIGENDIAN + compat_data[0] = MAIL_INDEX_COMPAT_LITTLE_ENDIAN; +#endif + compat_data[1] = sizeof(uoff_t); + compat_data[2] = sizeof(time_t); + compat_data[3] = 0; +} + void mail_index_init_header(struct mail_index_header *hdr) { i_assert(sizeof(struct mail_index_header) < 256); @@ -204,6 +214,7 @@ void mail_index_init_header(struct mail_index_header *hdr) hdr->major_version = MAIL_INDEX_MAJOR_VERSION; hdr->minor_version = MAIL_INDEX_MINOR_VERSION; hdr->header_size = (uint8_t)sizeof(struct mail_index_header); + get_compat_data(hdr->compat_data); hdr->indexid = ioloop_time; @@ -278,6 +289,7 @@ static int mail_index_open_index(struct mail_index *index, enum mail_index_open_flags flags) { struct mail_index_header hdr; + unsigned char compat_data[4]; int ret; if ((flags & _MAIL_INDEX_OPEN_FLAG_CREATING) == 0) @@ -299,8 +311,10 @@ static int mail_index_open_index(struct mail_index *index, return FALSE; index->indexid = hdr.indexid; + get_compat_data(compat_data); if (ret == 0 || hdr.major_version != MAIL_INDEX_MAJOR_VERSION || (hdr.flags & MAIL_INDEX_HDR_FLAG_REBUILD) != 0 || + memcmp(compat_data, hdr.compat_data, sizeof(compat_data)) != 0 || !mail_index_mmap_update(index)) { if ((flags & MAIL_INDEX_OPEN_FLAG_CREATE) == 0) return FALSE; diff --git a/src/lib-index/mail-index.h b/src/lib-index/mail-index.h index 2c4c7158e9..a217a5113a 100644 --- a/src/lib-index/mail-index.h +++ b/src/lib-index/mail-index.h @@ -24,6 +24,10 @@ enum mail_index_open_flags { _MAIL_INDEX_OPEN_FLAG_CREATING = 0x100 }; +enum mail_index_header_compat_flags { + MAIL_INDEX_COMPAT_LITTLE_ENDIAN = 0x01 +}; + enum mail_index_header_flag { /* Rebuild flag is set while index is being rebuilt or when some error is noticed in the index file. If this flag is set, @@ -104,6 +108,12 @@ struct mail_index_header { uint8_t header_size; uint8_t reserved; + /* 0 = flags + 1 = sizeof(uoff_t) + 2 = sizeof(time_t) + 3 = reserved, 0 for now */ + uint8_t compat_data[4]; + uint32_t indexid; uint32_t used_file_size;