]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
wimlib-imagex: allow specifying suffix in chunk size options
[wimlib] / programs / imagex.c
index 19ef736124a58eac0a9d519cbac3d3da23e1bf5d..052c4e19881ebd04bdad11bc0040715c6951e91c 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 /*
- * Copyright (C) 2012, 2013, 2014 Eric Biggers
+ * Copyright (C) 2012, 2013, 2014, 2015 Eric Biggers
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1303,16 +1303,37 @@ parse_num_threads(const tchar *optarg)
        }
 }
 
-static uint32_t parse_chunk_size(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;
-       }
+       tchar *tmp;
+       uint64_t chunk_size = tstrtoul(optarg, &tmp, 10);
+       if (chunk_size == 0) {
+               imagex_error(T("Invalid chunk size specification; must be a positive integer\n"
+                              "       with optional K, M, or G suffix"));
+               return UINT32_MAX;
+       }
+       if (*tmp) {
+               if (*tmp == T('k') || *tmp == T('K')) {
+                       chunk_size <<= 10;
+                       tmp++;
+               } else if (*tmp == T('m') || *tmp == T('M')) {
+                       chunk_size <<= 20;
+                       tmp++;
+               } else if (*tmp == T('g') || *tmp == T('G')) {
+                       chunk_size <<= 30;
+                       tmp++;
+               }
+               if (*tmp && !(*tmp == T('i') && *(tmp + 1) == T('B'))) {
+                       imagex_error(T("Invalid chunk size specification; suffix must be K, M, or G"));
+                       return UINT32_MAX;
+               }
+       }
+       if (chunk_size >= UINT32_MAX) {
+               imagex_error(T("Invalid chunk size specification; the value is too large!"));
+               return UINT32_MAX;
+       }
+       return chunk_size;
 }
 
 
@@ -1793,7 +1814,7 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                                goto out_err;
                        break;
                case IMAGEX_SOLID_OPTION:
-                       write_flags |= WIMLIB_WRITE_FLAG_PACK_STREAMS;
+                       write_flags |= WIMLIB_WRITE_FLAG_SOLID;
                        break;
                case IMAGEX_FLAGS_OPTION:
                        flags_element = optarg;
@@ -1891,9 +1912,9 @@ imagex_capture_or_append(int argc, tchar **argv, int cmd)
                if (add_flags & WIMLIB_ADD_FLAG_WIMBOOT) {
                        /* With --wimboot, default to XPRESS compression.  */
                        compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
-               } else if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS) {
+               } else if (write_flags & WIMLIB_WRITE_FLAG_SOLID) {
                        /* With --solid, default to LZMS compression.  (However,
-                        * this will not affect solid blocks!)  */
+                        * this will not affect solid resources!)  */
                        compression_type = WIMLIB_COMPRESSION_TYPE_LZMS;
                } else {
                        /* Otherwise, default to LZX compression.  */
@@ -2449,7 +2470,7 @@ print_resource(const struct wimlib_resource_entry *resource,
                if (resource->is_spanned)
                        tprintf(T("WIM_RESHDR_FLAG_SPANNED  "));
                if (resource->packed)
-                       tprintf(T("WIM_RESHDR_FLAG_PACKED_STREAMS  "));
+                       tprintf(T("WIM_RESHDR_FLAG_SOLID  "));
                tputchar(T('\n'));
        }
        tputchar(T('\n'));
@@ -2667,7 +2688,7 @@ imagex_export(int argc, tchar **argv, int cmd)
                        write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
                        break;
                case IMAGEX_SOLID_OPTION:
-                       write_flags |= WIMLIB_WRITE_FLAG_PACK_STREAMS;
+                       write_flags |= WIMLIB_WRITE_FLAG_SOLID;
                        break;
                case IMAGEX_CHUNK_SIZE_OPTION:
                        chunk_size = parse_chunk_size(optarg);
@@ -2802,7 +2823,7 @@ imagex_export(int argc, tchar **argv, int cmd)
                         * to that of the source WIM, unless --solid or
                         * --wimboot was specified.   */
 
-                       if (write_flags & WIMLIB_WRITE_FLAG_PACK_STREAMS)
+                       if (write_flags & WIMLIB_WRITE_FLAG_SOLID)
                                compression_type = WIMLIB_COMPRESSION_TYPE_LZMS;
                        else if (export_flags & WIMLIB_EXPORT_FLAG_WIMBOOT)
                                compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
@@ -3571,7 +3592,7 @@ imagex_optimize(int argc, tchar **argv, int cmd)
                                goto out_err;
                        break;
                case IMAGEX_SOLID_OPTION:
-                       write_flags |= WIMLIB_WRITE_FLAG_PACK_STREAMS;
+                       write_flags |= WIMLIB_WRITE_FLAG_SOLID;
                        write_flags |= WIMLIB_WRITE_FLAG_RECOMPRESS;
                        break;
                case IMAGEX_THREADS_OPTION:
@@ -4248,7 +4269,7 @@ static const tchar *get_cmd_string(int cmd, bool nospace)
 {
        static tchar buf[50];
        if (cmd == CMD_NONE) {
-               tsprintf(buf, T("%"TS), T(IMAGEX_PROGNAME));
+               return T("wimlib-imagex");
        } else if (invocation_cmd != CMD_NONE) {
                tsprintf(buf, T("wim%"TS), imagex_commands[cmd].name);
        } else {
@@ -4268,8 +4289,8 @@ version(void)
 {
        static const tchar *s =
        T(
-IMAGEX_PROGNAME " (distributed with " PACKAGE " " PACKAGE_VERSION ")\n"
-"Copyright (C) 2012, 2013, 2014 Eric Biggers\n"
+"wimlib-imagex (distributed with " PACKAGE " " PACKAGE_VERSION ")\n"
+"Copyright (C) 2012, 2013, 2014, 2015 Eric Biggers\n"
 "License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
 "This is free software: you are free to change and redistribute it.\n"
 "There is NO WARRANTY, to the extent permitted by law.\n"
@@ -4419,7 +4440,7 @@ main(int argc, char **argv)
        /* Allow being invoked as wimCOMMAND (e.g. wimapply).  */
        cmd = CMD_NONE;
        if (!tstrncmp(invocation_name, T("wim"), 3) &&
-           tstrcmp(invocation_name, T(IMAGEX_PROGNAME))) {
+           tstrcmp(invocation_name, T("wimlib-imagex"))) {
                for (int i = 0; i < CMD_MAX; i++) {
                        if (!tstrcmp(invocation_name + 3,
                                     imagex_commands[i].name))