From af8cdc72ef58ede31aa2b6e08ca81ec371b789a5 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 21 May 2014 21:21:44 -0500 Subject: [PATCH] wimexport: Add --wimboot flag --- include/wimlib.h | 16 ++++++++++++++++ programs/imagex.c | 23 ++++++++++++++++++----- src/export_image.c | 10 +++++++++- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/include/wimlib.h b/include/wimlib.h index 107c7404..0ac092fd 100644 --- a/include/wimlib.h +++ b/include/wimlib.h @@ -1413,6 +1413,22 @@ typedef int (*wimlib_iterate_lookup_table_callback_t)(const struct wimlib_resour * wimlib_export_image(), with the exception of the call to wimlib_free(). */ #define WIMLIB_EXPORT_FLAG_GIFT 0x00000008 +/** + * Mark each exported image as WIMBoot-compatible. + * + * Note: by itself, this does change the destination WIM's compression type, nor + * does it add the file \Windows\System32\WimBootCompress.ini in the WIM image. + * Before writing the destination WIM, it's recommended to do something like: + * + * \code + * wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_XPRESS); + * wimlib_set_output_chunk_size(wim, 4096); + * wimlib_add_tree(wim, image, L"myconfig.ini", + * L"\\Windows\\System32\\WimBootCompress.ini", 0); + * \endcode + */ +#define WIMLIB_EXPORT_FLAG_WIMBOOT 0x00000010 + /** @} */ /** @ingroup G_extracting_wims * @{ */ diff --git a/programs/imagex.c b/programs/imagex.c index 4979ee32..3501f4c8 100644 --- a/programs/imagex.c +++ b/programs/imagex.c @@ -285,6 +285,7 @@ static const struct option export_options[] = { {T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION}, {T("pipable"), no_argument, NULL, IMAGEX_PIPABLE_OPTION}, {T("not-pipable"), no_argument, NULL, IMAGEX_NOT_PIPABLE_OPTION}, + {T("wimboot"), no_argument, NULL, IMAGEX_WIMBOOT_OPTION}, {NULL, 0, NULL, 0}, }; @@ -2617,6 +2618,9 @@ imagex_export(int argc, tchar **argv, int cmd) case IMAGEX_NOT_PIPABLE_OPTION: write_flags |= WIMLIB_WRITE_FLAG_NOT_PIPABLE; break; + case IMAGEX_WIMBOOT_OPTION: + export_flags |= WIMLIB_EXPORT_FLAG_WIMBOOT; + break; default: goto out_usage; } @@ -2707,11 +2711,13 @@ imagex_export(int argc, tchar **argv, int cmd) if (compression_type == WIMLIB_COMPRESSION_TYPE_INVALID) { /* The user did not specify a compression type; default - * to that of the source WIM, unless --pack-streams or - * --solid was specified. */ + * to that of the source WIM, unless --pack-streams, + * --solid, or --wimboot was specified. */ if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS) compression_type = WIMLIB_COMPRESSION_TYPE_LZMS; + else if (export_flags & WIMLIB_EXPORT_FLAG_WIMBOOT) + compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS; else compression_type = src_info.compression_type; } @@ -2719,10 +2725,17 @@ imagex_export(int argc, tchar **argv, int cmd) if (ret) goto out_free_src_wim; - /* Use same chunk size if compression type is the same. */ - if (compression_type == src_info.compression_type && - chunk_size == UINT32_MAX) + if ((export_flags & WIMLIB_EXPORT_FLAG_WIMBOOT) + && compression_type == WIMLIB_COMPRESSION_TYPE_XPRESS) + { + /* For --wimboot export, use small XPRESS chunks. */ + wimlib_set_output_chunk_size(dest_wim, 4096); + } else if (compression_type == src_info.compression_type && + chunk_size == UINT32_MAX) + { + /* Use same chunk size if compression type is the same. */ wimlib_set_output_chunk_size(dest_wim, src_info.chunk_size); + } } if (chunk_size != UINT32_MAX) { diff --git a/src/export_image.c b/src/export_image.c index 8304ea01..9c25be73 100644 --- a/src/export_image.c +++ b/src/export_image.c @@ -124,7 +124,8 @@ wimlib_export_image(WIMStruct *src_wim, if (export_flags & ~(WIMLIB_EXPORT_FLAG_BOOT | WIMLIB_EXPORT_FLAG_NO_NAMES | WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS | - WIMLIB_EXPORT_FLAG_GIFT)) + WIMLIB_EXPORT_FLAG_GIFT | + WIMLIB_EXPORT_FLAG_WIMBOOT)) return WIMLIB_ERR_INVALID_PARAM; if (src_wim == NULL || dest_wim == NULL) @@ -263,6 +264,13 @@ wimlib_export_image(WIMStruct *src_wim, dest_wim->hdr.boot_idx = dest_wim->hdr.image_count; } + /* Possibly set WIMBoot flag */ + if (export_flags & WIMLIB_EXPORT_FLAG_WIMBOOT) { + wim_info_set_wimboot(dest_wim->wim_info, + dest_wim->hdr.image_count, + true); + } + } /* Set the reparse point fixup flag on the destination WIM if the flag * is set on the source WIM. */ -- 2.43.0