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, "", \
55 static const char *path_basename(const char *path)
62 /* Trailing slashes. */
63 while ((p != path - 1) && *p == '/')
66 while ((p != path - 1) && *p != '/')
73 static const char *usage_strings[] = {
75 " imagex append DIRECTORY WIMFILE [\"IMAGE_NAME\"] [\"DESCRIPTION\"] [--boot]\n"
76 " [--check] [--config CONFIG_FILE] [--flags EDITIONID] [--verify]\n",
78 " imagex apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all] DIRECTORY [--check]\n"
79 " [--verify] [--hardlink] [--symlink] [--verbose]\n",
81 " imagex capture DIRECTORY WIMFILE [\"IMAGE_NAME\"] [\"DESCRIPTION\"]\n"
82 " [--boot] [--check] [--compress[=TYPE]] [--config CONFIG_FILE]\n"
83 " [--flags \"EditionID\"] [--norpfix] [--verify] [--verbose]\n",
85 " imagex delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check]\n",
87 " imagex dir WIMFILE (IMAGE_NUM | IMAGE_NAME | \"all\")\n",
89 " imagex export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n"
90 " DEST_WIMFILE [\"DEST_IMAGE_NAME\"] [\"DEST_IMAGE_DESCRIPTION\"]\n"
91 " [--boot] [--check] [--compress[=TYPE]]\n",
93 " imagex info WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n"
94 " [NEW_DESC] [--boot] [--check] [--header] [--lookup-table]\n"
95 " [--xml] [--extract-xml FILE] [--metadata]\n",
97 " imagex join [--check] WIMFILE SPLIT_WIM...\n",
99 " imagex mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n"
100 " [--check] [--debug]\n",
102 " imagex mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
103 " [--check] [--debug]\n",
105 " imagex split WIMFILE SPLIT_WIMFILE PART_SIZE [--check]\n",
107 " imagex unmount DIRECTORY [--commit] [--check]\n",
110 static const struct option common_options[] = {
111 {"help", 0, NULL, 'h'},
112 {"version", 0, NULL, 'v'},
116 static const struct option append_options[] = {
117 {"boot", no_argument, NULL, 'b'},
118 {"check", no_argument, NULL, 'c'},
119 {"config", required_argument, NULL, 'C'},
120 {"flags", required_argument, NULL, 'f'},
121 {"verify", no_argument, NULL, 'V'},
124 static const struct option apply_options[] = {
125 {"check", no_argument, NULL, 'c'},
126 {"verify", no_argument, NULL, 'V'},
127 {"hardlink", no_argument, NULL, 'h'},
128 {"symlink", no_argument, NULL, 's'},
129 {"verbose", no_argument, NULL, 'v'},
132 static const struct option capture_options[] = {
133 {"boot", no_argument, NULL, 'b'},
134 {"check", no_argument, NULL, 'c'},
135 {"compress", optional_argument, NULL, 'x'},
136 {"config", required_argument, NULL, 'C'},
137 {"flags", required_argument, NULL, 'f'},
138 {"norpfix", no_argument, NULL, 'n'},
139 {"verify", no_argument, NULL, 'V'},
140 {"verbose", no_argument, NULL, 'v'},
143 static const struct option delete_options[] = {
144 {"check", no_argument, NULL, 'c'},
148 static const struct option export_options[] = {
149 {"boot", no_argument, NULL, 'b'},
150 {"check", no_argument , NULL, 'c'},
151 {"compress", optional_argument, NULL, 'x'},
155 static const struct option info_options[] = {
156 {"boot", no_argument, NULL, 'b'},
157 {"check", no_argument, NULL, 'c'},
158 {"header", no_argument, NULL, 'h'},
159 {"lookup-table", no_argument, NULL, 'l'},
160 {"xml", no_argument, NULL, 'x'},
161 {"extract-xml", required_argument, NULL, 'X'},
162 {"metadata", no_argument, NULL, 'm'},
166 static const struct option join_options[] = {
167 {"check", no_argument, NULL, 'c'},
171 static const struct option mount_options[] = {
172 {"check", no_argument, NULL, 'c'},
173 {"debug", no_argument, NULL, 'd'},
177 static const struct option split_options[] = {
178 {"check", no_argument, NULL, 'c'},
182 static const struct option unmount_options[] = {
183 {"commit", no_argument, NULL, 'c'},
184 {"check", no_argument, NULL, 'C'},
189 /* Print formatted error message to stderr. */
190 static void imagex_error(const char *format, ...)
193 va_start(va, format);
194 fputs("ERROR: ", stderr);
195 vfprintf(stderr, format, va);
200 static inline void version()
202 static const char *s =
203 "imagex (" PACKAGE ") " PACKAGE_VERSION "\n"
204 "Copyright (C) 2012 Eric Biggers\n"
205 "License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
206 "This is free software: you are free to change and redistribute it.\n"
207 "There is NO WARRANTY, to the extent permitted by law.\n"
209 "Report bugs to "PACKAGE_BUGREPORT".\n";
213 static inline void usage(int cmd)
215 puts("IMAGEX: Usage:");
216 fputs(usage_strings[cmd], stdout);
219 static void usage_all()
221 puts("IMAGEX: Usage:");
222 for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
223 fputs(usage_strings[i], stdout);
224 static const char *extra =
226 " imagex --version\n"
228 " The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
230 fputs(extra, stdout);
233 static int verify_image_exists(int image)
235 if (image == WIM_NO_IMAGE) {
236 imagex_error("Not a valid image!\n");
237 return WIMLIB_ERR_INVALID_IMAGE;
242 static int verify_image_is_single(int image)
244 if (image == WIM_ALL_IMAGES) {
245 imagex_error("Cannot specify all images for this action!\n");
246 return WIMLIB_ERR_INVALID_IMAGE;
251 static int verify_image_exists_and_is_single(int image)
254 ret = verify_image_exists(image);
256 ret = verify_image_is_single(image);
260 static int get_compression_type(const char *optarg)
263 return WIM_COMPRESSION_TYPE_LZX;
264 if (strcasecmp(optarg, "maximum") == 0 || strcasecmp(optarg, "lzx") == 0)
265 return WIM_COMPRESSION_TYPE_LZX;
266 else if (strcasecmp(optarg, "fast") == 0 || strcasecmp(optarg, "xpress") == 0)
267 return WIM_COMPRESSION_TYPE_XPRESS;
268 else if (strcasecmp(optarg, "none") == 0)
269 return WIM_COMPRESSION_TYPE_NONE;
271 imagex_error("Invalid compression type `%s'! Must be "
272 "\"maximum\", \"fast\", or \"none\".\n",
274 return WIM_COMPRESSION_TYPE_INVALID;
278 static int imagex_append(int argc, const char **argv)
281 const char *flags_element = NULL;
282 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
283 int add_image_flags = 0;
284 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
292 for_opt(c, append_options) {
295 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
298 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
299 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
305 flags_element = optarg;
317 if (argc < 2 || argc > 4) {
323 name = (argc >= 3) ? argv[2] : path_basename(dir);
324 desc = (argc >= 4) ? argv[3] : NULL;
326 ret = wimlib_open_wim(wimfile, open_flags, &w);
330 ret = wimlib_add_image(w, dir, name, desc,
331 flags_element, add_image_flags);
334 ret = wimlib_overwrite(w, write_flags);
340 /* Extract one image, or all images, from a WIM file into a directory. */
341 static int imagex_apply(int argc, const char **argv)
344 int link_type = WIM_LINK_TYPE_NONE;
345 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
346 bool verbose = false;
353 const char *image_num_or_name;
355 for_opt(c, apply_options) {
358 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
364 link_type = WIM_LINK_TYPE_HARD;
367 link_type = WIM_LINK_TYPE_SYMBOLIC;
379 if (argc != 2 && argc != 3) {
386 image_num_or_name = "1";
389 image_num_or_name = argv[1];
393 ret = wimlib_open_wim(wimfile, open_flags, &w);
397 image = wimlib_resolve_image(w, image_num_or_name);
398 ret = verify_image_exists(image);
402 num_images = wimlib_get_num_images(w);
403 if (argc == 2 && num_images != 1) {
404 imagex_error("`%s' contains %d images; Please select one "
405 "(or all).\n", wimfile, num_images);
410 ret = wimlib_set_output_dir(w, dir);
413 wimlib_set_verbose(w, verbose);
414 wimlib_set_link_type(w, link_type);
415 ret = wimlib_extract_image(w, image);
422 /* Create a WIM file from a directory. */
423 static int imagex_capture(int argc, const char **argv)
426 int add_image_flags = 0;
427 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
428 int compression_type = WIM_COMPRESSION_TYPE_NONE;
429 const char *flags_element = NULL;
430 bool verbose = false;
438 for_opt(c, capture_options) {
441 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
444 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
447 compression_type = get_compression_type(optarg);
448 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
455 flags_element = optarg;
474 if (argc < 2 || argc > 4) {
480 name = (argc >= 3) ? argv[2] : dir;
481 desc = (argc >= 4) ? argv[3] : NULL;
483 ret = wimlib_create_new_wim(compression_type, &w);
487 wimlib_set_verbose(w, verbose);
489 ret = wimlib_add_image(w, dir, name, desc, flags_element,
492 imagex_error("Failed to add the image `%s'!\n", dir);
496 ret = wimlib_write(w, wimfile, WIM_ALL_IMAGES, write_flags);
498 imagex_error("Failed to write the WIM file `%s'!\n", wimfile);
504 /* Remove image(s) from a WIM. */
505 static int imagex_delete(int argc, const char **argv)
508 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
509 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
511 const char *image_num_or_name;
516 for_opt(c, delete_options) {
519 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
520 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
532 imagex_error("Must specify a WIM file!\n");
534 imagex_error("Must specify an image!\n");
539 image_num_or_name = argv[1];
541 ret = wimlib_open_wim(wimfile, open_flags, &w);
545 image = wimlib_resolve_image(w, image_num_or_name);
547 ret = verify_image_exists(image);
551 ret = wimlib_delete_image(w, image);
553 imagex_error("Failed to delete image from `%s'!\n",
558 ret = wimlib_overwrite(w, write_flags);
560 imagex_error("Failed to write the file `%s' with image "
561 "deleted!\n", wimfile);
568 /* Print the files contained in an image(s) in a WIM file. */
569 static int imagex_dir(int argc, const char **argv)
579 imagex_error("Must specify a WIM file!\n");
584 imagex_error("Too many arguments!\n");
590 ret = wimlib_open_wim(wimfile, WIMLIB_OPEN_FLAG_SPLIT_OK, &w);
594 part_number = wimlib_get_part_number(w, NULL);
595 if (part_number != 1) {
596 imagex_error("`%s' is part %d of a split WIM! Specify the first part "
597 "to see the files.\n",
598 wimfile, part_number);
599 ret = WIMLIB_ERR_SPLIT_UNSUPPORTED;
604 image = wimlib_resolve_image(w, argv[2]);
605 ret = verify_image_exists(image);
609 /* Image was not specified. If the WIM only contains one image,
610 * choose that one; otherwise, print an error. */
611 num_images = wimlib_get_num_images(w);
612 if (num_images != 1) {
613 imagex_error("The file `%s' contains %d images; Please "
614 "select one.\n", wimfile, num_images);
622 ret = wimlib_print_files(w, image);
628 /* Exports one, or all, images from a WIM file to a new WIM file or an existing
630 static int imagex_export(int argc, const char **argv)
633 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
634 int export_flags = 0;
635 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
636 int compression_type = WIM_COMPRESSION_TYPE_NONE;
637 bool compression_type_specified = false;
638 const char *src_wimfile;
639 const char *src_image_num_or_name;
640 const char *dest_wimfile;
641 const char *dest_name;
642 const char *dest_desc;
643 WIMStruct *src_w = NULL;
644 WIMStruct *dest_w = NULL;
650 for_opt(c, export_options) {
653 export_flags |= WIMLIB_EXPORT_FLAG_BOOT;
656 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
657 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
660 compression_type = get_compression_type(optarg);
661 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
663 compression_type_specified = true;
672 if (argc < 3 || argc > 5) {
676 src_wimfile = argv[0];
677 src_image_num_or_name = argv[1];
678 dest_wimfile = argv[2];
679 dest_name = (argc >= 4) ? argv[3] : NULL;
680 dest_desc = (argc >= 5) ? argv[4] : NULL;
681 ret = wimlib_open_wim(src_wimfile, open_flags, &src_w);
685 /* Determine if the destination is an existing file or not.
686 * If so, we try to append the exported image(s) to it; otherwise, we
687 * create a new WIM containing the exported image(s). */
688 if (stat(dest_wimfile, &stbuf) == 0) {
690 /* Destination file exists. */
691 if (!S_ISREG(stbuf.st_mode)) {
692 imagex_error("`%s' is not a regular file!\n",
696 ret = wimlib_open_wim(dest_wimfile, open_flags, &dest_w);
700 if (compression_type_specified && compression_type !=
701 wimlib_get_compression_type(dest_w)) {
702 imagex_error("Cannot specify a compression type that is "
703 "not the same as that used in the "
704 "destination WIM!\n");
707 compression_type = wimlib_get_compression_type(dest_w);
710 /* dest_wimfile is not an existing file, so create a new WIM. */
711 if (errno == ENOENT) {
712 ret = wimlib_create_new_wim(compression_type, &dest_w);
716 imagex_error("Cannot stat file `%s': %m\n",
722 image = wimlib_resolve_image(src_w, src_image_num_or_name);
723 ret = verify_image_exists(image);
727 ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
734 ret = wimlib_write(dest_w, dest_wimfile, WIM_ALL_IMAGES,
737 ret = wimlib_overwrite(dest_w, write_flags);
744 /* Prints information about a WIM file; also can mark an image as bootable,
745 * change the name of an image, or change the description of an image. */
746 static int imagex_info(int argc, const char **argv)
752 bool lookup_table = false;
754 bool metadata = false;
755 bool short_header = true;
756 const char *xml_out_file = NULL;
758 const char *image_num_or_name = "all";
759 const char *new_name = NULL;
760 const char *new_desc = NULL;
765 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS |
766 WIMLIB_OPEN_FLAG_SPLIT_OK;
770 for_opt(c, info_options) {
780 short_header = false;
784 short_header = false;
788 short_header = false;
791 xml_out_file = optarg;
792 short_header = false;
796 short_header = false;
806 if (argc == 0 || argc > 4) {
812 image_num_or_name = argv[1];
822 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
824 ret = wimlib_open_wim(wimfile, open_flags, &w);
828 part_number = wimlib_get_part_number(w, &total_parts);
830 /*if (total_parts > 1 && part_number > 1) {*/
831 /*printf("Warning: this is part %d of a %d-part split WIM.\n"*/
832 /*" Select the first part if you want to see information\n"*/
833 /*" about images in the WIM.\n", */
834 /*part_number, total_parts);*/
837 image = wimlib_resolve_image(w, image_num_or_name);
838 if (image == WIM_NO_IMAGE && strcmp(image_num_or_name, "0") != 0) {
839 imagex_error("The image `%s' does not exist!\n",
842 imagex_error("If you would like to set the boot "
843 "index to 0, specify image \"0\" with "
844 "the --boot flag.\n");
845 ret = WIMLIB_ERR_INVALID_IMAGE;
849 if (image == WIM_ALL_IMAGES && wimlib_get_num_images(w) > 1) {
851 imagex_error("Cannot specify the --boot flag "
852 "without specifying a specific "
853 "image in a multi-image WIM!\n");
854 ret = WIMLIB_ERR_INVALID_IMAGE;
858 imagex_error("Cannot specify the NEW_NAME "
859 "without specifying a specific "
860 "image in a multi-image WIM!\n");
861 ret = WIMLIB_ERR_INVALID_IMAGE;
866 /* Operations that print information are separated from operations that
867 * recreate the WIM file. */
868 if (!new_name && !boot) {
870 if (image == WIM_NO_IMAGE) {
871 imagex_error("`%s' is not a valid image!\n",
873 ret = WIMLIB_ERR_INVALID_IMAGE;
877 if (image == WIM_ALL_IMAGES && short_header)
878 wimlib_print_wim_information(w);
881 wimlib_print_header(w);
884 if (total_parts != 1) {
885 printf("Warning: Only showing the lookup table "
886 "for part %d of a %d-part WIM.\n",
887 part_number, total_parts);
889 wimlib_print_lookup_table(w);
893 ret = wimlib_extract_xml_data(w, stdout);
899 fp = fopen(xml_out_file, "wb");
901 imagex_error("Failed to open the file `%s' for "
902 "writing: %m\n", xml_out_file);
905 ret = wimlib_extract_xml_data(w, fp);
906 if (fclose(fp) != 0) {
907 imagex_error("Failed to close the "
918 wimlib_print_available_images(w, image);
921 if (total_parts != 1 && part_number != 1) {
922 imagex_error("Select part 1 of this %d-part WIM "
923 "to see the image metadata.\n",
925 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
927 ret = wimlib_print_metadata(w, image);
932 if (total_parts != 1) {
933 imagex_error("Modifying a split WIM is not supported.\n");
936 if (image == WIM_ALL_IMAGES)
939 if (image == WIM_NO_IMAGE && new_name) {
940 imagex_error("Cannot specify new_name (`%s') when "
946 if (image == wimlib_get_boot_idx(w)) {
947 printf("Image %d is already marked as "
948 "bootable.\n", image);
951 printf("Marking image %d as bootable.\n",
953 wimlib_set_boot_idx(w, image);
957 if (strcmp(wimlib_get_image_name(w, image),
959 printf("Image %d is already named \"%s\".\n",
963 printf("Changing the name of image %d to \"%s\".\n",
965 ret = wimlib_set_image_name(w, image, new_name);
971 const char *old_desc;
972 old_desc = wimlib_get_image_description(w, image);
973 if (old_desc && strcmp(old_desc, new_desc) == 0) {
974 printf("The description of image %d is already "
975 "\"%s\".\n", image, new_desc);
978 printf("Changing the description of image %d "
979 "to \"%s\".\n", image, new_desc);
980 ret = wimlib_set_image_descripton(w, image,
987 /* Only call wimlib_overwrite_xml_and_header() if something
988 * actually needs to be changed. */
989 if (boot || new_name || new_desc ||
990 check != wimlib_has_integrity_table(w)) {
992 ret = wimlib_overwrite_xml_and_header(w, check ?
993 WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
994 WIMLIB_WRITE_FLAG_SHOW_PROGRESS : 0);
996 printf("The file `%s' was not modified because nothing "
997 "needed to be done.\n", wimfile);
1007 /* Join split WIMs into one part WIM */
1008 static int imagex_join(int argc, const char **argv)
1011 int flags = WIMLIB_OPEN_FLAG_SPLIT_OK | WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1014 const char *output_path;
1016 for_opt(c, join_options) {
1019 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1029 imagex_error("Must specify at least one split WIM "
1030 "(.swm) parts to join!\n");
1033 output_path = argv[0];
1034 return wimlib_join(++argv, --argc, output_path, flags);
1040 /* Mounts an image using a FUSE mount. */
1041 static int imagex_mount_rw_or_ro(int argc, const char **argv)
1045 int mount_flags = 0;
1046 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1047 const char *wimfile;
1054 if (strcmp(argv[0], "mountrw") == 0)
1055 mount_flags |= WIMLIB_MOUNT_FLAG_READWRITE;
1056 for_opt(c, mount_options) {
1059 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1062 mount_flags |= WIMLIB_MOUNT_FLAG_DEBUG;
1065 usage(ro ? MOUNT : MOUNTRW);
1071 if (argc != 2 && argc != 3) {
1072 usage(ro ? MOUNT : MOUNTRW);
1078 ret = wimlib_open_wim(wimfile, open_flags, &w);
1084 num_images = wimlib_get_num_images(w);
1085 if (num_images != 1) {
1086 imagex_error("The file `%s' contains %d images; Please "
1087 "select one.\n", wimfile, num_images);
1088 usage(ro ? MOUNT : MOUNTRW);
1089 ret = WIMLIB_ERR_INVALID_IMAGE;
1094 image = wimlib_resolve_image(w, argv[1]);
1098 ret = verify_image_exists_and_is_single(image);
1102 ret = wimlib_mount(w, image, dir, mount_flags);
1104 imagex_error("Failed to mount image %d from `%s' on `%s'!\n",
1105 image, wimfile, dir);
1113 /* Split a WIM into a spanned set */
1114 static int imagex_split(int argc, const char **argv)
1117 int flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1118 unsigned long part_size;
1120 for_opt(c, split_options) {
1123 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1137 part_size = strtoul(argv[2], NULL, 10) * (1 << 20);
1138 return wimlib_split(argv[0], argv[1], part_size, flags);
1141 /* Unmounts an image. */
1142 static int imagex_unmount(int argc, const char **argv)
1145 int unmount_flags = 0;
1148 for_opt(c, unmount_options) {
1151 unmount_flags |= WIMLIB_UNMOUNT_FLAG_COMMIT;
1154 unmount_flags |= WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY;
1168 ret = wimlib_unmount(argv[0], unmount_flags);
1170 imagex_error("Failed to unmount `%s'!\n", argv[0]);
1174 struct imagex_command {
1176 int (*func)(int , const char **);
1180 static struct imagex_command imagex_commands[] = {
1181 {"append", imagex_append, APPEND},
1182 {"apply", imagex_apply, APPLY},
1183 {"capture", imagex_capture, CAPTURE},
1184 {"delete", imagex_delete, DELETE},
1185 {"dir", imagex_dir, DIR},
1186 {"export", imagex_export, EXPORT},
1187 {"info", imagex_info, INFO},
1188 {"join", imagex_join, JOIN},
1189 {"mount", imagex_mount_rw_or_ro, MOUNT},
1190 {"mountrw", imagex_mount_rw_or_ro, MOUNTRW},
1191 {"split", imagex_split, SPLIT},
1192 {"unmount", imagex_unmount, UNMOUNT},
1195 #define for_imagex_command(p) for (p = &imagex_commands[0]; \
1196 p != &imagex_commands[ARRAY_LEN(imagex_commands)]; p++)
1198 static void help_or_version(int argc, const char **argv)
1202 struct imagex_command *cmd;
1204 for (i = 1; i < argc; i++) {
1212 if (strcmp(p, "help") == 0 || (*p == '?' && *(p + 1) == '\0')) {
1213 for_imagex_command(cmd) {
1214 if (strcmp(cmd->name, argv[1]) == 0) {
1222 if (strcmp(p, "version") == 0) {
1230 int main(int argc, const char **argv)
1232 struct imagex_command *cmd;
1236 imagex_error("No command specified!\n");
1241 help_or_version(argc, argv);
1245 wimlib_set_print_errors(true);
1247 for_imagex_command(cmd) {
1248 if (strcmp(cmd->name, *argv) == 0) {
1249 ret = cmd->func(argc, argv);
1251 imagex_error("Exiting with error code %d:\n"
1253 wimlib_get_error_string(ret));
1259 imagex_error("Unrecognized command: `%s'\n", argv[0]);