Skip to content

Commit 5f469c4

Browse files
ddissbrauner
authored andcommitted
init: add initramfs_internal.h
The new header only exports a single unpack function and a CPIO_HDRLEN constant for future test use. Signed-off-by: David Disseldorp <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 2014c95 commit 5f469c4

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

init/initramfs.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/security.h>
2121

2222
#include "do_mounts.h"
23+
#include "initramfs_internal.h"
2324

2425
static __initdata bool csum_present;
2526
static __initdata u32 io_csum;
@@ -256,7 +257,7 @@ static __initdata char *header_buf, *symlink_buf, *name_buf;
256257

257258
static int __init do_start(void)
258259
{
259-
read_into(header_buf, 110, GotHeader);
260+
read_into(header_buf, CPIO_HDRLEN, GotHeader);
260261
return 0;
261262
}
262263

@@ -497,14 +498,23 @@ static unsigned long my_inptr __initdata; /* index of next byte to be processed
497498

498499
#include <linux/decompress/generic.h>
499500

500-
static char * __init unpack_to_rootfs(char *buf, unsigned long len)
501+
/**
502+
* unpack_to_rootfs - decompress and extract an initramfs archive
503+
* @buf: input initramfs archive to extract
504+
* @len: length of initramfs data to process
505+
*
506+
* Returns: NULL for success or an error message string
507+
*
508+
* This symbol shouldn't be used externally. It's available for unit tests.
509+
*/
510+
char * __init unpack_to_rootfs(char *buf, unsigned long len)
501511
{
502512
long written;
503513
decompress_fn decompress;
504514
const char *compress_name;
505515
static __initdata char msg_buf[64];
506516

507-
header_buf = kmalloc(110, GFP_KERNEL);
517+
header_buf = kmalloc(CPIO_HDRLEN, GFP_KERNEL);
508518
symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
509519
name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
510520

init/initramfs_internal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#ifndef __INITRAMFS_INTERNAL_H__
3+
#define __INITRAMFS_INTERNAL_H__
4+
5+
char *unpack_to_rootfs(char *buf, unsigned long len);
6+
#define CPIO_HDRLEN 110
7+
8+
#endif

0 commit comments

Comments
 (0)