changeset 3819:61f0e1fe9b55 HEAD

Moved uoff_t and time_t compatibility checks to cache file, since they're not needed for index/log. Only index file incompatibility check is now endianess flag.
author Timo Sirainen <tss@iki.fi>
date Fri, 06 Jan 2006 16:21:21 +0200
parents 6758c0f3c318
children ec0119de5aa2
files src/lib-index/mail-cache-compress.c src/lib-index/mail-cache-private.h src/lib-index/mail-cache.c src/lib-index/mail-index.c src/lib-index/mail-index.h
diffstat 5 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-compress.c	Fri Jan 06 16:06:23 2006 +0200
+++ b/src/lib-index/mail-cache-compress.c	Fri Jan 06 16:21:21 2006 +0200
@@ -144,6 +144,8 @@
 
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.version = MAIL_CACHE_VERSION;
+	hdr.compat_sizeof_uoff_t = sizeof(uoff_t);
+	hdr.compat_sizeof_time_t = sizeof(time_t);
 	hdr.indexid = idx_hdr->indexid;
 	hdr.file_seq = get_next_file_seq(cache, view);
 	o_stream_send(output, &hdr, sizeof(hdr));
--- a/src/lib-index/mail-cache-private.h	Fri Jan 06 16:06:23 2006 +0200
+++ b/src/lib-index/mail-cache-private.h	Fri Jan 06 16:21:21 2006 +0200
@@ -44,7 +44,9 @@
 	/* version is increased only when you can't have backwards
 	   compatibility. */
 	uint8_t version;
-	uint8_t unused[3];
+	uint8_t compat_sizeof_uoff_t;
+	uint8_t compat_sizeof_time_t;
+	uint8_t unused;
 
 	uint32_t indexid;
 	uint32_t file_seq;
--- a/src/lib-index/mail-cache.c	Fri Jan 06 16:06:23 2006 +0200
+++ b/src/lib-index/mail-cache.c	Fri Jan 06 16:21:21 2006 +0200
@@ -126,6 +126,19 @@
 		/* version changed - upgrade silently */
 		return FALSE;
 	}
+	if (hdr->compat_sizeof_uoff_t != sizeof(uoff_t) ||
+	    hdr->compat_sizeof_time_t != sizeof(time_t)) {
+		if (hdr->compat_sizeof_uoff_t == 0 &&
+		    hdr->compat_sizeof_time_t == 0) {
+			/* FIXME: keep backwards compatibility for a while.
+			   set hdr_modified=TRUE so header gets fixed the next
+			   time cache is locked. */
+			cache->hdr_modified = TRUE;
+		} else {
+			/* architecture change - handle silently(?) */
+			return -1;
+		}
+	}
 
 	if (cache->hdr->indexid != cache->index->indexid) {
 		/* index id changed */
@@ -456,6 +469,10 @@
 	}
 
 	if (cache->hdr_modified) {
+		/* FIXME: for backwards compatibility - keep them for a while */
+		cache->hdr_copy.compat_sizeof_uoff_t = sizeof(uoff_t);
+		cache->hdr_copy.compat_sizeof_time_t = sizeof(time_t);
+
 		cache->hdr_modified = FALSE;
 		if (mail_cache_write(cache, &cache->hdr_copy,
 				     sizeof(cache->hdr_copy), 0) < 0)
--- a/src/lib-index/mail-index.c	Fri Jan 06 16:06:23 2006 +0200
+++ b/src/lib-index/mail-index.c	Fri Jan 06 16:21:21 2006 +0200
@@ -492,20 +492,17 @@
 				   struct mail_index_map *map)
 {
 	const struct mail_index_header *hdr = &map->hdr;
-	unsigned char compat_data[sizeof(hdr->compat_data)];
+        enum mail_index_header_compat_flags compat_flags = 0;
 
-	memset(compat_data, 0, sizeof(compat_data));
 #ifndef WORDS_BIGENDIAN
-	compat_data[0] = MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
+	compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
 #endif
-	compat_data[1] = sizeof(uoff_t);
-	compat_data[2] = sizeof(time_t);
 
 	if (hdr->major_version != MAIL_INDEX_MAJOR_VERSION) {
 		/* major version change - handle silently(?) */
 		return -1;
 	}
-	if (memcmp(hdr->compat_data, compat_data, sizeof(compat_data)) != 0) {
+	if (hdr->compat_flags != compat_flags) {
 		/* architecture change - handle silently(?) */
 		return -1;
 	}
@@ -1350,10 +1347,8 @@
 	hdr->record_size = sizeof(struct mail_index_record);
 
 #ifndef WORDS_BIGENDIAN
-	hdr->compat_data[0] = MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
+	hdr->compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
 #endif
-	hdr->compat_data[1] = sizeof(uoff_t);
-	hdr->compat_data[2] = sizeof(time_t);
 
 	hdr->indexid = now;
 
--- a/src/lib-index/mail-index.h	Fri Jan 06 16:06:23 2006 +0200
+++ b/src/lib-index/mail-index.h	Fri Jan 06 16:21:21 2006 +0200
@@ -67,11 +67,8 @@
 	uint32_t header_size; /* base + extended header size */
 	uint32_t record_size;
 
-	/* 0 = flags
-	   1 = sizeof(uoff_t)
-	   2 = sizeof(time_t)
-	   3 = unused */
-	uint8_t compat_data[4];
+	uint8_t compat_flags; /* enum mail_index_header_compat_flags */
+	uint8_t unused[3];
 
 	uint32_t indexid;
 	uint32_t flags;