[image] Allow download progress messages to be silenced

Add a "--quiet" option to each image-acquiring command that currently
accepts a "--timeout" option, to allow the displaying of the download
URI and the progress dots to be inhibited.

This is particularly useful with "data:" URIs to inhibit the echoing
of the full data URI contents:

    iPXE> imgfetch -n hw data:,hello%20world
    data:,hello%20world... ok
    iPXE>

vs.

    iPXE> imgfetch -q -n hw data:,hello%20world
    iPXE>

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2026-07-17 11:58:52 +01:00
parent e30422e49f
commit 9d6b3600ce
15 changed files with 81 additions and 44 deletions
@@ -181,7 +181,7 @@ static int comboot_fetch_kernel ( const char *kernel_file, char *cmdline ) {
DBG ( "COMBOOT: fetching initrd '%s'\n", initrd_file );
/* Fetch initrd */
if ( ( rc = imgdownload_string ( initrd_file, 0,
if ( ( rc = imgdownload_string ( initrd_file, 0, 0,
&initrd ) ) != 0 ) {
DBG ( "COMBOOT: could not fetch initrd: %s\n",
strerror ( rc ) );
@@ -196,7 +196,7 @@ static int comboot_fetch_kernel ( const char *kernel_file, char *cmdline ) {
DBG ( "COMBOOT: fetching kernel '%s'\n", kernel_file );
/* Fetch kernel */
if ( ( rc = imgdownload_string ( kernel_file, 0, &kernel ) ) != 0 ) {
if ( ( rc = imgdownload_string ( kernel_file, 0, 0, &kernel ) ) != 0 ){
DBG ( "COMBOOT: could not fetch kernel: %s\n",
strerror ( rc ) );
return rc;
+1 -1
View File
@@ -124,7 +124,7 @@ static int cert_exec ( int argc, char **argv,
/* Acquire image, if applicable */
if ( ( optind < argc ) &&
( ( rc = imgacquire ( argv[optind], 0, &image ) ) != 0 ) )
( ( rc = imgacquire ( argv[optind], 0, 0, &image ) ) != 0 ) )
goto err_acquire;
/* Get first entry in certificate store */
+1 -1
View File
@@ -97,7 +97,7 @@ static int console_exec ( int argc, char **argv ) {
if ( opts.picture ) {
/* Acquire image */
if ( ( rc = imgacquire ( opts.picture, 0, &image ) ) != 0 )
if ( ( rc = imgacquire ( opts.picture, 0, 0, &image ) ) != 0 )
goto err_acquire;
/* Convert to pixel buffer */
+1 -1
View File
@@ -86,7 +86,7 @@ int digest_exec ( int argc, char **argv, struct digest_algorithm *digest ) {
for ( i = optind ; i < argc ; i++ ) {
/* Acquire image */
if ( ( rc = imgacquire ( argv[i], 0, &image ) ) != 0 )
if ( ( rc = imgacquire ( argv[i], 0, 0, &image ) ) != 0 )
return rc;
/* Calculate digest */
+5 -1
View File
@@ -40,12 +40,16 @@ FILE_SECBOOT ( PERMITTED );
struct fdt_options {
/** Download timeout */
unsigned long timeout;
/** Display only error messages */
int quiet;
};
/** "fdt" option list */
static struct option_descriptor fdt_opts[] = {
OPTION_DESC ( "timeout", 't', required_argument,
struct fdt_options, timeout, parse_timeout ),
OPTION_DESC ( "quiet", 'q', no_argument,
struct fdt_options, quiet, parse_flag ),
};
/** "fdt" command descriptor */
@@ -74,7 +78,7 @@ static int fdt_exec ( int argc, char **argv ) {
/* Acquire image, if applicable */
if ( name_uri && ( ( rc = imgacquire ( name_uri, opts.timeout,
&image ) ) != 0 ) ) {
opts.quiet, &image ) ) != 0 ) ){
goto err_image;
}
+6 -1
View File
@@ -44,6 +44,8 @@ struct imgextract_options {
int keep;
/** Download timeout */
unsigned long timeout;
/** Display only error messages */
int quiet;
};
/** "imgextract" option list */
@@ -54,6 +56,8 @@ static struct option_descriptor imgextract_opts[] = {
struct imgextract_options, keep, parse_flag ),
OPTION_DESC ( "timeout", 't', required_argument,
struct imgextract_options, timeout, parse_timeout ),
OPTION_DESC ( "quiet", 'q', no_argument,
struct imgextract_options, quiet, parse_flag ),
};
/** "imgextract" command descriptor */
@@ -78,7 +82,8 @@ static int imgextract_exec ( int argc, char **argv ) {
goto err_parse;
/* Acquire image */
if ( ( rc = imgacquire ( argv[optind], opts.timeout, &image ) ) != 0 )
if ( ( rc = imgacquire ( argv[optind], opts.timeout, opts.quiet,
&image ) ) != 0 )
goto err_acquire;
/* Extract archive image */
+10 -6
View File
@@ -48,6 +48,8 @@ struct imgsingle_options {
char *name;
/** Download timeout */
unsigned long timeout;
/** Display only error messages */
int quiet;
/** Replace image */
int replace;
/** Free image after execution */
@@ -56,18 +58,20 @@ struct imgsingle_options {
/** "img{single}" option list */
static union {
/* "imgexec" takes all three options */
struct option_descriptor imgexec[4];
/* Other "img{single}" commands take only --name, --timeout,
/* "imgexec" takes all five options */
struct option_descriptor imgexec[5];
/* Other "img{single}" commands take only --name, --timeout, --quiet,
* and --autofree
*/
struct option_descriptor imgsingle[3];
struct option_descriptor imgsingle[4];
} opts = {
.imgexec = {
OPTION_DESC ( "name", 'n', required_argument,
struct imgsingle_options, name, parse_string ),
OPTION_DESC ( "timeout", 't', required_argument,
struct imgsingle_options, timeout, parse_timeout),
OPTION_DESC ( "quiet", 'q', no_argument,
struct imgsingle_options, quiet, parse_flag ),
OPTION_DESC ( "autofree", 'a', no_argument,
struct imgsingle_options, autofree, parse_flag ),
OPTION_DESC ( "replace", 'r', no_argument,
@@ -80,7 +84,7 @@ struct imgsingle_descriptor {
/** Command descriptor */
struct command_descriptor *cmd;
/** Function to use to acquire the image */
int ( * acquire ) ( const char *name, unsigned long timeout,
int ( * acquire ) ( const char *name, unsigned long timeout, int quiet,
struct image **image );
/** Pre-action to take upon image, or NULL */
void ( * preaction ) ( struct image *image );
@@ -127,7 +131,7 @@ static int imgsingle_exec ( int argc, char **argv,
/* Acquire the image */
if ( name_uri ) {
if ( ( rc = desc->acquire ( name_uri, opts.timeout,
if ( ( rc = desc->acquire ( name_uri, opts.timeout, opts.quiet,
&image ) ) != 0 )
goto err_acquire;
} else {
+8 -3
View File
@@ -47,6 +47,8 @@ struct imgdecrypt_options {
int keep;
/** Download timeout */
unsigned long timeout;
/** Display only error messages */
int quiet;
};
/** "imgdecrypt" option list */
@@ -56,7 +58,9 @@ static struct option_descriptor imgdecrypt_opts[] = {
OPTION_DESC ( "keep", 'k', no_argument,
struct imgdecrypt_options, keep, parse_flag ),
OPTION_DESC ( "timeout", 't', required_argument,
struct imgdecrypt_options, timeout, parse_timeout),
struct imgdecrypt_options, timeout, parse_timeout ),
OPTION_DESC ( "quiet", 'q', no_argument,
struct imgdecrypt_options, quiet, parse_flag ),
};
/** "imgdecrypt" command descriptor */
@@ -90,11 +94,12 @@ static int imgdecrypt_exec ( int argc, char **argv ) {
envelope_name_uri = argv[ optind + 1 ];
/* Acquire the image */
if ( ( rc = imgacquire ( image_name_uri, opts.timeout, &image ) ) != 0 )
if ( ( rc = imgacquire ( image_name_uri, opts.timeout, opts.quiet,
&image ) ) != 0 )
goto err_acquire_image;
/* Acquire the envelope image */
if ( ( rc = imgacquire ( envelope_name_uri, opts.timeout,
if ( ( rc = imgacquire ( envelope_name_uri, opts.timeout, opts.quiet,
&envelope ) ) != 0 )
goto err_acquire_envelope;
+6 -1
View File
@@ -44,6 +44,8 @@ struct imgset_options {
int keep;
/** Download timeout */
unsigned long timeout;
/** Display only error messages */
int quiet;
};
/** "imgset" option list */
@@ -52,6 +54,8 @@ static struct option_descriptor imgset_opts[] = {
struct imgset_options, keep, parse_flag ),
OPTION_DESC ( "timeout", 't', required_argument,
struct imgset_options, timeout, parse_timeout ),
OPTION_DESC ( "quiet", 'q', no_argument,
struct imgset_options, quiet, parse_flag ),
};
/** "imgset" command descriptor */
@@ -81,7 +85,8 @@ static int imgset_exec ( int argc, char **argv ) {
goto err_setting;
/* Acquire image */
if ( ( rc = imgacquire ( argv[optind], opts.timeout, &image ) ) != 0 )
if ( ( rc = imgacquire ( argv[optind], opts.timeout, opts.quiet,
&image ) ) != 0 )
goto err_acquire;
/* Store setting value */
+7 -2
View File
@@ -94,6 +94,8 @@ struct imgverify_options {
int keep;
/** Download timeout */
unsigned long timeout;
/** Display only error messages */
int quiet;
};
/** "imgverify" option list */
@@ -104,6 +106,8 @@ static struct option_descriptor imgverify_opts[] = {
struct imgverify_options, keep, parse_flag ),
OPTION_DESC ( "timeout", 't', required_argument,
struct imgverify_options, timeout, parse_timeout),
OPTION_DESC ( "quiet", 'q', no_argument,
struct imgverify_options, quiet, parse_flag ),
};
/** "imgverify" command descriptor */
@@ -137,11 +141,12 @@ static int imgverify_exec ( int argc, char **argv ) {
signature_name_uri = argv[ optind + 1 ];
/* Acquire the image */
if ( ( rc = imgacquire ( image_name_uri, opts.timeout, &image ) ) != 0 )
if ( ( rc = imgacquire ( image_name_uri, opts.timeout, opts.quiet,
&image ) ) != 0 )
goto err_acquire_image;
/* Acquire the signature image */
if ( ( rc = imgacquire ( signature_name_uri, opts.timeout,
if ( ( rc = imgacquire ( signature_name_uri, opts.timeout, opts.quiet,
&signature ) ) != 0 )
goto err_acquire_signature;
+5 -1
View File
@@ -48,6 +48,8 @@ FILE_SECBOOT ( PERMITTED );
struct shim_options {
/** Download timeout */
unsigned long timeout;
/** Display only error messages */
int quiet;
/** Require third party loader */
int require_loader;
/** Allow PXE base code protocol */
@@ -60,6 +62,8 @@ struct shim_options {
static struct option_descriptor shim_opts[] = {
OPTION_DESC ( "timeout", 't', required_argument,
struct shim_options, timeout, parse_timeout ),
OPTION_DESC ( "quiet", 'q', no_argument,
struct shim_options, quiet, parse_flag ),
OPTION_DESC ( "require-loader", 'l', no_argument,
struct shim_options, require_loader, parse_flag ),
OPTION_DESC ( "allow-pxe", 'p', no_argument,
@@ -106,7 +110,7 @@ static int shim_exec ( int argc, char **argv ) {
/* Acquire image, if applicable */
if ( download && name_uri &&
( ( rc = imgacquire ( name_uri, opts.timeout,
( ( rc = imgacquire ( name_uri, opts.timeout, opts.quiet,
&image ) ) != 0 ) ) {
goto err_image;
}
+3 -3
View File
@@ -12,11 +12,11 @@ FILE_SECBOOT ( PERMITTED );
#include <ipxe/image.h>
extern int imgdownload ( struct uri *uri, unsigned long timeout,
extern int imgdownload ( struct uri *uri, unsigned long timeout, int quiet,
struct image **image );
extern int imgdownload_string ( const char *uri_string, unsigned long timeout,
struct image **image );
extern int imgacquire ( const char *name, unsigned long timeout,
int quiet, struct image **image );
extern int imgacquire ( const char *name, unsigned long timeout, int quiet,
struct image **image );
extern void imgstat ( struct image *image );
extern int imgmem ( const char *name, const void *data, size_t len );
+4 -4
View File
@@ -86,12 +86,12 @@ static int efi_autoexec_filesystem ( EFI_HANDLE handle, struct image **image ) {
/* Try loading from loaded image directory, if supported */
if ( ( rc = imgacquire ( "file:" EFI_AUTOEXEC_NAME,
EFI_AUTOEXEC_TIMEOUT, image ) ) == 0 )
EFI_AUTOEXEC_TIMEOUT, 0, image ) ) == 0 )
return 0;
/* Try loading from root directory, if supported */
if ( ( rc = imgacquire ( "file:/" EFI_AUTOEXEC_NAME,
EFI_AUTOEXEC_TIMEOUT, image ) ) == 0 )
EFI_AUTOEXEC_TIMEOUT, 0, image ) ) == 0 )
return 0;
return rc;
@@ -133,9 +133,9 @@ static int efi_autoexec_network ( EFI_HANDLE handle, struct image **image ) {
/* Attempt download from current working URI, then from root */
if ( ( ( rc = imgacquire ( EFI_AUTOEXEC_NAME, EFI_AUTOEXEC_TIMEOUT,
image ) ) != 0 ) &&
0, image ) ) != 0 ) &&
( ( rc = imgacquire ( "/" EFI_AUTOEXEC_NAME, EFI_AUTOEXEC_TIMEOUT,
image ) ) != 0 ) ) {
0, image ) ) != 0 ) ) {
DBGC ( device, "EFI %s could not download [/]%s: %s\n",
efi_handle_name ( device ), EFI_AUTOEXEC_NAME,
strerror ( rc ) );
+1 -1
View File
@@ -162,7 +162,7 @@ int uriboot ( struct uri *filename, struct uri **root_paths,
/* Attempt filename boot if applicable */
if ( filename ) {
if ( ( rc = imgdownload ( filename, 0, &image ) ) != 0 )
if ( ( rc = imgdownload ( filename, 0, 0, &image ) ) != 0 )
goto err_download;
imgstat ( image );
image->flags |= IMAGE_AUTO_UNREGISTER;
+21 -16
View File
@@ -47,25 +47,28 @@ FILE_SECBOOT ( PERMITTED );
*
* @v uri URI
* @v timeout Download timeout
* @v quiet Display only error messages
* @v image Image to fill in
* @ret rc Return status code
*/
int imgdownload ( struct uri *uri, unsigned long timeout,
int imgdownload ( struct uri *uri, unsigned long timeout, int quiet,
struct image **image ) {
char *uri_string_redacted = NULL;
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.equery = NULL;
uri_redacted.efragment = NULL;
uri_string_redacted = format_uri_alloc ( &uri_redacted );
if ( ! uri_string_redacted ) {
rc = -ENOMEM;
goto err_uri_string;
/* Construct redacted URI, if applicable */
if ( ! quiet ) {
memcpy ( &uri_redacted, uri, sizeof ( uri_redacted ) );
uri_redacted.user = NULL;
uri_redacted.password = NULL;
uri_redacted.equery = NULL;
uri_redacted.efragment = NULL;
uri_string_redacted = format_uri_alloc ( &uri_redacted );
if ( ! uri_string_redacted ) {
rc = -ENOMEM;
goto err_uri_string;
}
}
/* Resolve URI */
@@ -115,18 +118,19 @@ int imgdownload ( struct uri *uri, unsigned long timeout,
*
* @v uri_string URI string
* @v timeout Download timeout
* @v quiet Display only error messages
* @v image Image to fill in
* @ret rc Return status code
*/
int imgdownload_string ( const char *uri_string, unsigned long timeout,
struct image **image ) {
int quiet, struct image **image ) {
struct uri *uri;
int rc;
if ( ! ( uri = parse_uri ( uri_string ) ) )
return -ENOMEM;
rc = imgdownload ( uri, timeout, image );
rc = imgdownload ( uri, timeout, quiet, image );
uri_put ( uri );
return rc;
@@ -137,10 +141,11 @@ int imgdownload_string ( const char *uri_string, unsigned long timeout,
*
* @v name_uri Name or URI string
* @v timeout Download timeout
* @v quiet Display only error messages
* @v image Image to fill in
* @ret rc Return status code
*/
int imgacquire ( const char *name_uri, unsigned long timeout,
int imgacquire ( const char *name_uri, unsigned long timeout, int quiet,
struct image **image ) {
/* If we already have an image with the specified name, use it */
@@ -149,7 +154,7 @@ int imgacquire ( const char *name_uri, unsigned long timeout,
return 0;
/* Otherwise, download a new image */
return imgdownload_string ( name_uri, timeout, image );
return imgdownload_string ( name_uri, timeout, quiet, image );
}
/**