Blame SOURCES/dovecot-2.3.16-ftbfsbigend.patch

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