[dovecot-cvs] dovecot/src/lib-index mail-index-sync-ext.c,1.9,1.10

cras at dovecot.org cras at dovecot.org
Wed Jul 13 18:55:20 EEST 2005


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv9034/lib-index

Modified Files:
	mail-index-sync-ext.c 
Log Message:
Keep record size divisible with maximum wanted extension field alignment.



Index: mail-index-sync-ext.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-ext.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mail-index-sync-ext.c	4 Jul 2005 11:32:20 -0000	1.9
+++ mail-index-sync-ext.c	13 Jul 2005 15:55:11 -0000	1.10
@@ -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. */



More information about the dovecot-cvs mailing list