4 * Use wimlib to create, modify, extract, mount, unmount, or display information
7 * Copyright (C) 2012 Eric Biggers
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 #define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
34 #define swap(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); \
37 #define for_opt(c, opts) while ((c = getopt_long_only(argc, (char**)argv, "", \
54 static const char *path_basename(const char *path)
61 /* Trailing slashes. */
62 while ((p != path - 1) && *p == '/')
65 while ((p != path - 1) && *p != '/')
72 static const char *usage_strings[] = {
74 " imagex append DIRECTORY WIMFILE [\"IMAGE_NAME\"] [\"DESCRIPTION\"] [--boot]\n"
75 " [--check] [--config CONFIG_FILE] [--flags EDITIONID] [--verify]\n",
77 " imagex apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all] DIRECTORY [--check]\n"
78 " [--verify] [--hardlink] [--symlink] [--verbose]\n",
80 " imagex capture DIRECTORY WIMFILE [\"IMAGE_NAME\"] [\"DESCRIPTION\"]\n"
81 " [--boot] [--check] [--compress[=TYPE]] [--config CONFIG_FILE]\n"
82 " [--flags \"EditionID\"] [--norpfix] [--verify] [--verbose]\n",
84 " imagex delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check]\n",
86 " imagex dir WIMFILE (IMAGE_NUM | IMAGE_NAME | \"all\")\n",
88 " imagex export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n"
89 " DEST_WIMFILE [\"DEST_IMAGE_NAME\"] [\"DEST_IMAGE_DESCRIPTION\"]\n"
90 " [--boot] [--check] [--compress[=TYPE]]\n",
92 " imagex info WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n"
93 " [NEW_DESC] [--boot] [--check] [--header] [--lookup-table]\n"
94 " [--xml] [--extract-xml FILE] [--metadata]\n",
96 " imagex join [--check] WIMFILE SPLIT_WIM...\n",
98 " imagex mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n"
99 " [--check] [--debug]\n",
101 " imagex mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
102 " [--check] [--debug]\n",
104 " imagex unmount DIRECTORY [--commit] [--check]\n",
107 static const struct option common_options[] = {
108 {"help", 0, NULL, 'h'},
109 {"version", 0, NULL, 'v'},
113 static const struct option append_options[] = {
114 {"boot", no_argument, NULL, 'b'},
115 {"check", no_argument, NULL, 'c'},
116 {"config", required_argument, NULL, 'C'},
117 {"flags", required_argument, NULL, 'f'},
118 {"verify", no_argument, NULL, 'V'},
121 static const struct option apply_options[] = {
122 {"check", no_argument, NULL, 'c'},
123 {"verify", no_argument, NULL, 'V'},
124 {"hardlink", no_argument, NULL, 'h'},
125 {"symlink", no_argument, NULL, 's'},
126 {"verbose", no_argument, NULL, 'v'},
129 static const struct option capture_options[] = {
130 {"boot", no_argument, NULL, 'b'},
131 {"check", no_argument, NULL, 'c'},
132 {"compress", optional_argument, NULL, 'x'},
133 {"config", required_argument, NULL, 'C'},
134 {"flags", required_argument, NULL, 'f'},
135 {"norpfix", no_argument, NULL, 'n'},
136 {"verify", no_argument, NULL, 'V'},
137 {"verbose", no_argument, NULL, 'v'},
140 static const struct option delete_options[] = {
141 {"check", no_argument, NULL, 'c'},
145 static const struct option export_options[] = {
146 {"boot", no_argument, NULL, 'b'},
147 {"check", no_argument , NULL, 'c'},
148 {"compress", optional_argument, NULL, 'x'},
152 static const struct option info_options[] = {
153 {"boot", no_argument, NULL, 'b'},
154 {"check", no_argument, NULL, 'c'},
155 {"header", no_argument, NULL, 'h'},
156 {"lookup-table", no_argument, NULL, 'l'},
157 {"xml", no_argument, NULL, 'x'},
158 {"extract-xml", required_argument, NULL, 'X'},
159 {"metadata", no_argument, NULL, 'm'},
163 static const struct option join_options[] = {
164 {"check", no_argument, NULL, 'c'},
165 {"output", required_argument, NULL, 'o'},
169 static const struct option mount_options[] = {
170 {"check", no_argument, NULL, 'c'},
171 {"debug", no_argument, NULL, 'd'},
175 static const struct option unmount_options[] = {
176 {"commit", no_argument, NULL, 'c'},
177 {"check", no_argument, NULL, 'C'},
182 /* Print formatted error message to stderr. */
183 static void imagex_error(const char *format, ...)
186 va_start(va, format);
187 fputs("ERROR: ", stderr);
188 vfprintf(stderr, format, va);
193 static inline void version()
195 static const char *s =
196 "imagex (" PACKAGE ") " PACKAGE_VERSION "\n"
197 "Copyright (C) 2012 Eric Biggers\n"
198 "License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
199 "This is free software: you are free to change and redistribute it.\n"
200 "There is NO WARRANTY, to the extent permitted by law.\n"
202 "Report bugs to "PACKAGE_BUGREPORT".\n";
206 static inline void usage(int cmd)
208 puts("IMAGEX: Usage:");
209 fputs(usage_strings[cmd], stdout);
212 static void usage_all()
214 puts("IMAGEX: Usage:");
215 for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
216 fputs(usage_strings[i], stdout);
217 static const char *extra =
219 " imagex --version\n"
221 " The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
223 fputs(extra, stdout);
226 static int verify_image_exists(int image)
228 if (image == WIM_NO_IMAGE) {
229 imagex_error("Not a valid image!\n");
230 return WIMLIB_ERR_INVALID_IMAGE;
235 static int verify_image_is_single(int image)
237 if (image == WIM_ALL_IMAGES) {
238 imagex_error("Cannot specify all images for this action!\n");
239 return WIMLIB_ERR_INVALID_IMAGE;
244 static int verify_image_exists_and_is_single(int image)
247 ret = verify_image_exists(image);
249 ret = verify_image_is_single(image);
253 static int get_compression_type(const char *optarg)
256 return WIM_COMPRESSION_TYPE_LZX;
257 if (strcasecmp(optarg, "maximum") == 0 || strcasecmp(optarg, "lzx") == 0)
258 return WIM_COMPRESSION_TYPE_LZX;
259 else if (strcasecmp(optarg, "fast") == 0 || strcasecmp(optarg, "xpress") == 0)
260 return WIM_COMPRESSION_TYPE_XPRESS;
261 else if (strcasecmp(optarg, "none") == 0)
262 return WIM_COMPRESSION_TYPE_NONE;
264 imagex_error("Invalid compression type `%s'! Must be "
265 "\"maximum\", \"fast\", or \"none\".\n",
267 return WIM_COMPRESSION_TYPE_INVALID;
271 static int imagex_append(int argc, const char **argv)
274 const char *flags_element = NULL;
275 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
276 int add_image_flags = 0;
277 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
285 for_opt(c, append_options) {
288 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
291 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
292 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
298 flags_element = optarg;
310 if (argc < 2 || argc > 4) {
316 name = (argc >= 3) ? argv[2] : path_basename(dir);
317 desc = (argc >= 4) ? argv[3] : NULL;
319 ret = wimlib_open_wim(wimfile, open_flags, &w);
323 ret = wimlib_add_image(w, dir, name, desc,
324 flags_element, add_image_flags);
327 ret = wimlib_overwrite(w, write_flags);
333 /* Extract one image, or all images, from a WIM file into a directory. */
334 static int imagex_apply(int argc, const char **argv)
337 int link_type = WIM_LINK_TYPE_NONE;
338 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
339 bool verbose = false;
346 const char *image_num_or_name;
348 for_opt(c, apply_options) {
351 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
357 link_type = WIM_LINK_TYPE_HARD;
360 link_type = WIM_LINK_TYPE_SYMBOLIC;
372 if (argc != 2 && argc != 3) {
379 image_num_or_name = "1";
382 image_num_or_name = argv[1];
386 ret = wimlib_open_wim(wimfile, open_flags, &w);
390 image = wimlib_resolve_image(w, image_num_or_name);
391 ret = verify_image_exists(image);
395 num_images = wimlib_get_num_images(w);
396 if (argc == 2 && num_images != 1) {
397 imagex_error("`%s' contains %d images; Please select one "
398 "(or all).\n", wimfile, num_images);
403 ret = wimlib_set_output_dir(w, dir);
406 wimlib_set_verbose(w, verbose);
407 wimlib_set_link_type(w, link_type);
408 ret = wimlib_extract_image(w, image);
415 /* Create a WIM file from a directory. */
416 static int imagex_capture(int argc, const char **argv)
419 int add_image_flags = 0;
420 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
421 int compression_type = WIM_COMPRESSION_TYPE_NONE;
422 const char *flags_element = NULL;
423 bool verbose = false;
431 for_opt(c, capture_options) {
434 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
437 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
440 compression_type = get_compression_type(optarg);
441 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
448 flags_element = optarg;
467 if (argc < 2 || argc > 4) {
473 name = (argc >= 3) ? argv[2] : dir;
474 desc = (argc >= 4) ? argv[3] : NULL;
476 ret = wimlib_create_new_wim(compression_type, &w);
480 wimlib_set_verbose(w, verbose);
482 ret = wimlib_add_image(w, dir, name, desc, flags_element,
485 imagex_error("Failed to add the image `%s'!\n", dir);
489 ret = wimlib_write(w, wimfile, WIM_ALL_IMAGES, write_flags);
491 imagex_error("Failed to write the WIM file `%s'!\n", wimfile);
497 /* Remove image(s) from a WIM. */
498 static int imagex_delete(int argc, const char **argv)
501 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
502 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
504 const char *image_num_or_name;
509 for_opt(c, delete_options) {
512 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
513 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
525 imagex_error("Must specify a WIM file!\n");
527 imagex_error("Must specify an image!\n");
532 image_num_or_name = argv[1];
534 ret = wimlib_open_wim(wimfile, open_flags, &w);
538 image = wimlib_resolve_image(w, image_num_or_name);
540 ret = verify_image_exists(image);
544 ret = wimlib_delete_image(w, image);
546 imagex_error("Failed to delete image from `%s'!\n",
551 ret = wimlib_overwrite(w, write_flags);
553 imagex_error("Failed to write the file `%s' with image "
554 "deleted!\n", wimfile);
561 /* Print the files contained in an image(s) in a WIM file. */
562 static int imagex_dir(int argc, const char **argv)
572 imagex_error("Must specify a WIM file!\n");
577 imagex_error("Too many arguments!\n");
583 ret = wimlib_open_wim(wimfile, WIMLIB_OPEN_FLAG_SPLIT_OK, &w);
587 part_number = wimlib_get_part_number(w, NULL);
588 if (part_number != 1) {
589 imagex_error("`%s' is part %d of a split WIM! Specify the first part "
590 "to see the files.\n",
591 wimfile, part_number);
592 ret = WIMLIB_ERR_SPLIT_UNSUPPORTED;
597 image = wimlib_resolve_image(w, argv[2]);
598 ret = verify_image_exists(image);
602 /* Image was not specified. If the WIM only contains one image,
603 * choose that one; otherwise, print an error. */
604 num_images = wimlib_get_num_images(w);
605 if (num_images != 1) {
606 imagex_error("The file `%s' contains %d images; Please "
607 "select one.\n", wimfile, num_images);
615 ret = wimlib_print_files(w, image);
621 /* Exports one, or all, images from a WIM file to a new WIM file or an existing
623 static int imagex_export(int argc, const char **argv)
626 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
627 int export_flags = 0;
628 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
629 int compression_type = WIM_COMPRESSION_TYPE_NONE;
630 bool compression_type_specified = false;
631 const char *src_wimfile;
632 const char *src_image_num_or_name;
633 const char *dest_wimfile;
634 const char *dest_name;
635 const char *dest_desc;
636 WIMStruct *src_w = NULL;
637 WIMStruct *dest_w = NULL;
643 for_opt(c, export_options) {
646 export_flags |= WIMLIB_EXPORT_FLAG_BOOT;
649 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
650 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
653 compression_type = get_compression_type(optarg);
654 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
656 compression_type_specified = true;
665 if (argc < 3 || argc > 5) {
669 src_wimfile = argv[0];
670 src_image_num_or_name = argv[1];
671 dest_wimfile = argv[2];
672 dest_name = (argc >= 4) ? argv[3] : NULL;
673 dest_desc = (argc >= 5) ? argv[4] : NULL;
674 ret = wimlib_open_wim(src_wimfile, open_flags, &src_w);
678 /* Determine if the destination is an existing file or not.
679 * If so, we try to append the exported image(s) to it; otherwise, we
680 * create a new WIM containing the exported image(s). */
681 if (stat(dest_wimfile, &stbuf) == 0) {
683 /* Destination file exists. */
684 if (!S_ISREG(stbuf.st_mode)) {
685 imagex_error("`%s' is not a regular file!\n",
689 ret = wimlib_open_wim(dest_wimfile, open_flags, &dest_w);
693 if (compression_type_specified && compression_type !=
694 wimlib_get_compression_type(dest_w)) {
695 imagex_error("Cannot specify a compression type that is "
696 "not the same as that used in the "
697 "destination WIM!\n");
700 compression_type = wimlib_get_compression_type(dest_w);
703 /* dest_wimfile is not an existing file, so create a new WIM. */
704 if (errno == ENOENT) {
705 ret = wimlib_create_new_wim(compression_type, &dest_w);
709 imagex_error("Cannot stat file `%s': %m\n",
715 image = wimlib_resolve_image(src_w, src_image_num_or_name);
716 ret = verify_image_exists(image);
720 ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
727 ret = wimlib_write(dest_w, dest_wimfile, WIM_ALL_IMAGES,
730 ret = wimlib_overwrite(dest_w, write_flags);
737 /* Prints information about a WIM file; also can mark an image as bootable,
738 * change the name of an image, or change the description of an image. */
739 static int imagex_info(int argc, const char **argv)
745 bool lookup_table = false;
747 bool metadata = false;
748 bool short_header = true;
749 const char *xml_out_file = NULL;
751 const char *image_num_or_name = "all";
752 const char *new_name = NULL;
753 const char *new_desc = NULL;
758 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS |
759 WIMLIB_OPEN_FLAG_SPLIT_OK;
763 for_opt(c, info_options) {
773 short_header = false;
777 short_header = false;
781 short_header = false;
784 xml_out_file = optarg;
785 short_header = false;
789 short_header = false;
799 if (argc == 0 || argc > 4) {
805 image_num_or_name = argv[1];
815 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
817 ret = wimlib_open_wim(wimfile, open_flags, &w);
821 part_number = wimlib_get_part_number(w, &total_parts);
823 /*if (total_parts > 1 && part_number > 1) {*/
824 /*printf("Warning: this is part %d of a %d-part split WIM.\n"*/
825 /*" Select the first part if you want to see information\n"*/
826 /*" about images in the WIM.\n", */
827 /*part_number, total_parts);*/
830 image = wimlib_resolve_image(w, image_num_or_name);
831 if (image == WIM_NO_IMAGE && strcmp(image_num_or_name, "0") != 0) {
832 imagex_error("The image `%s' does not exist!\n",
835 imagex_error("If you would like to set the boot "
836 "index to 0, specify image \"0\" with "
837 "the --boot flag.\n");
838 ret = WIMLIB_ERR_INVALID_IMAGE;
842 if (image == WIM_ALL_IMAGES && wimlib_get_num_images(w) > 1) {
844 imagex_error("Cannot specify the --boot flag "
845 "without specifying a specific "
846 "image in a multi-image WIM!\n");
847 ret = WIMLIB_ERR_INVALID_IMAGE;
851 imagex_error("Cannot specify the NEW_NAME "
852 "without specifying a specific "
853 "image in a multi-image WIM!\n");
854 ret = WIMLIB_ERR_INVALID_IMAGE;
859 /* Operations that print information are separated from operations that
860 * recreate the WIM file. */
861 if (!new_name && !boot) {
863 if (image == WIM_NO_IMAGE) {
864 imagex_error("`%s' is not a valid image!\n",
866 ret = WIMLIB_ERR_INVALID_IMAGE;
870 if (image == WIM_ALL_IMAGES && short_header)
871 wimlib_print_wim_information(w);
874 wimlib_print_header(w);
877 if (total_parts != 1) {
878 printf("Warning: Only showing the lookup table "
879 "for part %d of a %d-part WIM.\n",
880 part_number, total_parts);
882 wimlib_print_lookup_table(w);
886 ret = wimlib_extract_xml_data(w, stdout);
892 fp = fopen(xml_out_file, "wb");
894 imagex_error("Failed to open the file `%s' for "
895 "writing: %m\n", xml_out_file);
898 ret = wimlib_extract_xml_data(w, fp);
899 if (fclose(fp) != 0) {
900 imagex_error("Failed to close the "
911 wimlib_print_available_images(w, image);
914 if (total_parts != 1 && part_number != 1) {
915 imagex_error("Select part 1 of this %d-part WIM "
916 "to see the image metadata.\n",
918 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
920 ret = wimlib_print_metadata(w, image);
925 if (total_parts != 1) {
926 imagex_error("Modifying a split WIM is not supported.\n");
929 if (image == WIM_ALL_IMAGES)
932 if (image == WIM_NO_IMAGE && new_name) {
933 imagex_error("Cannot specify new_name (`%s') when "
939 if (image == wimlib_get_boot_idx(w)) {
940 printf("Image %d is already marked as "
941 "bootable.\n", image);
944 printf("Marking image %d as bootable.\n",
946 wimlib_set_boot_idx(w, image);
950 if (strcmp(wimlib_get_image_name(w, image),
952 printf("Image %d is already named \"%s\".\n",
956 printf("Changing the name of image %d to \"%s\".\n",
958 ret = wimlib_set_image_name(w, image, new_name);
964 const char *old_desc;
965 old_desc = wimlib_get_image_description(w, image);
966 if (old_desc && strcmp(old_desc, new_desc) == 0) {
967 printf("The description of image %d is already "
968 "\"%s\".\n", image, new_desc);
971 printf("Changing the description of image %d "
972 "to \"%s\".\n", image, new_desc);
973 ret = wimlib_set_image_descripton(w, image,
980 /* Only call wimlib_overwrite_xml_and_header() if something
981 * actually needs to be changed. */
982 if (boot || new_name || new_desc ||
983 check != wimlib_has_integrity_table(w)) {
985 ret = wimlib_overwrite_xml_and_header(w, check ?
986 WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
987 WIMLIB_WRITE_FLAG_SHOW_PROGRESS : 0);
989 printf("The file `%s' was not modified because nothing "
990 "needed to be done.\n", wimfile);
1000 /* Join split WIMs into one part WIM */
1001 static int imagex_join(int argc, const char **argv)
1004 int flags = WIMLIB_OPEN_FLAG_SPLIT_OK | WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1007 const char *output_path;
1009 for_opt(c, join_options) {
1012 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1022 imagex_error("Must specify at least two split WIM "
1023 "(.swm) parts to join!\n");
1026 output_path = argv[0];
1027 return wimlib_join(++argv, --argc, output_path, flags);
1033 /* Mounts an image using a FUSE mount. */
1034 static int imagex_mount_rw_or_ro(int argc, const char **argv)
1038 int mount_flags = 0;
1039 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1040 const char *wimfile;
1047 if (strcmp(argv[0], "mountrw") == 0)
1048 mount_flags |= WIMLIB_MOUNT_FLAG_READWRITE;
1049 for_opt(c, mount_options) {
1052 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1055 mount_flags |= WIMLIB_MOUNT_FLAG_DEBUG;
1058 usage(ro ? MOUNT : MOUNTRW);
1064 if (argc != 2 && argc != 3) {
1065 usage(ro ? MOUNT : MOUNTRW);
1071 ret = wimlib_open_wim(wimfile, open_flags, &w);
1077 num_images = wimlib_get_num_images(w);
1078 if (num_images != 1) {
1079 imagex_error("The file `%s' contains %d images; Please "
1080 "select one.\n", wimfile, num_images);
1081 usage(ro ? MOUNT : MOUNTRW);
1082 ret = WIMLIB_ERR_INVALID_IMAGE;
1087 image = wimlib_resolve_image(w, argv[1]);
1091 ret = verify_image_exists_and_is_single(image);
1095 ret = wimlib_mount(w, image, dir, mount_flags);
1097 imagex_error("Failed to mount image %d from `%s' on `%s'!\n",
1098 image, wimfile, dir);
1106 /* Unmounts an image. */
1107 static int imagex_unmount(int argc, const char **argv)
1110 int unmount_flags = 0;
1113 for_opt(c, unmount_options) {
1116 unmount_flags |= WIMLIB_UNMOUNT_FLAG_COMMIT;
1119 unmount_flags |= WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY;
1133 ret = wimlib_unmount(argv[0], unmount_flags);
1135 imagex_error("Failed to unmount `%s'!\n", argv[0]);
1139 struct imagex_command {
1141 int (*func)(int , const char **);
1145 static struct imagex_command imagex_commands[] = {
1146 {"append", imagex_append, APPEND},
1147 {"apply", imagex_apply, APPLY},
1148 {"capture", imagex_capture, CAPTURE},
1149 {"delete", imagex_delete, DELETE},
1150 {"dir", imagex_dir, DIR},
1151 {"export", imagex_export, EXPORT},
1152 {"info", imagex_info, INFO},
1153 {"join", imagex_join, JOIN},
1154 {"mount", imagex_mount_rw_or_ro, MOUNT},
1155 {"mountrw", imagex_mount_rw_or_ro, MOUNTRW},
1156 {"unmount", imagex_unmount, UNMOUNT},
1159 #define for_imagex_command(p) for (p = &imagex_commands[0]; \
1160 p != &imagex_commands[ARRAY_LEN(imagex_commands)]; p++)
1162 static void help_or_version(int argc, const char **argv)
1166 struct imagex_command *cmd;
1168 for (i = 1; i < argc; i++) {
1176 if (strcmp(p, "help") == 0 || (*p == '?' && *(p + 1) == '\0')) {
1177 for_imagex_command(cmd) {
1178 if (strcmp(cmd->name, argv[1]) == 0) {
1186 if (strcmp(p, "version") == 0) {
1194 int main(int argc, const char **argv)
1196 struct imagex_command *cmd;
1200 imagex_error("No command specified!\n");
1205 help_or_version(argc, argv);
1209 wimlib_set_print_errors(true);
1211 for_imagex_command(cmd) {
1212 if (strcmp(cmd->name, *argv) == 0) {
1213 ret = cmd->func(argc, argv);
1215 imagex_error("Exiting with error code %d:\n"
1217 wimlib_get_error_string(ret));
1223 imagex_error("Unrecognized command: `%s'\n", argv[0]);