Source
// SPDX-License-Identifier: GPL-2.0-only
/* ----------------------------------------------------------------------- *
*
* Copyright 2012 Intel Corporation; author H. Peter Anvin
*
* ----------------------------------------------------------------------- */
/*
* earlycpio.c
*
* Find a specific cpio member; must precede any compressed content.
* This is used to locate data items in the initramfs used by the
* kernel itself during early boot (before the main initramfs is
* decompressed.) It is the responsibility of the initramfs creator
* to ensure that these items are uncompressed at the head of the
* blob. Depending on the boot loader or package tool that may be a
* separate file or part of the same file.
*/
enum cpio_fields {
C_MAGIC,
C_INO,
C_MODE,
C_UID,
C_GID,
C_NLINK,
C_MTIME,
C_FILESIZE,
C_MAJ,
C_MIN,
C_RMAJ,
C_RMIN,
C_NAMESIZE,
C_CHKSUM,
C_NFIELDS
};
/**
* cpio_data find_cpio_data - Search for files in an uncompressed cpio
* @path: The directory to search for, including a slash at the end
* @data: Pointer to the the cpio archive or a header inside
* @len: Remaining length of the cpio based on data pointer
* @nextoff: When a matching file is found, this is the offset from the
* beginning of the cpio to the beginning of the next file, not the
* matching file itself. It can be used to iterate through the cpio
* to find all files inside of a directory path.
*
* @return: struct cpio_data containing the address, length and
* filename (with the directory path cut off) of the found file.
* If you search for a filename and not for files in a directory,
* pass the absolute path of the filename in the cpio and make sure
* the match returned an empty filename string.
*/
struct cpio_data find_cpio_data(const char *path, void *data,
size_t len, long *nextoff)
{
const size_t cpio_header_len = 8*C_NFIELDS - 2;
struct cpio_data cd = { NULL, 0, "" };