]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
Win32: compile
[wimlib] / programs / imagex.c
index 2fc1b9d754ea77a5865b037577e5375b37c88381..c3187f74f94341a4b3bf089c134cde7c31a0c00c 100644 (file)
@@ -120,6 +120,7 @@ enum {
        IMAGEX_ALLOW_OTHER_OPTION,
        IMAGEX_BOOT_OPTION,
        IMAGEX_CHECK_OPTION,
+       IMAGEX_CHUNK_SIZE_OPTION,
        IMAGEX_COMMAND_OPTION,
        IMAGEX_COMMIT_OPTION,
        IMAGEX_COMPRESS_OPTION,
@@ -190,6 +191,7 @@ static const struct option capture_or_append_options[] = {
        {T("nocheck"),     no_argument,       NULL, IMAGEX_NOCHECK_OPTION},
        {T("compress"),    required_argument, NULL, IMAGEX_COMPRESS_OPTION},
        {T("compress-slow"), no_argument,     NULL, IMAGEX_COMPRESS_SLOW_OPTION},
+       {T("chunk-size"),  required_argument, NULL, IMAGEX_CHUNK_SIZE_OPTION},
        {T("config"),      required_argument, NULL, IMAGEX_CONFIG_OPTION},
        {T("dereference"), no_argument,       NULL, IMAGEX_DEREFERENCE_OPTION},
        {T("flags"),       required_argument, NULL, IMAGEX_FLAGS_OPTION},
@@ -282,8 +284,11 @@ static const struct option optimize_options[] = {
        {T("check"),       no_argument,       NULL, IMAGEX_CHECK_OPTION},
        {T("nocheck"),     no_argument,       NULL, IMAGEX_NOCHECK_OPTION},
        {T("no-check"),    no_argument,       NULL, IMAGEX_NOCHECK_OPTION},
+       {T("compress"),    required_argument, NULL, IMAGEX_COMPRESS_OPTION},
        {T("recompress"),  no_argument,       NULL, IMAGEX_RECOMPRESS_OPTION},
        {T("compress-slow"), no_argument,     NULL, IMAGEX_COMPRESS_SLOW_OPTION},
+       {T("recompress-slow"), no_argument,     NULL, IMAGEX_COMPRESS_SLOW_OPTION},
+       {T("chunk-size"),  required_argument, NULL, IMAGEX_CHUNK_SIZE_OPTION},
        {T("threads"),     required_argument, NULL, IMAGEX_THREADS_OPTION},
        {T("pipable"),     no_argument,       NULL, IMAGEX_PIPABLE_OPTION},
        {T("not-pipable"), no_argument,       NULL, IMAGEX_NOT_PIPABLE_OPTION},
@@ -418,9 +423,10 @@ get_compression_type(const tchar *optarg)
        }
 }
 
-static void
+static int
 set_compress_slow(void)
 {
+       int ret;
        static const struct wimlib_lzx_params slow_params = {
                .size_of_this = sizeof(struct wimlib_lzx_params),
                .algorithm = WIMLIB_LZX_ALGORITHM_SLOW,
@@ -437,8 +443,10 @@ set_compress_slow(void)
                        },
                },
        };
-       if (wimlib_lzx_set_default_params(&slow_params))
+       ret = wimlib_lzx_set_default_params(&slow_params);
+       if (ret)
                imagex_error(T("Couldn't set slow compression parameters.!"));
+       return ret;
 }
 
 struct string_set {
@@ -1268,6 +1276,19 @@ parse_num_threads(const tchar *optarg)
        }
 }
 
