changeset 3495:5ed3f06cd1b8 HEAD

Keep record size divisible with maximum wanted extension field alignment.
author Timo Sirainen <tss@iki.fi>
date Wed, 13 Jul 2005 18:55:11 +0300
parents 7cab5dc6a0cd
children 51bf11f92c07
files src/lib-index/mail-index-sync-ext.c
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync-ext.c	Wed Jul 13 18:50:56 2005 +0300
+++ b/src/lib-index/mail-index-sync-ext.c	Wed Jul 13 18:55:11 2005 +0300
@@ -169,7 +169,7 @@
 	struct mail_index_map *new_map;
 	struct mail_index_ext *ext, **sorted;
 	struct mail_index_ext_header *ext_hdr;
-	uint16_t *old_offsets, min_align;
+	uint16_t *old_offsets, min_align, max_align;
 	uint32_t offset, old_records_count, rec_idx;
 	unsigned int i, count;
 	const void *src;
@@ -192,9 +192,13 @@
 	   requirement first. FIXME: if the extension sizes don't match
 	   alignmentation, this may not give the minimal layout. */
 	offset = sizeof(struct mail_index_record);
+	max_align = sizeof(uint32_t);
 	for (;;) {
 		min_align = (uint16_t)-1;
 		for (i = 0; i < count; i++) {
+			if (sorted[i]->record_align > max_align)
+				max_align = sorted[i]->record_align;
+
 			if (sorted[i]->record_offset == 0) {
 				if ((offset % sorted[i]->record_align) == 0)
 					break;
@@ -218,9 +222,9 @@
 		i_assert(offset < (uint16_t)-1);
 	}
 
-	if ((offset % sizeof(uint32_t)) != 0) {
-		/* keep 32bit alignment */
-		offset += sizeof(uint32_t) - (offset % sizeof(uint32_t));
+	if ((offset % max_align) != 0) {
+		/* keep record size divisible with maximum alignment */
+		offset += max_align - (offset % max_align);
 	}
 
 	/* create a new mapping without records. a bit kludgy. */