4 * Use wimlib to create, modify, extract, mount, unmount, or display information
9 * Copyright (C) 2012 Eric Biggers
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 #define ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
36 #define swap(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); \
39 #define for_opt(c, opts) while ((c = getopt_long_only(argc, (char**)argv, "", \
57 static const char *path_basename(const char *path)
64 /* Trailing slashes. */
65 while ((p != path - 1) && *p == '/')
68 while ((p != path - 1) && *p != '/')
75 static const char *usage_strings[] = {
77 " imagex append DIRECTORY WIMFILE [\"IMAGE_NAME\"] [\"DESCRIPTION\"] [--boot]\n"
78 " [--check] [--config CONFIG_FILE] [--flags EDITIONID] [--verify]\n",
80 " imagex apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all] DIRECTORY [--check]\n"
81 " [--verify] [--hardlink] [--symlink] [--verbose]\n",
83 " imagex capture DIRECTORY WIMFILE [\"IMAGE_NAME\"] [\"DESCRIPTION\"]\n"
84 " [--boot] [--check] [--compress[=TYPE]] [--config CONFIG_FILE]\n"
85 " [--flags \"EditionID\"] [--norpfix] [--verify] [--verbose]\n",
87 " imagex delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check]\n",
89 " imagex dir WIMFILE (IMAGE_NUM | IMAGE_NAME | \"all\")\n",
91 " imagex export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n"
92 " DEST_WIMFILE [\"DEST_IMAGE_NAME\"] [\"DEST_IMAGE_DESCRIPTION\"]\n"
93 " [--boot] [--check] [--compress[=TYPE]]\n",
95 " imagex info WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n"
96 " [NEW_DESC] [--boot] [--check] [--header] [--lookup-table]\n"
97 " [--xml] [--extract-xml FILE] [--metadata]\n",
99 " imagex join [--check] WIMFILE SPLIT_WIM...\n",
101 " imagex mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n"
102 " [--check] [--debug]\n",
104 " imagex mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
105 " [--check] [--debug]\n",
107 " imagex split WIMFILE SPLIT_WIMFILE PART_SIZE [--check]\n",
109 " imagex unmount DIRECTORY [--commit] [--check]\n",
112 static const struct option common_options[] = {
113 {"help", 0, NULL, 'h'},
114 {"version", 0, NULL, 'v'},
118 static const struct option append_options[] = {
119 {"boot", no_argument, NULL, 'b'},
120 {"check", no_argument, NULL, 'c'},
121 {"config", required_argument, NULL, 'C'},
122 {"flags", required_argument, NULL, 'f'},
123 {"verify", no_argument, NULL, 'V'},
126 static const struct option apply_options[] = {
127 {"check", no_argument, NULL, 'c'},
128 {"verify", no_argument, NULL, 'V'},
129 {"hardlink", no_argument, NULL, 'h'},
130 {"symlink", no_argument, NULL, 's'},
131 {"verbose", no_argument, NULL, 'v'},
134 static const struct option capture_options[] = {
135 {"boot", no_argument, NULL, 'b'},
136 {"check", no_argument, NULL, 'c'},
137 {"compress", optional_argument, NULL, 'x'},
138 {"config", required_argument, NULL, 'C'},
139 {"flags", required_argument, NULL, 'f'},
140 {"norpfix", no_argument, NULL, 'n'},
141 {"verify", no_argument, NULL, 'V'},
142 {"verbose", no_argument, NULL, 'v'},
145 static const struct option delete_options[] = {
146 {"check", no_argument, NULL, 'c'},
150 static const struct option export_options[] = {
151 {"boot", no_argument, NULL, 'b'},
152 {"check", no_argument , NULL, 'c'},
153 {"compress", optional_argument, NULL, 'x'},
157 static const struct option info_options[] = {
158 {"boot", no_argument, NULL, 'b'},
159 {"check", no_argument, NULL, 'c'},
160 {"header", no_argument, NULL, 'h'},
161 {"lookup-table", no_argument, NULL, 'l'},
162 {"xml", no_argument, NULL, 'x'},
163 {"extract-xml", required_argument, NULL, 'X'},
164 {"metadata", no_argument, NULL, 'm'},
168 static const struct option join_options[] = {
169 {"check", no_argument, NULL, 'c'},
173 static const struct option mount_options[] = {
174 {"check", no_argument, NULL, 'c'},
175 {"debug", no_argument, NULL, 'd'},
179 static const struct option split_options[] = {
180 {"check", no_argument, NULL, 'c'},
184 static const struct option unmount_options[] = {
185 {"commit", no_argument, NULL, 'c'},
186 {"check", no_argument, NULL, 'C'},
191 /* Print formatted error message to stderr. */
192 static void imagex_error(const char *format, ...)
195 va_start(va, format);
196 fputs("ERROR: ", stderr);
197 vfprintf(stderr, format, va);
202 static inline void version()
204 static const char *s =
205 "imagex (" PACKAGE ") " PACKAGE_VERSION "\n"
206 "Copyright (C) 2012 Eric Biggers\n"
207 "License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
208 "This is free software: you are free to change and redistribute it.\n"
209 "There is NO WARRANTY, to the extent permitted by law.\n"
211 "Report bugs to "PACKAGE_BUGREPORT".\n";
215 static inline void usage(int cmd)
217 puts("IMAGEX: Usage:");
218 fputs(usage_strings[cmd], stdout);
221 static void usage_all()
223 puts("IMAGEX: Usage:");
224 for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
225 fputs(usage_strings[i], stdout);
226 static const char *extra =
228 " imagex --version\n"
230 " The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
232 fputs(extra, stdout);
235 static int verify_image_exists(int image)
237 if (image == WIM_NO_IMAGE) {
238 imagex_error("Not a valid image!\n");
239 return WIMLIB_ERR_INVALID_IMAGE;
244 static int verify_image_is_single(int image)
246 if (image == WIM_ALL_IMAGES) {
247 imagex_error("Cannot specify all images for this action!\n");
248 return WIMLIB_ERR_INVALID_IMAGE;
253 static int verify_image_exists_and_is_single(int image)
256 ret = verify_image_exists(image);
258 ret = verify_image_is_single(image);
262 static int get_compression_type(const char *optarg)
265 return WIM_COMPRESSION_TYPE_LZX;
266 if (strcasecmp(optarg, "maximum") == 0 || strcasecmp(optarg, "lzx") == 0)
267 return WIM_COMPRESSION_TYPE_LZX;
268 else if (strcasecmp(optarg, "fast") == 0 || strcasecmp(optarg, "xpress") == 0)
269 return WIM_COMPRESSION_TYPE_XPRESS;
270 else if (strcasecmp(optarg, "none") == 0)
271 return WIM_COMPRESSION_TYPE_NONE;
273 imagex_error("Invalid compression type `%s'! Must be "
274 "\"maximum\", \"fast\", or \"none\".\n",
276 return WIM_COMPRESSION_TYPE_INVALID;
280 static int imagex_append(int argc, const char **argv)
283 const char *flags_element = NULL;
284 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
285 int add_image_flags = 0;
286 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
294 for_opt(c, append_options) {
297 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
300 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
301 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
307 flags_element = optarg;
319 if (argc < 2 || argc > 4) {
325 name = (argc >= 3) ? argv[2] : path_basename(dir);
326 desc = (argc >= 4) ? argv[3] : NULL;
328 ret = wimlib_open_wim(wimfile, open_flags, &w);
332 ret = wimlib_add_image(w, dir, name, desc,
333 flags_element, add_image_flags);
336 ret = wimlib_overwrite(w, write_flags);
342 /* Extract one image, or all images, from a WIM file into a directory. */
343 static int imagex_apply(int argc, const char **argv)
346 int link_type = WIM_LINK_TYPE_NONE;
347 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
348 bool verbose = false;
355 const char *image_num_or_name;
357 for_opt(c, apply_options) {
360 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
366 link_type = WIM_LINK_TYPE_HARD;
369 link_type = WIM_LINK_TYPE_SYMBOLIC;
381 if (argc != 2 && argc != 3) {
388 image_num_or_name = "1";
391 image_num_or_name = argv[1];
395 ret = wimlib_open_wim(wimfile, open_flags, &w);
399 image = wimlib_resolve_image(w, image_num_or_name);
400 ret = verify_image_exists(image);
404 num_images = wimlib_get_num_images(w);
405 if (argc == 2 && num_images != 1) {
406 imagex_error("`%s' contains %d images; Please select one "
407 "(or all).\n", wimfile, num_images);
412 ret = wimlib_set_output_dir(w, dir);
415 wimlib_set_verbose(w, verbose);
416 wimlib_set_link_type(w, link_type);
417 ret = wimlib_extract_image(w, image);
424 /* Create a WIM file from a directory. */
425 static int imagex_capture(int argc, const char **argv)
428 int add_image_flags = 0;
429 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
430 int compression_type = WIM_COMPRESSION_TYPE_NONE;
431 const char *flags_element = NULL;
432 bool verbose = false;
440 for_opt(c, capture_options) {
443 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
446 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
449 compression_type = get_compression_type(optarg);
450 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
457 flags_element = optarg;
476 if (argc < 2 || argc > 4) {
482 name = (argc >= 3) ? argv[2] : dir;
483 desc = (argc >= 4) ? argv[3] : NULL;
485 ret = wimlib_create_new_wim(compression_type, &w);
489 wimlib_set_verbose(w, verbose);
491 ret = wimlib_add_image(w, dir, name, desc, flags_element,
494 imagex_error("Failed to add the image `%s'!\n", dir);
498 ret = wimlib_write(w, wimfile, WIM_ALL_IMAGES, write_flags);
500 imagex_error("Failed to write the WIM file `%s'!\n", wimfile);
506 /* Remove image(s) from a WIM. */
507 static int imagex_delete(int argc, const char **argv)
510 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
511 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
513 const char *image_num_or_name;
518 for_opt(c, delete_options) {
521 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
522 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
534 imagex_error("Must specify a WIM file!\n");
536 imagex_error("Must specify an image!\n");
541 image_num_or_name = argv[1];
543 ret = wimlib_open_wim(wimfile, open_flags, &w);
547 image = wimlib_resolve_image(w, image_num_or_name);
549 ret = verify_image_exists(image);
553 ret = wimlib_delete_image(w, image);
555 imagex_error("Failed to delete image from `%s'!\n",
560 ret = wimlib_overwrite(w, write_flags);
562 imagex_error("Failed to write the file `%s' with image "
563 "deleted!\n", wimfile);
570 /* Print the files contained in an image(s) in a WIM file. */
571 static int imagex_dir(int argc, const char **argv)
581 imagex_error("Must specify a WIM file!\n");
586 imagex_error("Too many arguments!\n");
592 ret = wimlib_open_wim(wimfile, WIMLIB_OPEN_FLAG_SPLIT_OK, &w);
596 part_number = wimlib_get_part_number(w, NULL);
597 if (part_number != 1) {
598 imagex_error("`%s' is part %d of a split WIM! Specify the first part "
599 "to see the files.\n",
600 wimfile, part_number);
601 ret = WIMLIB_ERR_SPLIT_UNSUPPORTED;
606 image = wimlib_resolve_image(w, argv[2]);
607 ret = verify_image_exists(image);
611 /* Image was not specified. If the WIM only contains one image,
612 * choose that one; otherwise, print an error. */
613 num_images = wimlib_get_num_images(w);
614 if (num_images != 1) {
615 imagex_error("The file `%s' contains %d images; Please "
616 "select one.\n", wimfile, num_images);
624 ret = wimlib_print_files(w, image);
630 /* Exports one, or all, images from a WIM file to a new WIM file or an existing
632 static int imagex_export(int argc, const char **argv)
635 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
636 int export_flags = 0;
637 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
638 int compression_type = WIM_COMPRESSION_TYPE_NONE;
639 bool compression_type_specified = false;
640 const char *src_wimfile;
641 const char *src_image_num_or_name;
642 const char *dest_wimfile;
643 const char *dest_name;
644 const char *dest_desc;
645 WIMStruct *src_w = NULL;
646 WIMStruct *dest_w = NULL;
652 for_opt(c, export_options) {
655 export_flags |= WIMLIB_EXPORT_FLAG_BOOT;
658 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
659 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
662 compression_type = get_compression_type(optarg);
663 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
665 compression_type_specified = true;
674 if (argc < 3 || argc > 5) {
678 src_wimfile = argv[0];
679 src_image_num_or_name = argv[1];
680 dest_wimfile = argv[2];
681 dest_name = (argc >= 4) ? argv[3] : NULL;
682 dest_desc = (argc >= 5) ? argv[4] : NULL;
683 ret = wimlib_open_wim(src_wimfile, open_flags, &src_w);
687 /* Determine if the destination is an existing file or not.
688 * If so, we try to append the exported image(s) to it; otherwise, we
689 * create a new WIM containing the exported image(s). */
690 if (stat(dest_wimfile, &stbuf) == 0) {
692 /* Destination file exists. */
693 if (!S_ISREG(stbuf.st_mode)) {
694 imagex_error("`%s' is not a regular file!\n",
698 ret = wimlib_open_wim(dest_wimfile, open_flags, &dest_w);
702 if (compression_type_specified && compression_type !=
703 wimlib_get_compression_type(dest_w)) {
704 imagex_error("Cannot specify a compression type that is "
705 "not the same as that used in the "
706 "destination WIM!\n");
709 compression_type = wimlib_get_compression_type(dest_w);
712 /* dest_wimfile is not an existing file, so create a new WIM. */
713 if (errno == ENOENT) {
714 ret = wimlib_create_new_wim(compression_type, &dest_w);
718 imagex_error("Cannot stat file `%s': %m\n",
724 image = wimlib_resolve_image(src_w, src_image_num_or_name);
725 ret = verify_image_exists(image);
729 ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
736 ret = wimlib_write(dest_w, dest_wimfile, WIM_ALL_IMAGES,
739 ret = wimlib_overwrite(dest_w, write_flags);
746 /* Prints information about a WIM file; also can mark an image as bootable,
747 * change the name of an image, or change the description of an image. */
748 static int imagex_info(int argc, const char **argv)
754 bool lookup_table = false;
756 bool metadata = false;
757 bool short_header = true;
758 const char *xml_out_file = NULL;
760 const char *image_num_or_name = "all";
761 const char *new_name = NULL;
762 const char *new_desc = NULL;
767 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS |
768 WIMLIB_OPEN_FLAG_SPLIT_OK;
772 for_opt(c, info_options) {
782 short_header = false;
786 short_header = false;
790 short_header = false;
793 xml_out_file = optarg;
794 short_header = false;
798 short_header = false;
808 if (argc == 0 || argc > 4) {
814 image_num_or_name = argv[1];
824 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
826 ret = wimlib_open_wim(wimfile, open_flags, &w);
830 part_number = wimlib_get_part_number(w, &total_parts);
832 /*if (total_parts > 1 && part_number > 1) {*/
833 /*printf("Warning: this is part %d of a %d-part split WIM.\n"*/
834 /*" Select the first part if you want to see information\n"*/
835 /*" about images in the WIM.\n", */
836 /*part_number, total_parts);*/
839 image = wimlib_resolve_image(w, image_num_or_name);
840 if (image == WIM_NO_IMAGE && strcmp(image_num_or_name, "0") != 0) {
841 imagex_error("The image `%s' does not exist!\n",
844 imagex_error("If you would like to set the boot "
845 "index to 0, specify image \"0\" with "
846 "the --boot flag.\n");
847 ret = WIMLIB_ERR_INVALID_IMAGE;
851 if (image == WIM_ALL_IMAGES && wimlib_get_num_images(w) > 1) {
853 imagex_error("Cannot specify the --boot flag "
854 "without specifying a specific "
855 "image in a multi-image WIM!\n");
856 ret = WIMLIB_ERR_INVALID_IMAGE;
860 imagex_error("Cannot specify the NEW_NAME "
861 "without specifying a specific "
862 "image in a multi-image WIM!\n");
863 ret = WIMLIB_ERR_INVALID_IMAGE;
868 /* Operations that print information are separated from operations that
869 * recreate the WIM file. */
870 if (!new_name && !boot) {
872 if (image == WIM_NO_IMAGE) {
873 imagex_error("`%s' is not a valid image!\n",
875 ret = WIMLIB_ERR_INVALID_IMAGE;
879 if (image == WIM_ALL_IMAGES && short_header)
880 wimlib_print_wim_information(w);
883 wimlib_print_header(w);
886 if (total_parts != 1) {
887 printf("Warning: Only showing the lookup table "
888 "for part %d of a %d-part WIM.\n",
889 part_number, total_parts);
891 wimlib_print_lookup_table(w);
895 ret = wimlib_extract_xml_data(w, stdout);
901 fp = fopen(xml_out_file, "wb");
903 imagex_error("Failed to open the file `%s' for "
904 "writing: %m\n", xml_out_file);
907 ret = wimlib_extract_xml_data(w, fp);
908 if (fclose(fp) != 0) {
909 imagex_error("Failed to close the "
920 wimlib_print_available_images(w, image);
923 if (total_parts != 1 && part_number != 1) {
924 imagex_error("Select part 1 of this %d-part WIM "
925 "to see the image metadata.\n",
927 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
929 ret = wimlib_print_metadata(w, image);
934 if (total_parts != 1) {
935 imagex_error("Modifying a split WIM is not supported.\n");
938 if (image == WIM_ALL_IMAGES)
941 if (image == WIM_NO_IMAGE && new_name) {
942 imagex_error("Cannot specify new_name (`%s') when "
948 if (image == wimlib_get_boot_idx(w)) {
949 printf("Image %d is already marked as "
950 "bootable.\n", image);
953 printf("Marking image %d as bootable.\n",
955 wimlib_set_boot_idx(w, image);
959 if (strcmp(wimlib_get_image_name(w, image),
961 printf("Image %d is already named \"%s\".\n",
965 printf("Changing the name of image %d to \"%s\".\n",
967 ret = wimlib_set_image_name(w, image, new_name);
973 const char *old_desc;
974 old_desc = wimlib_get_image_description(w, image);
975 if (old_desc && strcmp(old_desc, new_desc) == 0) {
976 printf("The description of image %d is already "
977 "\"%s\".\n", image, new_desc);
980 printf("Changing the description of image %d "
981 "to \"%s\".\n", image, new_desc);
982 ret = wimlib_set_image_descripton(w, image,
989 /* Only call wimlib_overwrite_xml_and_header() if something
990 * actually needs to be changed. */
991 if (boot || new_name || new_desc ||
992 check != wimlib_has_integrity_table(w)) {
994 ret = wimlib_overwrite_xml_and_header(w, check ?
995 WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
996 WIMLIB_WRITE_FLAG_SHOW_PROGRESS : 0);
998 printf("The file `%s' was not modified because nothing "
999 "needed to be done.\n", wimfile);
1009 /* Join split WIMs into one part WIM */
1010 static int imagex_join(int argc, const char **argv)
1013 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)
1044 int mount_flags = 0;
1045 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1046 const char *wimfile;
1053 if (strcmp(argv[0], "mountrw") == 0)
1054 mount_flags |= WIMLIB_MOUNT_FLAG_READWRITE;
1055 for_opt(c, mount_options) {
1058 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1061 mount_flags |= WIMLIB_MOUNT_FLAG_DEBUG;
1064 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1071 if (argc != 2 && argc != 3) {
1072 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1079 ret = wimlib_open_wim(wimfile, open_flags, &w);
1085 num_images = wimlib_get_num_images(w);
1086 if (num_images != 1) {
1087 imagex_error("The file `%s' contains %d images; Please "
1088 "select one.\n", wimfile, num_images);
1089 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1091 ret = WIMLIB_ERR_INVALID_IMAGE;
1096 image = wimlib_resolve_image(w, argv[1]);
1100 ret = verify_image_exists_and_is_single(image);
1104 ret = wimlib_mount(w, image, dir, mount_flags);
1106 imagex_error("Failed to mount image %d from `%s' on `%s'!\n",
1107 image, wimfile, dir);
1115 /* Split a WIM into a spanned set */
1116 static int imagex_split(int argc, const char **argv)
1119 int flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1120 unsigned long part_size;
1122 for_opt(c, split_options) {
1125 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1139 part_size = strtoul(argv[2], NULL, 10) * (1 << 20);
1140 return wimlib_split(argv[0], argv[1], part_size, flags);
1143 /* Unmounts an image. */
1144 static int imagex_unmount(int argc, const char **argv)
1147 int unmount_flags = 0;
1150 for_opt(c, unmount_options) {
1153 unmount_flags |= WIMLIB_UNMOUNT_FLAG_COMMIT;
1156 unmount_flags |= WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY;
1170 ret = wimlib_unmount(argv[0], unmount_flags);
1172 imagex_error("Failed to unmount `%s'!\n", argv[0]);
1176 struct imagex_command {
1178 int (*func)(int , const char **);
1182 static struct imagex_command imagex_commands[] = {
1183 {"append", imagex_append, APPEND},
1184 {"apply", imagex_apply, APPLY},
1185 {"capture", imagex_capture, CAPTURE},
1186 {"delete", imagex_delete, DELETE},
1187 {"dir", imagex_dir, DIR},
1188 {"export", imagex_export, EXPORT},
1189 {"info", imagex_info, INFO},
1190 {"join", imagex_join, JOIN},
1191 {"mount", imagex_mount_rw_or_ro, MOUNT},
1192 {"mountrw", imagex_mount_rw_or_ro, MOUNTRW},
1193 {"split", imagex_split, SPLIT},
1194 {"unmount", imagex_unmount, UNMOUNT},
1197 #define for_imagex_command(p) for (p = &imagex_commands[0]; \
1198 p != &imagex_commands[ARRAY_LEN(imagex_commands)]; p++)
1200 static void help_or_version(int argc, const char **argv)
1204 struct imagex_command *cmd;
1206 for (i = 1; i < argc; i++) {
1214 if (strcmp(p, "help") == 0 || (*p == '?' && *(p + 1) == '\0')) {
1215 for_imagex_command(cmd) {
1216 if (strcmp(cmd->name, argv[1]) == 0) {
1224 if (strcmp(p, "version") == 0) {
1232 int main(int argc, const char **argv)
1234 struct imagex_command *cmd;
1238 imagex_error("No command specified!\n");
1243 help_or_version(argc, argv);
1247 wimlib_set_print_errors(true);
1249 for_imagex_command(cmd) {
1250 if (strcmp(cmd->name, *argv) == 0) {
1251 ret = cmd->func(argc, argv);
1253 imagex_error("Exiting with error code %d:\n"
1255 wimlib_get_error_string(ret));
1261 imagex_error("Unrecognized command: `%s'\n", argv[0]);