Commit 7c184ecd authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

initramfs: factor out a helper to populate the initrd image

This will allow for cleaner code sharing in the caller.

Link: http://lkml.kernel.org/r/20190213174621.29297-5-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarMike Rapoport <rppt@linux.ibm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>	[arm64]
Cc: Geert Uytterhoeven <geert@linux-m68k.org>	[m68k]
Cc: Steven Price <steven.price@arm.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Guan Xuetao <gxt@pku.edu.cn>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 23091e28
...@@ -597,6 +597,28 @@ static void __init clean_rootfs(void) ...@@ -597,6 +597,28 @@ static void __init clean_rootfs(void)
} }
#endif #endif
#ifdef CONFIG_BLK_DEV_RAM
static void populate_initrd_image(char *err)
{
ssize_t written;
int fd;
unpack_to_rootfs(__initramfs_start, __initramfs_size);
printk(KERN_INFO "rootfs image is not initramfs (%s); looks like an initrd\n",
err);
fd = ksys_open("/initrd.image", O_WRONLY | O_CREAT, 0700);
if (fd < 0)
return;
written = xwrite(fd, (char *)initrd_start, initrd_end - initrd_start);
if (written != initrd_end - initrd_start)
pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
written, initrd_end - initrd_start);
ksys_close(fd);
}
#endif /* CONFIG_BLK_DEV_RAM */
static int __init populate_rootfs(void) static int __init populate_rootfs(void)
{ {
/* Load the built in initramfs */ /* Load the built in initramfs */
...@@ -606,7 +628,6 @@ static int __init populate_rootfs(void) ...@@ -606,7 +628,6 @@ static int __init populate_rootfs(void)
/* If available load the bootloader supplied initrd */ /* If available load the bootloader supplied initrd */
if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) { if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) {
#ifdef CONFIG_BLK_DEV_RAM #ifdef CONFIG_BLK_DEV_RAM
int fd;
printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
err = unpack_to_rootfs((char *)initrd_start, err = unpack_to_rootfs((char *)initrd_start,
initrd_end - initrd_start); initrd_end - initrd_start);
...@@ -614,22 +635,7 @@ static int __init populate_rootfs(void) ...@@ -614,22 +635,7 @@ static int __init populate_rootfs(void)
goto done; goto done;
clean_rootfs(); clean_rootfs();
unpack_to_rootfs(__initramfs_start, __initramfs_size); populate_initrd_image(err);
printk(KERN_INFO "rootfs image is not initramfs (%s)"
"; looks like an initrd\n", err);
fd = ksys_open("/initrd.image",
O_WRONLY|O_CREAT, 0700);
if (fd >= 0) {
ssize_t written = xwrite(fd, (char *)initrd_start,
initrd_end - initrd_start);
if (written != initrd_end - initrd_start)
pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
written, initrd_end - initrd_start);
ksys_close(fd);
}
done: done:
/* empty statement */; /* empty statement */;
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment