Blame SOURCES/dovecot-2.3.16-ftbfsbigend.patch

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