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  char *dot;
47  int rc;
48 
49  /* Check that this image can be used to extract an archive image */
50  if ( ! ( image->type && image->type->extract ) ) {
51  rc = -ENOTSUP;
52  goto err_unsupported;
53  }
54 
55  /* Allocate new image */
56  *extracted = alloc_image ( image->uri );
57  if ( ! *extracted ) {
58  rc = -ENOMEM;
59  goto err_alloc;
60  }
61 
62  /* Set image name */
63  if ( ( rc = image_set_name ( *extracted,
64  ( name ? name : image->name ) ) ) != 0 ) {
65  goto err_set_name;
66  }
67 
68  /* Strip any archive or compression suffix from implicit name */
69  if ( ( ! name ) && ( (*extracted)->name ) &&
70  ( ( dot = strrchr ( (*extracted)->name, '.' ) ) != NULL ) ) {
71  *dot = '\0';
72  }
73 
74  /* Try extracting archive image */
75  if ( ( rc = image->type->extract ( image, *extracted ) ) != 0 ) {
76  DBGC ( image, "IMAGE %s could not extract image: %s\n",
77  image->name, strerror ( rc ) );
78  goto err_extract;
79  }
80 
81  /* Register image */
82  if ( ( rc = register_image ( *extracted ) ) != 0 )
83  goto err_register;
84 
85  /* Propagate trust flag */
86  if ( image->flags & IMAGE_TRUSTED )
87  image_trust ( *extracted );
88 
89  /* Drop local reference to image */
90  image_put ( *extracted );
91 
92  return 0;
93 
94  unregister_image ( *extracted );
95  err_register:
96  err_extract:
97  err_set_name:
98  image_put ( *extracted );
99  err_alloc:
100  err_unsupported:
101  return rc;
102 }
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 * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition: string.c:289
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:264
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:157
#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:228
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:300
static void image_trust(struct image *image)
Set image as trusted.
Definition: image.h:246
struct image * alloc_image(struct uri *uri)
Allocate executable image.
Definition: image.c:103
char * name
Name.
Definition: image.h:34
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References alloc_image(), DBGC, ENOMEM, ENOTSUP, image_type::extract, image::flags, image_put(), image_set_name(), image_trust(), IMAGE_TRUSTED, image::name, name, NULL, rc, register_image(), strerror(), strrchr(), 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 110 of file archive.c.

110  {
111  struct image *extracted;
112  int rc;
113 
114  /* Extract image */
115  if ( ( rc = image_extract ( image, NULL, &extracted ) ) != 0 )
116  goto err_extract;
117 
118  /* Set image command line */
119  if ( ( rc = image_set_cmdline ( extracted, image->cmdline ) ) != 0 )
120  goto err_set_cmdline;
121 
122  /* Set auto-unregister flag */
123  extracted->flags |= IMAGE_AUTO_UNREGISTER;
124 
125  /* Tail-recurse into extracted image */
126  return image_exec ( extracted );
127 
128  err_set_cmdline:
129  unregister_image ( extracted );
130  err_extract:
131  return rc;
132 }
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:356
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:300
int image_set_cmdline(struct image *image, const char *cmdline)
Set image command line.
Definition: image.c:179
#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  )