Blame SOURCES/dovecot-2.3.16-ftbfsbigend.patch

8cdc5b
commit ec4595097067a736717ef202fe8542b1b4bc2dd5
8cdc5b
Author: Timo Sirainen <timo.sirainen@open-xchange.com>
8cdc5b
Date:   Tue Aug 10 12:22:08 2021 +0300
8cdc5b
8cdc5b
    lib-index: Fix storing cache fields' last_used with 64bit big endian CPUs
8cdc5b
8cdc5b
diff --git a/src/lib-index/mail-cache-fields.c b/src/lib-index/mail-cache-fields.c
8cdc5b
index e929fb559d..429e0d234c 100644
8cdc5b
--- a/src/lib-index/mail-cache-fields.c
8cdc5b
+++ b/src/lib-index/mail-cache-fields.c
8cdc5b
@@ -524,6 +524,19 @@ static void copy_to_buf_byte(struct mail_cache *cache, buffer_t *dest,
8cdc5b
 	}
8cdc5b
 }
8cdc5b
 
8cdc5b
+static void
8cdc5b
+copy_to_buf_last_used(struct mail_cache *cache, buffer_t *dest, bool add_new)
8cdc5b
+{
8cdc5b
+	size_t offset = offsetof(struct mail_cache_field, last_used);
8cdc5b
+#if defined(WORDS_BIGENDIAN) && SIZEOF_VOID_P == 8
8cdc5b
+	/* 64bit time_t with big endian CPUs: copy the last 32 bits instead of
8cdc5b
+	   the first 32 bits (that are always 0). The 32 bits are enough until
8cdc5b
+	   year 2106, so we're not in a hurry to use 64 bits on disk. */
8cdc5b
+	offset += sizeof(uint32_t);
8cdc5b
+#endif
8cdc5b
+	copy_to_buf(cache, dest, add_new, offset, sizeof(uint32_t));
8cdc5b
+}
8cdc5b
+
8cdc5b
 static int mail_cache_header_fields_update_locked(struct mail_cache *cache)
8cdc5b
 {
8cdc5b
 	buffer_t *buffer;
8cdc5b
@@ -536,9 +549,7 @@ static int mail_cache_header_fields_update_locked(struct mail_cache *cache)
8cdc5b
 
8cdc5b
 	buffer = t_buffer_create(256);
8cdc5b
 
8cdc5b
-	copy_to_buf(cache, buffer, FALSE,
8cdc5b
-		    offsetof(struct mail_cache_field, last_used),
8cdc5b
-		    sizeof(uint32_t));
8cdc5b
+	copy_to_buf_last_used(cache, buffer, FALSE);
8cdc5b
 	ret = mail_cache_write(cache, buffer->data, buffer->used,
8cdc5b
 			       offset + MAIL_CACHE_FIELD_LAST_USED());
8cdc5b
 	if (ret == 0) {
8cdc5b
@@ -599,9 +610,7 @@ void mail_cache_header_fields_get(struct mail_cache *cache, buffer_t *dest)
8cdc5b
 	buffer_append(dest, &hdr, sizeof(hdr));
8cdc5b
 
8cdc5b
 	/* we have to keep the field order for the existing fields. */
8cdc5b
-	copy_to_buf(cache, dest, TRUE,
8cdc5b
-		    offsetof(struct mail_cache_field, last_used),
8cdc5b
-		    sizeof(uint32_t));
8cdc5b
+	copy_to_buf_last_used(cache, dest, TRUE);
8cdc5b
 	copy_to_buf(cache, dest, TRUE,
8cdc5b
 		    offsetof(struct mail_cache_field, field_size),
8cdc5b
 		    sizeof(uint32_t));
8cdc5b