iPXE
Data Structures | Functions
zlib.h File Reference

zlib compressed images More...

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

Go to the source code of this file.

Data Structures

union  zlib_magic
 zlib magic header More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int zlib_magic_is_valid (union zlib_magic *magic)
 Check that zlib magic header is valid. More...
 
int zlib_deflate (enum deflate_format format, struct deflate_chunk *in, struct image *extracted)
 Extract compressed data to image. More...
 
struct image_type zlib_image_type __image_type (PROBE_NORMAL)
 

Detailed Description

zlib compressed images

Definition in file zlib.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ zlib_magic_is_valid()

static int zlib_magic_is_valid ( union zlib_magic magic)
inlinestatic

Check that zlib magic header is valid.

Parameters
magicMagic header
Return values
is_validMagic header is valid

Definition at line 31 of file zlib.h.

31  {
32 
33  /* Check magic value as per RFC 6713 */
34  return ( ( ( magic->cmf & 0x8f ) == 0x08 ) &&
35  ( ( be16_to_cpu ( magic->check ) % 31 ) == 0 ) );
36 }
uint32_t magic
Magic signature.
Definition: fdt.h:12
#define be16_to_cpu(value)
Definition: byteswap.h:115

References be16_to_cpu, and magic.

Referenced by zlib_probe().

◆ zlib_deflate()

int zlib_deflate ( enum deflate_format  format,
struct deflate_chunk in,
struct image extracted 
)

Extract compressed data to image.

Parameters
formatCompression format code
inCompressed input chunk
extractedExtracted image
Return values
rcReturn status code

Definition at line 48 of file zlib.c.

49  {
50  struct deflate *deflate;
51  struct deflate_chunk out;
52  int rc;
53 
54  /* Allocate and initialise decompressor */
55  deflate = zalloc ( sizeof ( *deflate ) );
56  if ( ! deflate ) {
57  rc = -ENOMEM;
58  goto err_alloc;
59  }
60 
61  /* Decompress data, (re)allocating if necessary */
62  while ( 1 ) {
63 
64  /* (Re)initialise decompressor */
66 
67  /* (Re)initialise input chunk */
68  in->offset = 0;
69 
70  /* Initialise output chunk */
71  deflate_chunk_init ( &out, extracted->data, 0, extracted->len );
72 
73  /* Decompress data */
74  if ( ( rc = deflate_inflate ( deflate, in, &out ) ) != 0 ) {
75  DBGC ( extracted, "ZLIB %p could not decompress: %s\n",
76  extracted, strerror ( rc ) );
77  goto err_inflate;
78  }
79 
80  /* Check that decompression is valid */
81  if ( ! deflate_finished ( deflate ) ) {
82  DBGC ( extracted, "ZLIB %p decompression incomplete\n",
83  extracted );
84  rc = -EINVAL;
85  goto err_unfinished;
86  }
87 
88  /* Finish if output image size was correct */
89  if ( out.offset == extracted->len )
90  break;
91 
92  /* Otherwise, resize output image and retry */
93  if ( ( rc = image_set_len ( extracted, out.offset ) ) != 0 ) {
94  DBGC ( extracted, "ZLIB %p could not resize: %s\n",
95  extracted, strerror ( rc ) );
96  goto err_set_size;
97  }
98  }
99 
100  /* Success */
101  rc = 0;
102 
103  err_set_size:
104  err_unfinished:
105  err_inflate:
106  free ( deflate );
107  err_alloc:
108  return rc;
109 }
int deflate_inflate(struct deflate *deflate, struct deflate_chunk *in, struct deflate_chunk *out)
Inflate compressed data.
Definition: deflate.c:492
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
userptr_t data
Raw file image.
Definition: image.h:41
__be32 in[4]
Definition: CIB_PRM.h:35
#define DBGC(...)
Definition: compiler.h:505
__be32 out[4]
Definition: CIB_PRM.h:36
#define ENOMEM
Not enough space.
Definition: errno.h:534
A chunk of data.
Definition: deflate.h:241
void deflate_init(struct deflate *deflate, enum deflate_format format)
Initialise decompressor.
Definition: deflate.c:999
static int deflate_finished(struct deflate *deflate)
Check if decompression has finished.
Definition: deflate.h:273
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
size_t len
Length of raw file image.
Definition: image.h:43
int image_set_len(struct image *image, size_t len)
Set image length.
Definition: image.c:201
int const char * format
Definition: xfer.h:104
Decompressor.
Definition: deflate.h:156

References image::data, DBGC, deflate_finished(), deflate_inflate(), deflate_init(), EINVAL, ENOMEM, format, free, image_set_len(), in, image::len, out, rc, strerror(), and zalloc().

Referenced by gzip_extract(), and zlib_extract().

◆ __image_type()

struct image_type zlib_image_type __image_type ( PROBE_NORMAL  )