" (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n"
" [--symlink] [--verbose] [--ref=\"GLOB\"] [--unix-data]\n"
" [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n"
" (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n"
" [--symlink] [--verbose] [--ref=\"GLOB\"] [--unix-data]\n"
" [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n"
IMAGEX_PROGNAME" extract WIMFILE (IMAGE_NUM | IMAGE_NAME) [PATH...]\n"
" [--check] [--ref=\"GLOB\"] [--verbose] [--unix-data]\n"
" [--no-acls] [--strict-acls] [--to-stdout] [--dest-dir=DIR]\n"
IMAGEX_PROGNAME" extract WIMFILE (IMAGE_NUM | IMAGE_NAME) [PATH...]\n"
" [--check] [--ref=\"GLOB\"] [--verbose] [--unix-data]\n"
" [--no-acls] [--strict-acls] [--to-stdout] [--dest-dir=DIR]\n"
-IMAGEX_PROGNAME" update WIMFILE IMAGE [--check] [--rebuild]\n"
-" [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n"
-" [DEFAULT_DELETE_OPTIONS] [< CMDFILE]\n"
-" ... where each CMD is:\n"
-" add [--unix-data] [--no-acls] [--strict-acls] [--dereference]\n"
-" [--verbose] FILE_OR_DIRECTORY DEST_WIM_PATH\n"
-" delete [--force] [--recursive] WIM_PATH\n"
-" rename SRC_PATH_IN_WIM DEST_PATH_IN_WIM\n"
+IMAGEX_PROGNAME" update WIMFILE [IMAGE_NUM | IMAGE_NAME] [--check] [--rebuild]\n"
+" [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n"
+" [DEFAULT_DELETE_OPTIONS] [--command=STRING] [< CMDFILE]\n"
+
+static void
+recommend_man_page(const tchar *cmd_name)
+{
+ const tchar *format_str;
+#ifdef __WIN32__
+ format_str = T("See "IMAGEX_PROGNAME"%"TS"%"TS".pdf in the "
+ "doc directory for more details.\n");
+#else
+ format_str = T("Try `man "IMAGEX_PROGNAME"%"TS"%"TS"' "
+ "for more details.\n");
+#endif
+ tprintf(format_str, *cmd_name ? T("-") : T(""), cmd_name);
+}
+
{T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION},
{T("rpfix"), no_argument, NULL, IMAGEX_RPFIX_OPTION},
{T("norpfix"), no_argument, NULL, IMAGEX_NORPFIX_OPTION},
{T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION},
{T("rpfix"), no_argument, NULL, IMAGEX_RPFIX_OPTION},
{T("norpfix"), no_argument, NULL, IMAGEX_NORPFIX_OPTION},
{T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION},
{T("dest-dir"), required_argument, NULL, IMAGEX_DEST_DIR_OPTION},
{T("to-stdout"), no_argument, NULL, IMAGEX_TO_STDOUT_OPTION},
{T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION},
{T("dest-dir"), required_argument, NULL, IMAGEX_DEST_DIR_OPTION},
{T("to-stdout"), no_argument, NULL, IMAGEX_TO_STDOUT_OPTION},
{T("commit"), no_argument, NULL, IMAGEX_COMMIT_OPTION},
{T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION},
{T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION},
{T("commit"), no_argument, NULL, IMAGEX_COMMIT_OPTION},
{T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION},
{T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION},
{T("threads"), required_argument, NULL, IMAGEX_THREADS_OPTION},
{T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION},
{T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION},
{T("threads"), required_argument, NULL, IMAGEX_THREADS_OPTION},
{T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION},
{T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION},
{T("force"), no_argument, NULL, IMAGEX_FORCE_OPTION},
{T("recursive"), no_argument, NULL, IMAGEX_RECURSIVE_OPTION},
{T("force"), no_argument, NULL, IMAGEX_FORCE_OPTION},
{T("recursive"), no_argument, NULL, IMAGEX_RECURSIVE_OPTION},
{T("config"), required_argument, NULL, IMAGEX_CONFIG_OPTION},
{T("config"), required_argument, NULL, IMAGEX_CONFIG_OPTION},
{T("dereference"), no_argument, NULL, IMAGEX_DEREFERENCE_OPTION},
{T("unix-data"), no_argument, NULL, IMAGEX_UNIX_DATA_OPTION},
{T("noacls"), no_argument, NULL, IMAGEX_NO_ACLS_OPTION},
{T("no-acls"), no_argument, NULL, IMAGEX_NO_ACLS_OPTION},
{T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION},
{T("dereference"), no_argument, NULL, IMAGEX_DEREFERENCE_OPTION},
{T("unix-data"), no_argument, NULL, IMAGEX_UNIX_DATA_OPTION},
{T("noacls"), no_argument, NULL, IMAGEX_NO_ACLS_OPTION},
{T("no-acls"), no_argument, NULL, IMAGEX_NO_ACLS_OPTION},
{T("strict-acls"), no_argument, NULL, IMAGEX_STRICT_ACLS_OPTION},
+#define GIBIBYTE_MIN_NBYTES 10000000000ULL
+#define MEBIBYTE_MIN_NBYTES 10000000ULL
+#define KIBIBYTE_MIN_NBYTES 10000ULL
+
+static unsigned
+get_unit(uint64_t total_bytes, const tchar **name_ret)
+{
+ if (total_bytes >= GIBIBYTE_MIN_NBYTES) {
+ *name_ret = T("GiB");
+ return 30;
+ } else if (total_bytes >= MEBIBYTE_MIN_NBYTES) {
+ *name_ret = T("MiB");
+ return 20;
+ } else if (total_bytes >= KIBIBYTE_MIN_NBYTES) {
+ *name_ret = T("KiB");
+ return 10;
+ } else {
+ *name_ret = T("bytes");
+ return 0;
+ }
+}
+
/* Progress callback function passed to various wimlib functions. */
static int
imagex_progress_func(enum wimlib_progress_msg msg,
const union wimlib_progress_info *info)
{
unsigned percent_done;
/* Progress callback function passed to various wimlib functions. */
static int
imagex_progress_func(enum wimlib_progress_msg msg,
const union wimlib_progress_info *info)
{
unsigned percent_done;
percent_done = TO_PERCENT(info->write_streams.completed_bytes,
info->write_streams.total_bytes);
if (info->write_streams.completed_streams == 0) {
percent_done = TO_PERCENT(info->write_streams.completed_bytes,
info->write_streams.total_bytes);
if (info->write_streams.completed_streams == 0) {
data_type, info->write_streams.num_threads,
(info->write_streams.num_threads == 1) ? T("") : T("s"));
}
data_type, info->write_streams.num_threads,
(info->write_streams.num_threads == 1) ? T("") : T("s"));
}
- info->write_streams.completed_bytes >> 20,
- info->write_streams.total_bytes >> 20,
+ info->write_streams.completed_bytes >> unit_shift,
+ unit_name,
+ info->write_streams.total_bytes >> unit_shift,
+ unit_name,
percent_done = TO_PERCENT(info->integrity.completed_bytes,
info->integrity.total_bytes);
percent_done = TO_PERCENT(info->integrity.completed_bytes,
info->integrity.total_bytes);
- tprintf(T("\rVerifying integrity of \"%"TS"\": %"PRIu64" MiB "
- "of %"PRIu64" MiB (%u%%) done"),
+ tprintf(T("\rVerifying integrity of \"%"TS"\": %"PRIu64" "TS" "
+ "of %"PRIu64" "TS" (%u%%) done"),
- info->integrity.completed_bytes >> 20,
- info->integrity.total_bytes >> 20,
+ info->integrity.completed_bytes >> unit_shift,
+ unit_name,
+ info->integrity.total_bytes >> unit_shift,
+ unit_name,
percent_done);
if (info->integrity.completed_bytes == info->integrity.total_bytes)
tputchar(T('\n'));
break;
case WIMLIB_PROGRESS_MSG_CALC_INTEGRITY:
percent_done);
if (info->integrity.completed_bytes == info->integrity.total_bytes)
tputchar(T('\n'));
break;
case WIMLIB_PROGRESS_MSG_CALC_INTEGRITY:
percent_done = TO_PERCENT(info->integrity.completed_bytes,
info->integrity.total_bytes);
percent_done = TO_PERCENT(info->integrity.completed_bytes,
info->integrity.total_bytes);
- tprintf(T("\rCalculating integrity table for WIM: %"PRIu64" MiB "
- "of %"PRIu64" MiB (%u%%) done"),
- info->integrity.completed_bytes >> 20,
- info->integrity.total_bytes >> 20,
+ tprintf(T("\rCalculating integrity table for WIM: %"PRIu64" %"TS" "
+ "of %"PRIu64" %"TS" (%u%%) done"),
+ info->integrity.completed_bytes >> unit_shift,
+ unit_name,
+ info->integrity.total_bytes >> unit_shift,
+ unit_name,
case WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS:
percent_done = TO_PERCENT(info->extract.completed_bytes,
info->extract.total_bytes);
case WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS:
percent_done = TO_PERCENT(info->extract.completed_bytes,
info->extract.total_bytes);
- "%"PRIu64" MiB of %"PRIu64" MiB (%u%%) done"),
- info->extract.completed_bytes >> 20,
- info->extract.total_bytes >> 20,
+ "%"PRIu64" %"TS" of %"PRIu64" %"TS" (%u%%) done"),
+ info->extract.completed_bytes >> unit_shift,
+ unit_name,
+ info->extract.total_bytes >> unit_shift,
+ unit_name,
case WIMLIB_PROGRESS_MSG_JOIN_STREAMS:
percent_done = TO_PERCENT(info->join.completed_bytes,
info->join.total_bytes);
case WIMLIB_PROGRESS_MSG_JOIN_STREAMS:
percent_done = TO_PERCENT(info->join.completed_bytes,
info->join.total_bytes);
(info->join.completed_parts == info->join.total_parts) ?
info->join.completed_parts : info->join.completed_parts + 1,
info->join.total_parts,
(info->join.completed_parts == info->join.total_parts) ?
info->join.completed_parts : info->join.completed_parts + 1,
info->join.total_parts,
- info->join.completed_bytes >> 20,
- info->join.total_bytes >> 20,
+ info->join.completed_bytes >> unit_shift,
+ unit_name,
+ info->join.total_bytes >> unit_shift,
+ unit_name,
percent_done);
break;
case WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART:
percent_done = TO_PERCENT(info->split.completed_bytes,
info->split.total_bytes);
percent_done);
break;
case WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART:
percent_done = TO_PERCENT(info->split.completed_bytes,
info->split.total_bytes);
- tprintf(T("Writing \"%"TS"\": %"PRIu64" MiB of "
- "%"PRIu64" MiB (%u%%) written\n"),
+ unit_shift = get_unit(info->split.total_bytes, &unit_name);
+ tprintf(T("Writing \"%"TS"\": %"PRIu64" %"TS" of "
+ "%"PRIu64" %"TS" (%u%%) written\n"),
- info->split.completed_bytes >> 20,
- info->split.total_bytes >> 20,
+ info->split.completed_bytes >> unit_shift,
+ unit_name,
+ info->split.total_bytes >> unit_shift,
+ unit_name,
- if (!tstrcmp(option, T("--unix-data")))
+ if (!tstrcmp(option, T("--verbose")))
+ cmd->add.add_flags |= WIMLIB_ADD_IMAGE_FLAG_VERBOSE;
+ else if (!tstrcmp(option, T("--unix-data")))
cmd->add.add_flags |= WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA;
else if (!tstrcmp(option, T("--no-acls")) || !tstrcmp(option, T("--noacls")))
cmd->add.add_flags |= WIMLIB_ADD_IMAGE_FLAG_NO_ACLS;
cmd->add.add_flags |= WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA;
else if (!tstrcmp(option, T("--no-acls")) || !tstrcmp(option, T("--noacls")))
cmd->add.add_flags |= WIMLIB_ADD_IMAGE_FLAG_NO_ACLS;
if (!update_command_add_option(op, next_string, command))
{
imagex_error(T("Unrecognized option \"%"TS"\" to "
if (!update_command_add_option(op, next_string, command))
{
imagex_error(T("Unrecognized option \"%"TS"\" to "
- "update command on line %zu"),
- next_string, line_number);
+ "update command \"%"TS"\" on line %zu"),
+ next_string, command_name, line_number);
num_images = wimlib_get_num_images(w);
if (argc == 2 && num_images != 1) {
imagex_error(T("\"%"TS"\" contains %d images; Please select one "
num_images = wimlib_get_num_images(w);
if (argc == 2 && num_images != 1) {
imagex_error(T("\"%"TS"\" contains %d images; Please select one "
* choose that one; otherwise, print an error. */
num_images = wimlib_get_num_images(w);
if (num_images != 1) {
* choose that one; otherwise, print an error. */
num_images = wimlib_get_num_images(w);
if (num_images != 1) {
-prepare_extract_commands(tchar **argv, int argc, int extract_flags,
- tchar *dest_dir, size_t *num_cmds_ret)
+prepare_extract_commands(tchar **paths, unsigned num_paths,
+ int extract_flags, tchar *dest_dir,
+ size_t *num_cmds_ret)
cmds = calloc(num_cmds, sizeof(cmds[0]));
if (!cmds) {
imagex_error(T("Out of memory!"));
cmds = calloc(num_cmds, sizeof(cmds[0]));
if (!cmds) {
imagex_error(T("Out of memory!"));
cmds[i].fs_dest_path = malloc((len + 1) * sizeof(tchar));
if (!cmds[i].fs_dest_path) {
free_extract_commands(cmds, num_cmds, dest_dir);
return NULL;
}
tsprintf(cmds[i].fs_dest_path, T("%"TS"/%"TS), dest_dir,
cmds[i].fs_dest_path = malloc((len + 1) * sizeof(tchar));
if (!cmds[i].fs_dest_path) {
free_extract_commands(cmds, num_cmds, dest_dir);
return NULL;
}
tsprintf(cmds[i].fs_dest_path, T("%"TS"/%"TS), dest_dir,
- ret = wimlib_extract_files(wim, image, 0, cmds, num_cmds,
+ ret = wimlib_extract_files(wim, image, cmds, num_cmds, 0,
"select one."), wimfile, num_images);
usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
? MOUNTRW : MOUNT);
"select one."), wimfile, num_images);
usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
? MOUNTRW : MOUNT);
ret = wimlib_open_wim(wimfile, open_flags, &w,
imagex_progress_func);
ret = wimlib_open_wim(wimfile, open_flags, &w,
imagex_progress_func);
int update_flags = 0;
int default_add_flags = WIMLIB_ADD_IMAGE_FLAG_EXCLUDE_VERBOSE;
int default_delete_flags = 0;
unsigned num_threads = 0;
int c;
int update_flags = 0;
int default_add_flags = WIMLIB_ADD_IMAGE_FLAG_EXCLUDE_VERBOSE;
int default_delete_flags = 0;
unsigned num_threads = 0;
int c;
case IMAGEX_THREADS_OPTION:
num_threads = parse_num_threads(optarg);
if (num_threads == UINT_MAX) {
case IMAGEX_THREADS_OPTION:
num_threads = parse_num_threads(optarg);
if (num_threads == UINT_MAX) {
+ case IMAGEX_COMMAND_OPTION:
+ if (command_str) {
+ imagex_error(T("--command may only be specified "
+ "one time. Please provide\n"
+ " the update commands "
+ "on standard input instead."));
+ ret = -1;
+ goto out;
+ }
+ command_str = tstrdup(optarg);
+ if (!command_str) {
+ imagex_error(T("Out of memory!"));
+ ret = -1;
+ goto out;
+ }
+ break;
+ /* Default delete options */
case IMAGEX_FORCE_OPTION:
default_delete_flags |= WIMLIB_DELETE_FLAG_FORCE;
break;
case IMAGEX_RECURSIVE_OPTION:
default_delete_flags |= WIMLIB_DELETE_FLAG_RECURSIVE;
break;
case IMAGEX_FORCE_OPTION:
default_delete_flags |= WIMLIB_DELETE_FLAG_FORCE;
break;
case IMAGEX_RECURSIVE_OPTION:
default_delete_flags |= WIMLIB_DELETE_FLAG_RECURSIVE;
break;
ret = wimlib_open_wim(wimfile, open_flags, &wim, imagex_progress_func);
if (ret)
goto out;
ret = wimlib_open_wim(wimfile, open_flags, &wim, imagex_progress_func);
if (ret)
goto out;
- /* Read update commands from standard input */
- if (isatty(STDIN_FILENO))
- tputs(T("Reading update commands from standard input..."));
- cmd_file_contents = stdin_get_text_contents(&cmd_file_nchars);
- if (!cmd_file_contents) {
- ret = -1;
- goto out_free_config;
- }
+ /* Read update commands from standard input, or the command string if
+ * specified. */
+ if (command_str) {
+ cmds = parse_update_command_file(&command_str, tstrlen(command_str),
+ &num_cmds);
+ } else {
+ if (isatty(STDIN_FILENO)) {
+ tputs(T("Reading update commands from standard input..."));
+ recommend_man_page(T("update"));
+ }
+ cmd_file_contents = stdin_get_text_contents(&cmd_file_nchars);
+ if (!cmd_file_contents) {
+ ret = -1;
+ goto out_free_config;
+ }
- /* Parse the update commands */
- cmds = parse_update_command_file(&cmd_file_contents, cmd_file_nchars,
- &num_cmds);
+ /* Parse the update commands */
+ cmds = parse_update_command_file(&cmd_file_contents, cmd_file_nchars,
+ &num_cmds);
+ }
/* Execute the update commands */
ret = wimlib_update_image(wim, image, cmds, num_cmds, update_flags,
imagex_progress_func);
if (ret)
/* Execute the update commands */
ret = wimlib_update_image(wim, image, cmds, num_cmds, update_flags,
imagex_progress_func);
if (ret)
/* Overwrite the updated WIM */
ret = wimlib_overwrite(wim, write_flags, num_threads,
imagex_progress_func);
/* Overwrite the updated WIM */
ret = wimlib_overwrite(wim, write_flags, num_threads,
imagex_progress_func);
tprintf(T("Usage:\n%"TS), usage_strings[cmd_type]);
for_imagex_command(cmd) {
if (cmd->cmd == cmd_type) {
tprintf(T("Usage:\n%"TS), usage_strings[cmd_type]);
for_imagex_command(cmd) {
if (cmd->cmd == cmd_type) {
- tprintf(T("\nTry `man "IMAGEX_PROGNAME"-%"TS"' "
- "for more details.\n"), cmd->name);
+ tputc(T('\n'), stdout);
+ recommend_man_page(cmd->name);
{
tfputs(T("Usage:\n"), stdout);
for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
{
tfputs(T("Usage:\n"), stdout);
for (int i = 0; i < ARRAY_LEN(usage_strings); i++)