iPXE
cpio.h File Reference

CPIO archives. More...

#include <stdint.h>
#include <ipxe/image.h>

Go to the source code of this file.

Data Structures

struct  cpio_header
 A CPIO archive header. More...

Macros

#define CPIO_MAGIC   "070701"
 CPIO magic.
#define CPIO_MODE_FILE   0100000
 CPIO type for regular files.
#define CPIO_MODE_DIR   0040000
 CPIO type for directories.
#define CPIO_ALIGN   4
 CPIO header length alignment.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static const char * cpio_name (struct image *image)
 Get CPIO image name.
static size_t cpio_pad_len (size_t len)
 Get CPIO header zero-padding length.
size_t cpio_header (struct image *image, unsigned int index, struct cpio_header *cpio)
 Construct CPIO header for image, if applicable.

Detailed Description

CPIO archives.

Definition in file cpio.h.

Macro Definition Documentation

◆ CPIO_MAGIC

#define CPIO_MAGIC   "070701"

CPIO magic.

Definition at line 53 of file cpio.h.

Referenced by cpio_header().

◆ CPIO_MODE_FILE

#define CPIO_MODE_FILE   0100000

CPIO type for regular files.

Definition at line 56 of file cpio.h.

Referenced by cpio_header().

◆ CPIO_MODE_DIR

#define CPIO_MODE_DIR   0040000

CPIO type for directories.

Definition at line 59 of file cpio.h.

Referenced by cpio_header().

◆ CPIO_ALIGN

#define CPIO_ALIGN   4

CPIO header length alignment.

Definition at line 62 of file cpio.h.

Referenced by cpio_okx(), and cpio_pad_len().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ cpio_name()

const char * cpio_name ( struct image * image)
inlinestatic

Get CPIO image name.

Parameters
imageImage
Return values
nameImage name (not NUL terminated)

Definition at line 71 of file cpio.h.

71 {
72 return image->cmdline;
73}
An executable image.
Definition image.h:24
char * cmdline
Command line to pass to image.
Definition image.h:43

References image::cmdline.

Referenced by cpio_header(), cpio_max(), cpio_name_len(), cpio_okx(), efi_file_read_initrd(), and initrd_load().

◆ cpio_pad_len()

size_t cpio_pad_len ( size_t len)
inlinestatic

Get CPIO header zero-padding length.

Parameters
lenLength of CPIO header (including name, excluding NUL)
Return values
pad_lenPadding length

Definition at line 82 of file cpio.h.

82 {
83
84 /* Pad by at least one byte (for name's terminating NUL) */
85 return ( CPIO_ALIGN - ( len % CPIO_ALIGN ) );
86}
#define CPIO_ALIGN
CPIO header length alignment.
Definition cpio.h:62
ring len
Length.
Definition dwmac.h:226

References CPIO_ALIGN, and len.

Referenced by cpio_okx(), efi_file_read_initrd(), and initrd_load().

◆ cpio_header()

size_t cpio_header ( struct image * image,
unsigned int index,
struct cpio_header * cpio )
extern

Construct CPIO header for image, if applicable.

Parameters
imageImage
indexCPIO header index
cpioCPIO header to fill in
Return values
lenLength of CPIO header (including name, excluding NUL)

Definition at line 156 of file cpio.c.

157 {
158 const char *name = cpio_name ( image );
159 unsigned int mode;
160 unsigned int count;
161 unsigned int max;
162 unsigned int depth;
163 unsigned int i;
164 size_t name_len;
165 size_t len;
166
167 /* Parse command line arguments */
169
170 /* Determine number of CPIO headers to be constructed */
171 max = cpio_max ( image );
172 if ( count > max )
173 count = max;
174
175 /* Determine path depth of this CPIO header */
176 if ( index >= count )
177 return 0;
178 depth = ( max - count + index + 1 );
179
180 /* Get filename length */
181 name_len = cpio_name_len ( image, depth );
182
183 /* Set directory mode or file mode as appropriate */
184 if ( name[name_len] == '/' ) {
186 } else {
188 }
189
190 /* Set length on final header */
191 len = ( ( depth < max ) ? 0 : image->len );
192
193 /* Construct CPIO header */
194 memset ( cpio, '0', sizeof ( *cpio ) );
195 memcpy ( cpio->c_magic, CPIO_MAGIC, sizeof ( cpio->c_magic ) );
196 cpio_set_field ( cpio->c_mode, mode );
197 cpio_set_field ( cpio->c_nlink, 1 );
198 cpio_set_field ( cpio->c_filesize, len );
199 cpio_set_field ( cpio->c_namesize, ( name_len + 1 /* NUL */ ) );
200 DBGC ( image, "CPIO %s %d/%d \"", image->name, depth, max );
201 for ( i = 0 ; i < name_len ; i++ )
202 DBGC ( image, "%c", name[i] );
203 DBGC ( image, "\"\n" );
204 DBGC2_HDA ( image, 0, cpio, sizeof ( *cpio ) );
205
206 /* Calculate total length */
207 return ( sizeof ( *cpio ) + name_len );
208}
long index
Definition bigint.h:65
const char * name
Definition ath9k_hw.c:1986
#define max(x, y)
Definition ath.h:41
static void cpio_parse_cmdline(struct image *image, unsigned int *mode, unsigned int *count)
Parse CPIO image parameters.
Definition cpio.c:116
static size_t cpio_name_len(struct image *image, unsigned int depth)
Get CPIO image filename.
Definition cpio.c:89
static void cpio_set_field(char *field, unsigned long value)
Set field within a CPIO header.
Definition cpio.c:50
static unsigned int cpio_max(struct image *image)
Get maximum number of CPIO headers (i.e.
Definition cpio.c:63
#define CPIO_DEFAULT_DIR_MODE
CPIO directory mode.
Definition cpio.c:42
#define CPIO_MODE_DIR
CPIO type for directories.
Definition cpio.h:59
#define CPIO_MAGIC
CPIO magic.
Definition cpio.h:53
#define CPIO_MODE_FILE
CPIO type for regular files.
Definition cpio.h:56
static const char * cpio_name(struct image *image)
Get CPIO image name.
Definition cpio.h:71
uint16_t mode
Acceleration mode.
Definition ena.h:15
#define DBGC2_HDA(...)
Definition compiler.h:523
#define DBGC(...)
Definition compiler.h:505
static unsigned int count
Number of entries.
Definition dwmac.h:220
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
char c_filesize[8]
Size of data field.
Definition cpio.h:37
char c_mode[8]
File mode and permissions.
Definition cpio.h:27
char c_nlink[8]
Number of links.
Definition cpio.h:33
char c_namesize[8]
Length of filename, including final NUL.
Definition cpio.h:47
char c_magic[6]
The string "070701" or "070702".
Definition cpio.h:23
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:56

References cpio_header::c_filesize, cpio_header::c_magic, cpio_header::c_mode, cpio_header::c_namesize, cpio_header::c_nlink, count, CPIO_DEFAULT_DIR_MODE, CPIO_MAGIC, cpio_max(), CPIO_MODE_DIR, CPIO_MODE_FILE, cpio_name(), cpio_name_len(), cpio_parse_cmdline(), cpio_set_field(), DBGC, DBGC2_HDA, index, image::len, len, max, memcpy(), memset(), mode, image::name, and name.

Referenced by cpio_okx(), efi_file_read_initrd(), and initrd_load().