iPXE
Functions
archive.c File Reference

Archive images. More...

#include <string.h>
#include <errno.h>
#include <ipxe/image.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int image_extract (struct image *image, const char *name, struct image **extracted)
 Extract archive image. More...
 
int image_extract_exec (struct image *image)
 Extract and execute image. More...
 
 REQUIRING_SYMBOL (image_extract)
 
 REQUIRE_OBJECT (config_archive)
 

Detailed Description

Archive images.

Definition in file archive.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ image_extract()

int image_extract ( struct image image,
const char *  name,
struct image **  extracted 
)

Extract archive image.

Parameters
imageImage
nameExtracted image name
extractedExtracted image to fill in
Return values
rcReturn status code

Definition at line 44 of file archive.c.

45  {
46  int rc;
47 
48  /* Check that this image can be used to extract an archive image */
49  if ( ! ( image->type && image->type->extract ) ) {
50  rc = -ENOTSUP;
51  goto err_unsupported;
52  }
53 
54  /* Allocate new image */
55  *extracted = alloc_image ( image->uri );
56  if ( ! *extracted ) {
57  rc = -ENOMEM;
58  goto err_alloc;
59  }
60 
61  /* Set image name */
62  if ( ( rc = image_set_name ( *extracted,
63  ( name ? name : image->name ) ) ) != 0 ) {
64  goto err_set_name;
65  }
66 
67  /* Strip any archive or compression suffix from implicit name */
68  if ( ! name )
69  image_strip_suffix ( *extracted );
70 
71  /* Try extracting archive image */
72  if ( ( rc = image->type->extract ( image, *extracted ) ) != 0 ) {
73  DBGC ( image, "IMAGE %s could not extract image: %s\n",
74  image->name, strerror ( rc ) );
75  goto err_extract;
76  }
77 
78  /* Register image */
79  if ( ( rc = register_image ( *extracted ) ) != 0 )
80  goto err_register;
81 
82  /* Propagate trust flag */
83  if ( image->flags & IMAGE_TRUSTED )
84  image_trust ( *extracted );
85 
86  /* Drop local reference to image */
87  image_put ( *extracted );
88 
89  return 0;
90 
91  unregister_image ( *extracted );
92  err_register:
93  err_extract:
94  err_set_name:
95  image_put ( *extracted );
96  err_alloc:
97  err_unsupported:
98  return rc;
99 }
unsigned int flags
Flags.
Definition: image.h:36
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
char * image_strip_suffix(struct image *image)
Strip dot suffix from image name, if present.
Definition: image.c:181
struct image_type * type
Image type, if known.
Definition: image.h:46
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define ENOMEM
Not enough space.
Definition: errno.h:534
int register_image(struct image *image)
Register executable image.
Definition: image.c:286
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int image_set_name(struct image *image, const char *name)
Set image name.
Definition: image.c:160
#define IMAGE_TRUSTED
Image is trusted.
Definition: image.h:67
struct uri * uri
URI of image.
Definition: image.h:32
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:229
int(* extract)(struct image *image, struct image *extracted)
Extract archive image.
Definition: image.h:123
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:322
static void image_trust(struct image *image)
Set image as trusted.
Definition: image.h:247
struct image * alloc_image(struct uri *uri)
Allocate executable image.
Definition: image.c:103
char * name
Name.
Definition: image.h:34

References alloc_image(), DBGC, ENOMEM, ENOTSUP, image_type::extract, image::flags, image_put(), image_set_name(), image_strip_suffix(), image_trust(), IMAGE_TRUSTED, image::name, name, rc, register_image(), strerror(), image::type, unregister_image(), and image::uri.

Referenced by gzip_okx(), image_extract_exec(), imgextract(), and zlib_okx().

◆ image_extract_exec()

int image_extract_exec ( struct image image)

Extract and execute image.

Parameters
imageImage
Return values
rcReturn status code

Definition at line 107 of file archive.c.

107  {
108  struct image *extracted;
109  int rc;
110 
111  /* Extract image */
112  if ( ( rc = image_extract ( image, NULL, &extracted ) ) != 0 )
113  goto err_extract;
114 
115  /* Set image command line */
116  if ( ( rc = image_set_cmdline ( extracted, image->cmdline ) ) != 0 )
117  goto err_set_cmdline;
118 
119  /* Set auto-unregister flag */
120  extracted->flags |= IMAGE_AUTO_UNREGISTER;
121 
122  /* Tail-recurse into extracted image */
123  return image_exec ( extracted );
124 
125  err_set_cmdline:
126  unregister_image ( extracted );
127  err_extract:
128  return rc;
129 }
unsigned int flags
Flags.
Definition: image.h:36
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
An executable image.
Definition: image.h:24
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition: image.h:70
char * cmdline
Command line to pass to image.
Definition: image.h:39
int image_exec(struct image *image)
Execute image.
Definition: image.c:378
int image_extract(struct image *image, const char *name, struct image **extracted)
Extract archive image.
Definition: archive.c:44
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:322
int image_set_cmdline(struct image *image, const char *cmdline)
Set image command line.
Definition: image.c:201
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References image::cmdline, image::flags, IMAGE_AUTO_UNREGISTER, image_exec(), image_extract(), image_set_cmdline(), NULL, rc, and unregister_image().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( image_extract  )

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( config_archive  )