Blame SOURCES/0197-loader-linux-do-not-pad-initrd-with-zeroes-at-the-en.patch

6b3c76
From d0bf58c1c71a1e192fa955e9786432bcdcb31bf1 Mon Sep 17 00:00:00 2001
a85e8e
From: Andrei Borzenkov <arvidjaar@gmail.com>
a85e8e
Date: Thu, 7 May 2015 20:24:24 +0300
6b3c76
Subject: [PATCH 197/261] loader/linux: do not pad initrd with zeroes at the
6b3c76
 end
a85e8e
a85e8e
Syslinux memdisk is using initrd image and needs to know uncompressed
a85e8e
size in advance. For gzip uncompressed size is at the end of compressed
a85e8e
stream. Grub padded each input file to 4 bytes at the end, which means
a85e8e
syslinux got wrong size.
a85e8e
a85e8e
Linux initramfs loader apparently does not care about trailing alignment.
a85e8e
So change code to align beginning of each file instead which atomatically
a85e8e
gives us the correct size for single file.
a85e8e
a85e8e
Reported-By: David Shaw <dshaw@jabberwocky.com>
a85e8e
a85e8e
(cherry picked from commit a8c473288d3f0a5e17a903a5121dea1a695dda3b)
a85e8e
a85e8e
Resolves: rhbz#1219864
a85e8e
---
a85e8e
 grub-core/loader/linux.c | 11 +++++++----
a85e8e
 1 file changed, 7 insertions(+), 4 deletions(-)
a85e8e
a85e8e
diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
6b3c76
index 117232f0c..d2cd591f6 100644
a85e8e
--- a/grub-core/loader/linux.c
a85e8e
+++ b/grub-core/loader/linux.c
a85e8e
@@ -161,6 +161,9 @@ grub_initrd_init (int argc, char *argv[],
a85e8e
   for (i = 0; i < argc; i++)
a85e8e
     {
a85e8e
       const char *fname = argv[i];
a85e8e
+
a85e8e
+      initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
a85e8e
+
a85e8e
       if (grub_memcmp (argv[i], "newc:", 5) == 0)
a85e8e
 	{
a85e8e
 	  const char *ptr, *eptr;
a85e8e
@@ -205,7 +208,7 @@ grub_initrd_init (int argc, char *argv[],
a85e8e
       initrd_ctx->nfiles++;
a85e8e
       initrd_ctx->components[i].size
a85e8e
 	= grub_file_size (initrd_ctx->components[i].file);
a85e8e
-      initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4);
a85e8e
+      initrd_ctx->size += initrd_ctx->components[i].size;
a85e8e
     }
a85e8e
 
a85e8e
   if (newc)
a85e8e
@@ -248,10 +251,12 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
a85e8e
   int i;
a85e8e
   int newc = 0;
a85e8e
   struct dir *root = 0;
a85e8e
+  grub_ssize_t cursize = 0;
a85e8e
 
a85e8e
   for (i = 0; i < initrd_ctx->nfiles; i++)
a85e8e
     {
a85e8e
-      grub_ssize_t cursize;
a85e8e
+      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
a85e8e
+      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
a85e8e
 
a85e8e
       if (initrd_ctx->components[i].newc_name)
a85e8e
 	{
a85e8e
@@ -283,8 +288,6 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
a85e8e
 	  return grub_errno;
a85e8e
 	}
a85e8e
       ptr += cursize;
a85e8e
-      grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
a85e8e
-      ptr += ALIGN_UP_OVERHEAD (cursize, 4);
a85e8e
     }
a85e8e
   if (newc)
a85e8e
     ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0);
6b3c76
-- 
6b3c76
2.13.5
6b3c76