+static uint32_t parse_chunk_size(const tchar *optarg)
+{
+       tchar *tmp;
+       unsigned long chunk_size = tstrtoul(optarg, &tmp, 10);
+       if (chunk_size >= UINT32_MAX || *tmp || tmp == optarg) {
+               imagex_error(T("Chunk size must be a non-negative integer!"));
+               return UINT32_MAX;
+       } else {
+               return chunk_size;
+       }
+}
+
+
 /*
  * Parse an option passed to an update command.
  *
@@ -1666,6 +1687,7 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                              WIMLIB_ADD_IMAGE_FLAG_WINCONFIG;
        int write_flags = 0;
        int compression_type = WIMLIB_COMPRESSION_TYPE_INVALID;
+       uint32_t chunk_size = UINT32_MAX;
        const tchar *wimfile;
        int wim_fd;
        const tchar *name;
@@ -1721,7 +1743,15 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                                goto out_err;
                        break;
                case IMAGEX_COMPRESS_SLOW_OPTION:
-                       set_compress_slow();
+                       ret = set_compress_slow();
+                       if (ret)
+                               goto out_err;
+                       compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
+                       break;
+               case IMAGEX_CHUNK_SIZE_OPTION:
+                       chunk_size = parse_chunk_size(optarg);
+                       if (chunk_size == UINT32_MAX)
+                               goto out_err;
                        break;
                case IMAGEX_FLAGS_OPTION:
                        flags_element = optarg;
@@ -1953,6 +1983,13 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
        if (ret)
                goto out_free_config;
 
+       /* Set chunk size if non-default.  */
+       if (chunk_size != UINT32_MAX) {
+               ret = wimlib_set_output_chunk_size(wim, chunk_size);
+               if (ret)
+                       goto out_free_wim;
+       }
+
 #ifndef __WIN32__
        /* Detect if source is regular file or block device and set NTFS volume
         * capture mode.  */
@@ -2478,6 +2515,8 @@ imagex_export(int argc, tchar **argv, int cmd)
                ret = wimlib_create_new_wim(compression_type, &dest_wim);
                if (ret)
                        goto out_free_src_wim;
+
+               wimlib_set_output_chunk_size(dest_wim, src_info.chunk_size);
        }
 
        image = wimlib_resolve_image(src_wim, src_image_num_or_name);
@@ -2737,6 +2776,8 @@ print_wim_information(const tchar *wimfile, const struct wimlib_wim_info *info)
        tprintf(T("Image Count:    %d\n"), info->image_count);
        tprintf(T("Compression:    %"TS"\n"),
                wimlib_get_compression_type_string(info->compression_type));
+       tprintf(T("Chunk Size:     %"PRIu32" bytes\n"),
+               info->chunk_size);
        tprintf(T("Part Number:    %d/%d\n"), info->part_number, info->total_parts);
        tprintf(T("Boot Index:     %d\n"), info->boot_index);
        tprintf(T("Size:           %"PRIu64" bytes\n"), info->total_bytes);
