iPXE
Functions
imgmgmt.h File Reference

Image management. More...

#include <ipxe/image.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int imgdownload (struct uri *uri, unsigned long timeout, struct image **image)
 Download a new image.
int imgdownload_string (const char *uri_string, unsigned long timeout, struct image **image)
 Download a new image.
int imgacquire (const char *name, unsigned long timeout, struct image **image)
 Acquire an image.
void imgstat (struct image *image)
 Display status of an image.

Detailed Description

Image management.

Definition in file imgmgmt.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int imgdownload ( struct uri uri,
unsigned long  timeout,
struct image **  image 
)

Download a new image.

Parameters:
uriURI
timeoutDownload timeout
imageImage to fill in
Return values:
rcReturn status code

Definition at line 51 of file imgmgmt.c.

References alloc_image(), create_downloader(), cwuri, ENOMEM, format_uri_alloc(), uri::fragment, free, image_put(), memcpy(), monojob, monojob_wait(), NULL, uri::password, printf(), uri::query, rc, register_image(), resolve_uri(), strerror(), uri_put(), and uri::user.

Referenced by imgdownload_string(), and uriboot().

                                         {
        struct uri uri_redacted;
        char *uri_string_redacted;
        int rc;

        /* Construct redacted URI */
        memcpy ( &uri_redacted, uri, sizeof ( uri_redacted ) );
        uri_redacted.user = NULL;
        uri_redacted.password = NULL;
        uri_redacted.query = NULL;
        uri_redacted.fragment = NULL;
        uri_string_redacted = format_uri_alloc ( &uri_redacted );
        if ( ! uri_string_redacted ) {
                rc = -ENOMEM;
                goto err_uri_string;
        }

        /* Resolve URI */
        uri = resolve_uri ( cwuri, uri );
        if ( ! uri ) {
                rc = -ENOMEM;
                goto err_resolve_uri;
        }

        /* Allocate image */
        *image = alloc_image ( uri );
        if ( ! *image ) {
                rc = -ENOMEM;
                goto err_alloc_image;
        }

        /* Create downloader */
        if ( ( rc = create_downloader ( &monojob, *image ) ) != 0 ) {
                printf ( "Could not start download: %s\n", strerror ( rc ) );
                goto err_create_downloader;
        }

        /* Wait for download to complete */
        if ( ( rc = monojob_wait ( uri_string_redacted, timeout ) ) != 0 )
                goto err_monojob_wait;

        /* Register image */
        if ( ( rc = register_image ( *image ) ) != 0 ) {
                printf ( "Could not register image: %s\n", strerror ( rc ) );
                goto err_register_image;
        }

 err_register_image:
 err_monojob_wait:
 err_create_downloader:
        image_put ( *image );
 err_alloc_image:
        uri_put ( uri );
 err_resolve_uri:
        free ( uri_string_redacted );
 err_uri_string:
        return rc;
}
int imgdownload_string ( const char *  uri_string,
unsigned long  timeout,
struct image **  image 
)

Download a new image.

Parameters:
uri_stringURI string
timeoutDownload timeout
imageImage to fill in
Return values:
rcReturn status code

Definition at line 119 of file imgmgmt.c.

References ENOMEM, imgdownload(), parse_uri(), rc, and uri_put().

Referenced by comboot_fetch_kernel(), and imgacquire().

                                                {
        struct uri *uri;
        int rc;

        if ( ! ( uri = parse_uri ( uri_string ) ) )
                return -ENOMEM;

        rc = imgdownload ( uri, timeout, image );

        uri_put ( uri );
        return rc;
}
int imgacquire ( const char *  name_uri,
unsigned long  timeout,
struct image **  image 
)

Acquire an image.

Parameters:
name_uriName or URI string
timeoutDownload timeout
imageImage to fill in
Return values:
rcReturn status code

Definition at line 141 of file imgmgmt.c.

References find_image(), and imgdownload_string().

Referenced by cert_exec(), console_exec(), digest_exec(), and imgverify_exec().

                                        {

        /* If we already have an image with the specified name, use it */
        *image = find_image ( name_uri );
        if ( *image )
                return 0;

        /* Otherwise, download a new image */
        return imgdownload_string ( name_uri, timeout, image );
}
void imgstat ( struct image image)

Display status of an image.

Parameters:
imageExecutable/loadable image

Definition at line 158 of file imgmgmt.c.

References image::cmdline, image::flags, IMAGE_AUTO_UNREGISTER, IMAGE_SELECTED, IMAGE_TRUSTED, image::len, image::name, image_type::name, printf(), and image::type.

Referenced by imgstat_exec(), and uriboot().

                                     {
        printf ( "%s : %zd bytes", image->name, image->len );
        if ( image->type )
                printf ( " [%s]", image->type->name );
        if ( image->flags & IMAGE_TRUSTED )
                printf ( " [TRUSTED]" );
        if ( image->flags & IMAGE_SELECTED )
                printf ( " [SELECTED]" );
        if ( image->flags & IMAGE_AUTO_UNREGISTER )
                printf ( " [AUTOFREE]" );
        if ( image->cmdline )
                printf ( " \"%s\"", image->cmdline );
        printf ( "\n" );
}