loader/linux: do not pad initrd with zeroes at the end
Syslinux memdisk is using initrd image and needs to know uncompressed size in advance. For gzip uncompressed size is at the end of compressed stream. Grub padded each input file to 4 bytes at the end, which means syslinux got wrong size. Linux initramfs loader apparently does not care about trailing alignment. So change code to align beginning of each file instead which atomatically gives us the correct size for single file. Reported-By: David Shaw <dshaw@jabberwocky.com>
This commit is contained in:
parent
71783dc978
commit
a8c473288d
1 changed files with 7 additions and 4 deletions
|
@ -161,6 +161,9 @@ grub_initrd_init (int argc, char *argv[],
|
|||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
const char *fname = argv[i];
|
||||
|
||||
initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4);
|
||||
|
||||
if (grub_memcmp (argv[i], "newc:", 5) == 0)
|
||||
{
|
||||
const char *ptr, *eptr;
|
||||
|
@ -205,7 +208,7 @@ grub_initrd_init (int argc, char *argv[],
|
|||
initrd_ctx->nfiles++;
|
||||
initrd_ctx->components[i].size
|
||||
= grub_file_size (initrd_ctx->components[i].file);
|
||||
initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4);
|
||||
initrd_ctx->size += initrd_ctx->components[i].size;
|
||||
}
|
||||
|
||||
if (newc)
|
||||
|
@ -248,10 +251,12 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
|
|||
int i;
|
||||
int newc = 0;
|
||||
struct dir *root = 0;
|
||||
grub_ssize_t cursize = 0;
|
||||
|
||||
for (i = 0; i < initrd_ctx->nfiles; i++)
|
||||
{
|
||||
grub_ssize_t cursize;
|
||||
grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
|
||||
ptr += ALIGN_UP_OVERHEAD (cursize, 4);
|
||||
|
||||
if (initrd_ctx->components[i].newc_name)
|
||||
{
|
||||
|
@ -283,8 +288,6 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
|
|||
return grub_errno;
|
||||
}
|
||||
ptr += cursize;
|
||||
grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4));
|
||||
ptr += ALIGN_UP_OVERHEAD (cursize, 4);
|
||||
}
|
||||
if (newc)
|
||||
ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0);
|
||||
|
|
Loading…
Reference in a new issue