@@ -2753,25 +2794,37 @@ static int
 print_resource(const struct wimlib_resource_entry *resource,
               void *_ignore)
 {
-
-       tprintf(T("Uncompressed size   = %"PRIu64" bytes\n"),
+       tprintf(T("Uncompressed size     = %"PRIu64" bytes\n"),
                resource->uncompressed_size);
+       if (resource->is_partial) {
+               tprintf(T("Raw uncompressed size = %"PRIu64" bytes\n"),
+                       resource->raw_resource_uncompressed_size);
+
+               tprintf(T("Raw compressed size   = %"PRIu64" bytes\n"),
+                       resource->raw_resource_compressed_size);
+
+               tprintf(T("Raw offset in WIM     = %"PRIu64" bytes\n"),
+                       resource->raw_resource_offset_in_wim);
 
-       tprintf(T("Compressed size     = %"PRIu64" bytes\n"),
-               resource->compressed_size);
+               tprintf(T("Offset in raw         = %"PRIu64" bytes\n"),
+                       resource->offset);
+       } else {
+               tprintf(T("Compressed size       = %"PRIu64" bytes\n"),
+                       resource->compressed_size);
 
-       tprintf(T("Offset              = %"PRIu64" bytes\n"),
-               resource->offset);
+               tprintf(T("Offset in WIM         = %"PRIu64" bytes\n"),
+                       resource->offset);
+       }
 
 
-       tprintf(T("Part Number         = %u\n"), resource->part_number);
-       tprintf(T("Reference Count     = %u\n"), resource->reference_count);
+       tprintf(T("Part Number           = %u\n"), resource->part_number);
+       tprintf(T("Reference Count       = %u\n"), resource->reference_count);
 
-       tprintf(T("Hash                = 0x"));
+       tprintf(T("Hash                  = 0x"));
        print_byte_field(resource->sha1_hash, sizeof(resource->sha1_hash));
        tputchar(T('\n'));
 
-       tprintf(T("Flags               = "));
+       tprintf(T("Flags                 = "));
        if (resource->is_compressed)
                tprintf(T("WIM_RESHDR_FLAG_COMPRESSED  "));
        if (resource->is_metadata)
@@ -3239,6 +3292,8 @@ imagex_optimize(int argc, tchar **argv, int cmd)
        int c;
        int open_flags = WIMLIB_OPEN_FLAG_WRITE_ACCESS;
        int write_flags = WIMLIB_WRITE_FLAG_REBUILD;
+       int compression_type = WIMLIB_COMPRESSION_TYPE_INVALID;
+       uint32_t chunk_size = UINT32_MAX;
        int ret;
        WIMStruct *wim;
        const tchar *wimfile;
@@ -3255,11 +3310,26 @@ imagex_optimize(int argc, tchar **argv, int cmd)
                case IMAGEX_NOCHECK_OPTION:
                        write_flags |= WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY;
                        break;
+               case IMAGEX_COMPRESS_OPTION:
+                       write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
+                       compression_type = get_compression_type(optarg);
+                       if (compression_type == WIMLIB_COMPRESSION_TYPE_INVALID)
+                               goto out_err;
+                       break;
                case IMAGEX_RECOMPRESS_OPTION:
                        write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
                        break;
                case IMAGEX_COMPRESS_SLOW_OPTION:
-                       set_compress_slow();
+                       write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
+                       compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
+                       ret = set_compress_slow();
+                       if (ret)
+                               goto out_err;
+                       break;
+               case IMAGEX_CHUNK_SIZE_OPTION:
+                       chunk_size = parse_chunk_size(optarg);
+                       if (chunk_size == UINT32_MAX)
+                               goto out_err;
                        break;
                case IMAGEX_THREADS_OPTION:
                        num_threads = parse_num_threads(optarg);
@@ -3288,6 +3358,20 @@ imagex_optimize(int argc, tchar **argv, int cmd)
        if (ret)
                goto out;
 
+       if (compression_type != WIMLIB_COMPRESSION_TYPE_INVALID) {
+               /* Change compression type.  */
+               ret = wimlib_set_output_compression_type(wim, compression_type);
+               if (ret)
+                       goto out_wimlib_free;
+       }
+
+       if (chunk_size != UINT32_MAX) {
+               /* Change chunk size.  */
+               ret = wimlib_set_output_chunk_size(wim, chunk_size);
+               if (ret)
+                       goto out_wimlib_free;
+       }
+
        old_size = file_get_size(wimfile);
        tprintf(T("\"%"TS"\" original size: "), wimfile);
        if (old_size == -1)
@@ -3751,7 +3835,8 @@ T(
 #endif
 [CMD_OPTIMIZE] =
 T(
-"    %"TS" WIMFILE [--check] [--nocheck] [--recompress] [--compress-slow]\n"
+"    %"TS" WIMFILE [--check] [--nocheck] [--recompress]\n"
+"                    [--recompress-slow] [--compress=TYPE]\n"
 "                    [--threads=NUM_THREADS] [--pipable] [--not-pipable]\n"
 ),
 [CMD_SPLIT] =