iPXE
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)
 FILE_SECBOOT (PERMITTED)
int image_extract (struct image *image, const char *name, struct image **extracted)
 Extract archive image.
int image_extract_exec (struct image *image)
 Extract and execute image.
 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 )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ 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 45 of file archive.c.

46 {
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 )
70 image_strip_suffix ( *extracted );
71
72 /* Try extracting archive image */
73 if ( ( rc = image->type->extract ( image, *extracted ) ) != 0 ) {
74 DBGC ( image, "IMAGE %s could not extract image: %s\n",
75 image->name, strerror ( rc ) );
76 goto err_extract;
77 }
78
79 /* Register image */
80 if ( ( rc = register_image ( *extracted ) ) != 0 )
81 goto err_register;
82
83 /* Propagate trust flag */
84 if ( image->flags & IMAGE_TRUSTED )
85 image_trust ( *extracted );
86
87 /* Drop local reference to image */
88 image_put ( *extracted );
89
90 return 0;
91
92 unregister_image ( *extracted );
93 err_register:
94 err_extract:
95 err_set_name:
96 image_put ( *extracted );
97 err_alloc:
98 err_unsupported:
99 return rc;
100}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
const char * name
Definition ath9k_hw.c:1986
#define DBGC(...)
Definition compiler.h:505
#define ENOMEM
Not enough space.
Definition errno.h:535
#define ENOTSUP
Operation not supported.
Definition errno.h:590
struct image * alloc_image(struct uri *uri)
Allocate executable image.
Definition image.c:124
char * image_strip_suffix(struct image *image)
Strip dot suffix from image name, if present.
Definition image.c:206
void unregister_image(struct image *image)
Unregister executable image.
Definition image.c:358
int register_image(struct image *image)
Register executable image.
Definition image.c:315
int image_set_name(struct image *image, const char *name)
Set image name.
Definition image.c:181
#define IMAGE_TRUSTED
Image is trusted.
Definition image.h:80
static void image_trust(struct image *image)
Set image as trusted.
Definition image.h:268
static void image_put(struct image *image)
Decrement reference count on an image.
Definition image.h:250
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int(* extract)(struct image *image, struct image *extracted)
Extract archive image.
Definition image.h:142
An executable image.
Definition image.h:24
unsigned int flags
Flags.
Definition image.h:40
struct image_type * type
Image type, if known.
Definition image.h:59
char * name
Name.
Definition image.h:38
struct uri * uri
URI of image.
Definition image.h:32

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(), REQUIRING_SYMBOL(), 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 108 of file archive.c.

108 {
109 struct image *extracted;
110 int rc;
111
112 /* Extract image */
113 if ( ( rc = image_extract ( image, NULL, &extracted ) ) != 0 )
114 goto err_extract;
115
116 /* Set image command line */
117 if ( ( rc = image_set_cmdline ( extracted, image->cmdline ) ) != 0 )
118 goto err_set_cmdline;
119
120 /* Set auto-unregister flag */
121 extracted->flags |= IMAGE_AUTO_UNREGISTER;
122
123 /* Replace current image */
124 if ( ( rc = image_replace ( extracted ) ) != 0 )
125 goto err_replace;
126
127 /* Return to allow replacement image to be executed */
128 return 0;
129
130 err_replace:
131 err_set_cmdline:
132 unregister_image ( extracted );
133 err_extract:
134 return rc;
135}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
int image_extract(struct image *image, const char *name, struct image **extracted)
Extract archive image.
Definition archive.c:45
int image_set_cmdline(struct image *image, const char *cmdline)
Set image command line.
Definition image.c:226
int image_replace(struct image *replacement)
Set replacement image.
Definition image.c:529
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition image.h:83
char * cmdline
Command line to pass to image.
Definition image.h:43

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

Referenced by __image_type().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( image_extract )

References image_extract().

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( config_archive )