• Milton D. Miller II's avatar
    [PATCH] INITRAMFS: allow no trailer · fd604180
    Milton D. Miller II authored
    According to "initramfs buffer format -- third draft"
    http://lwn.net/2002/0117/a/initramfs-buffer-format.php3 "the cpio
    "TRAILER!!!" entry (cpio end-of-archive) is optional, but is not ignored"
    
    The kernel handling does not follow this spec.  If you add null padding
    after an uncompressed cpio without TRAILER!!!  the kernel complains "no
    cpio magic".  In a gzipped archive one gets "junk in gzipped archive"
    without the TRAILER!!!
    
    This patch changes the state transitions so the kernel will follow the spec.
    
    Tested: padded uncompressed, padded compressed, unpadded compressed (error)
    and trailing junk in compressed (error)
    
    ===
    
    I have a boot loader that knows how to load files, determine their size,
    and advance to the next 4-byte boundary and reports the total size of the
    files loaded.  It doesn't understand about converting this number to some
    ASCII representation.
    
    With this patch I can embed the contents of a file padded with NULs
    with out knowing the exact size of the file with the following files:
    
    1) file containing cpio header & file name, padded to 4 bytes
    2) contents of file
    3) pad file of zeros, the size at least as large as the that specified
       for the file.
    
    hpa points out that you should be careful with the headers, use unique
    inode numbers and/or add a cpio header with just TRAILER!!!  to reset the
    inode hash table to avoid unwanted hard links.  I just put this sequence as
    the last files loaded.
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    fd604180
initramfs.c 9.93 KB