iPXE
Data Structures | Macros | Functions
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. More...
 
#define CPIO_MODE_FILE   0100000
 CPIO type for regular files. More...
 
#define CPIO_MODE_DIR   0040000
 CPIO type for directories. More...
 
#define CPIO_ALIGN   4
 CPIO header length alignment. More...
 

Functions

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

Detailed Description

CPIO archives.

Definition in file cpio.h.

Macro Definition Documentation

◆ CPIO_MAGIC

#define CPIO_MAGIC   "070701"

CPIO magic.

Definition at line 52 of file cpio.h.

◆ CPIO_MODE_FILE

#define CPIO_MODE_FILE   0100000

CPIO type for regular files.

Definition at line 55 of file cpio.h.

◆ CPIO_MODE_DIR

#define CPIO_MODE_DIR   0040000

CPIO type for directories.

Definition at line 58 of file cpio.h.

◆ CPIO_ALIGN

#define CPIO_ALIGN   4

CPIO header length alignment.

Definition at line 61 of file cpio.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ cpio_name()

static const char* cpio_name ( struct image image)
inlinestatic

Get CPIO image name.

Parameters
imageImage
Return values
nameImage name (not NUL terminated)

Definition at line 70 of file cpio.h.

70  {
71  return image->cmdline;
72 }
An executable image.
Definition: image.h:23
char * cmdline
Command line to pass to image.
Definition: image.h:42

References image::cmdline.

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

◆ cpio_pad_len()

static 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 81 of file cpio.h.

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

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 
)

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 155 of file cpio.c.

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

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().