Blame SOURCES/dovecot-2.3.16-ftbfsbigend.patch

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