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 /* Print formatted error message to stderr. */
203 static void imagex_error_with_errno(const char *format, ...)
205 int errno_save = errno;
207 va_start(va, format);
208 fputs("ERROR: ", stderr);
209 vfprintf(stderr, format, va);
210 fprintf(stderr, ": %s\n", strerror(errno_save));
215 static inline void version()
217 static const char *s =
218 "imagex (" PACKAGE ") " PACKAGE_VERSION "\n"
219 "Copyright (C) 2012 Eric Biggers\n"
220 "License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
221 "This is free software: you are free to change and redistribute it.\n"
222 "There is NO WARRANTY, to the extent permitted by law.\n"
224 "Report bugs to "PACKAGE_BUGREPORT".\n";
228 static inline void usage(int cmd)
230 puts("IMAGEX: Usage:");
231 fputs(usage_strings[cmd], stdout);
234 static void usage_all()
236 puts("IMAGEX: Usage:");
237 for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
238 fputs(usage_strings[i], stdout);
239 static const char *extra =
241 " imagex --version\n"
243 " The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
245 fputs(extra, stdout);
248 static int verify_image_exists(int image)
250 if (image == WIM_NO_IMAGE) {
251 imagex_error("Not a valid image");
252 return WIMLIB_ERR_INVALID_IMAGE;
257 static int verify_image_is_single(int image)
259 if (image == WIM_ALL_IMAGES) {
260 imagex_error("Cannot specify all images for this action");
261 return WIMLIB_ERR_INVALID_IMAGE;
266 static int verify_image_exists_and_is_single(int image)
269 ret = verify_image_exists(image);
271 ret = verify_image_is_single(image);
275 static int get_compression_type(const char *optarg)
278 return WIM_COMPRESSION_TYPE_LZX;
279 if (strcasecmp(optarg, "maximum") == 0 || strcasecmp(optarg, "lzx") == 0)
280 return WIM_COMPRESSION_TYPE_LZX;
281 else if (strcasecmp(optarg, "fast") == 0 || strcasecmp(optarg, "xpress") == 0)
282 return WIM_COMPRESSION_TYPE_XPRESS;
283 else if (strcasecmp(optarg, "none") == 0)
284 return WIM_COMPRESSION_TYPE_NONE;
286 imagex_error("Invalid compression type `%s'! Must be "
287 "\"maximum\", \"fast\", or \"none\".", optarg);
288 return WIM_COMPRESSION_TYPE_INVALID;
292 static int imagex_append(int argc, const char **argv)
295 const char *flags_element = NULL;
296 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
297 int add_image_flags = 0;
298 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
306 for_opt(c, append_options) {
309 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
312 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
313 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
319 flags_element = optarg;
331 if (argc < 2 || argc > 4) {
337 name = (argc >= 3) ? argv[2] : path_basename(dir);
338 desc = (argc >= 4) ? argv[3] : NULL;
340 ret = wimlib_open_wim(wimfile, open_flags, &w);
344 ret = wimlib_add_image(w, dir, name, desc,
345 flags_element, add_image_flags);
348 ret = wimlib_overwrite(w, write_flags);
354 /* Extract one image, or all images, from a WIM file into a directory. */
355 static int imagex_apply(int argc, const char **argv)
358 int link_type = WIM_LINK_TYPE_NONE;
359 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
360 bool verbose = false;
367 const char *image_num_or_name;
369 for_opt(c, apply_options) {
372 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
378 link_type = WIM_LINK_TYPE_HARD;
381 link_type = WIM_LINK_TYPE_SYMBOLIC;
393 if (argc != 2 && argc != 3) {
400 image_num_or_name = "1";
403 image_num_or_name = argv[1];
407 ret = wimlib_open_wim(wimfile, open_flags, &w);
411 image = wimlib_resolve_image(w, image_num_or_name);
412 ret = verify_image_exists(image);
416 num_images = wimlib_get_num_images(w);
417 if (argc == 2 && num_images != 1) {
418 imagex_error("`%s' contains %d images; Please select one "
419 "(or all)", wimfile, num_images);
424 ret = wimlib_set_output_dir(w, dir);
427 wimlib_set_verbose(w, verbose);
428 wimlib_set_link_type(w, link_type);
429 ret = wimlib_extract_image(w, image);
436 /* Create a WIM file from a directory. */
437 static int imagex_capture(int argc, const char **argv)
440 int add_image_flags = 0;
441 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
442 int compression_type = WIM_COMPRESSION_TYPE_NONE;
443 const char *flags_element = NULL;
444 bool verbose = false;
452 for_opt(c, capture_options) {
455 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
458 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
461 compression_type = get_compression_type(optarg);
462 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
469 flags_element = optarg;
488 if (argc < 2 || argc > 4) {
494 name = (argc >= 3) ? argv[2] : dir;
495 desc = (argc >= 4) ? argv[3] : NULL;
497 ret = wimlib_create_new_wim(compression_type, &w);
501 wimlib_set_verbose(w, verbose);
503 ret = wimlib_add_image(w, dir, name, desc, flags_element,
506 imagex_error("Failed to add the image `%s'", dir);
510 ret = wimlib_write(w, wimfile, WIM_ALL_IMAGES, write_flags);
512 imagex_error("Failed to write the WIM file `%s'", wimfile);
518 /* Remove image(s) from a WIM. */
519 static int imagex_delete(int argc, const char **argv)
522 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
523 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
525 const char *image_num_or_name;
530 for_opt(c, delete_options) {
533 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
534 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
546 imagex_error("Must specify a WIM file");
548 imagex_error("Must specify an image");
553 image_num_or_name = argv[1];
555 ret = wimlib_open_wim(wimfile, open_flags, &w);
559 image = wimlib_resolve_image(w, image_num_or_name);
561 ret = verify_image_exists(image);
565 ret = wimlib_delete_image(w, image);
567 imagex_error("Failed to delete image from `%s'", wimfile);
571 ret = wimlib_overwrite(w, write_flags);
573 imagex_error("Failed to write the file `%s' with image "
581 /* Print the files contained in an image(s) in a WIM file. */
582 static int imagex_dir(int argc, const char **argv)
592 imagex_error("Must specify a WIM file");
597 imagex_error("Too many arguments");
603 ret = wimlib_open_wim(wimfile, WIMLIB_OPEN_FLAG_SPLIT_OK, &w);
607 part_number = wimlib_get_part_number(w, NULL);
608 if (part_number != 1) {
609 imagex_error("`%s' is part %d of a split WIM! Specify the "
610 "first part to see the files",
611 wimfile, part_number);
612 ret = WIMLIB_ERR_SPLIT_UNSUPPORTED;
617 image = wimlib_resolve_image(w, argv[2]);
618 ret = verify_image_exists(image);
622 /* Image was not specified. If the WIM only contains one image,
623 * choose that one; otherwise, print an error. */
624 num_images = wimlib_get_num_images(w);
625 if (num_images != 1) {
626 imagex_error("The file `%s' contains %d images; Please "
627 "select one.", wimfile, num_images);
635 ret = wimlib_print_files(w, image);
641 /* Exports one, or all, images from a WIM file to a new WIM file or an existing
643 static int imagex_export(int argc, const char **argv)
646 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
647 int export_flags = 0;
648 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
649 int compression_type = WIM_COMPRESSION_TYPE_NONE;
650 bool compression_type_specified = false;
651 const char *src_wimfile;
652 const char *src_image_num_or_name;
653 const char *dest_wimfile;
654 const char *dest_name;
655 const char *dest_desc;
656 WIMStruct *src_w = NULL;
657 WIMStruct *dest_w = NULL;
663 for_opt(c, export_options) {
666 export_flags |= WIMLIB_EXPORT_FLAG_BOOT;
669 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
670 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
673 compression_type = get_compression_type(optarg);
674 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
676 compression_type_specified = true;
685 if (argc < 3 || argc > 5) {
689 src_wimfile = argv[0];
690 src_image_num_or_name = argv[1];
691 dest_wimfile = argv[2];
692 dest_name = (argc >= 4) ? argv[3] : NULL;
693 dest_desc = (argc >= 5) ? argv[4] : NULL;
694 ret = wimlib_open_wim(src_wimfile, open_flags, &src_w);
698 /* Determine if the destination is an existing file or not.
699 * If so, we try to append the exported image(s) to it; otherwise, we
700 * create a new WIM containing the exported image(s). */
701 if (stat(dest_wimfile, &stbuf) == 0) {
703 /* Destination file exists. */
704 if (!S_ISREG(stbuf.st_mode)) {
705 imagex_error("`%s' is not a regular file",
709 ret = wimlib_open_wim(dest_wimfile, open_flags, &dest_w);
713 if (compression_type_specified && compression_type !=
714 wimlib_get_compression_type(dest_w)) {
715 imagex_error("Cannot specify a compression type that is "
716 "not the same as that used in the "
720 compression_type = wimlib_get_compression_type(dest_w);
723 /* dest_wimfile is not an existing file, so create a new WIM. */
724 if (errno == ENOENT) {
725 ret = wimlib_create_new_wim(compression_type, &dest_w);
729 imagex_error_with_errno("Cannot stat file `%s'",
735 image = wimlib_resolve_image(src_w, src_image_num_or_name);
736 ret = verify_image_exists(image);
740 ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
747 ret = wimlib_write(dest_w, dest_wimfile, WIM_ALL_IMAGES,
750 ret = wimlib_overwrite(dest_w, write_flags);
757 /* Prints information about a WIM file; also can mark an image as bootable,
758 * change the name of an image, or change the description of an image. */
759 static int imagex_info(int argc, const char **argv)
765 bool lookup_table = false;
767 bool metadata = false;
768 bool short_header = true;
769 const char *xml_out_file = NULL;
771 const char *image_num_or_name = "all";
772 const char *new_name = NULL;
773 const char *new_desc = NULL;
778 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS |
779 WIMLIB_OPEN_FLAG_SPLIT_OK;
783 for_opt(c, info_options) {
793 short_header = false;
797 short_header = false;
801 short_header = false;
804 xml_out_file = optarg;
805 short_header = false;
809 short_header = false;
819 if (argc == 0 || argc > 4) {
825 image_num_or_name = argv[1];
835 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
837 ret = wimlib_open_wim(wimfile, open_flags, &w);
841 part_number = wimlib_get_part_number(w, &total_parts);
843 /*if (total_parts > 1 && part_number > 1) {*/
844 /*printf("Warning: this is part %d of a %d-part split WIM.\n"*/
845 /*" Select the first part if you want to see information\n"*/
846 /*" about images in the WIM.\n", */
847 /*part_number, total_parts);*/
850 image = wimlib_resolve_image(w, image_num_or_name);
851 if (image == WIM_NO_IMAGE && strcmp(image_num_or_name, "0") != 0) {
852 imagex_error("The image `%s' does not exist",
855 imagex_error("If you would like to set the boot "
856 "index to 0, specify image \"0\" with "
858 ret = WIMLIB_ERR_INVALID_IMAGE;
862 if (image == WIM_ALL_IMAGES && wimlib_get_num_images(w) > 1) {
864 imagex_error("Cannot specify the --boot flag "
865 "without specifying a specific "
866 "image in a multi-image WIM");
867 ret = WIMLIB_ERR_INVALID_IMAGE;
871 imagex_error("Cannot specify the NEW_NAME "
872 "without specifying a specific "
873 "image in a multi-image WIM");
874 ret = WIMLIB_ERR_INVALID_IMAGE;
879 /* Operations that print information are separated from operations that
880 * recreate the WIM file. */
881 if (!new_name && !boot) {
883 if (image == WIM_NO_IMAGE) {
884 imagex_error("`%s' is not a valid image",
886 ret = WIMLIB_ERR_INVALID_IMAGE;
890 if (image == WIM_ALL_IMAGES && short_header)
891 wimlib_print_wim_information(w);
894 wimlib_print_header(w);
897 if (total_parts != 1) {
898 printf("Warning: Only showing the lookup table "
899 "for part %d of a %d-part WIM.\n",
900 part_number, total_parts);
902 wimlib_print_lookup_table(w);
906 ret = wimlib_extract_xml_data(w, stdout);
912 fp = fopen(xml_out_file, "wb");
914 imagex_error_with_errno("Failed to open the "
920 ret = wimlib_extract_xml_data(w, fp);
921 if (fclose(fp) != 0) {
922 imagex_error("Failed to close the file `%s'",
932 wimlib_print_available_images(w, image);
935 if (total_parts != 1 && part_number != 1) {
936 imagex_error("Select part 1 of this %d-part WIM "
937 "to see the image metadata",
939 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
941 ret = wimlib_print_metadata(w, image);
946 if (total_parts != 1) {
947 imagex_error("Modifying a split WIM is not supported.");
950 if (image == WIM_ALL_IMAGES)
953 if (image == WIM_NO_IMAGE && new_name) {
954 imagex_error("Cannot specify new_name (`%s') when "
955 "using image 0", new_name);
960 if (image == wimlib_get_boot_idx(w)) {
961 printf("Image %d is already marked as "
962 "bootable.\n", image);
965 printf("Marking image %d as bootable.\n",
967 wimlib_set_boot_idx(w, image);
971 if (strcmp(wimlib_get_image_name(w, image),
973 printf("Image %d is already named \"%s\".\n",
977 printf("Changing the name of image %d to "
978 "\"%s\".\n", image, new_name);
979 ret = wimlib_set_image_name(w, image, new_name);
985 const char *old_desc;
986 old_desc = wimlib_get_image_description(w, image);
987 if (old_desc && strcmp(old_desc, new_desc) == 0) {
988 printf("The description of image %d is already "
989 "\"%s\".\n", image, new_desc);
992 printf("Changing the description of image %d "
993 "to \"%s\".\n", image, new_desc);
994 ret = wimlib_set_image_descripton(w, image,
1001 /* Only call wimlib_overwrite_xml_and_header() if something
1002 * actually needs to be changed. */
1003 if (boot || new_name || new_desc ||
1004 check != wimlib_has_integrity_table(w)) {
1006 ret = wimlib_overwrite_xml_and_header(w, check ?
1007 WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
1008 WIMLIB_WRITE_FLAG_SHOW_PROGRESS : 0);
1010 printf("The file `%s' was not modified because nothing "
1011 "needed to be done.\n", wimfile);
1021 /* Join split WIMs into one part WIM */
1022 static int imagex_join(int argc, const char **argv)
1025 int flags = WIMLIB_OPEN_FLAG_SPLIT_OK | WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1026 const char *output_path;
1028 for_opt(c, join_options) {
1031 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1041 imagex_error("Must specify at least one split WIM (.swm) parts "
1045 output_path = argv[0];
1046 return wimlib_join(++argv, --argc, output_path, flags);
1052 /* Mounts an image using a FUSE mount. */
1053 static int imagex_mount_rw_or_ro(int argc, const char **argv)
1056 int mount_flags = 0;
1057 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1058 const char *wimfile;
1065 if (strcmp(argv[0], "mountrw") == 0)
1066 mount_flags |= WIMLIB_MOUNT_FLAG_READWRITE;
1067 for_opt(c, mount_options) {
1070 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1073 mount_flags |= WIMLIB_MOUNT_FLAG_DEBUG;
1076 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1083 if (argc != 2 && argc != 3) {
1084 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1091 ret = wimlib_open_wim(wimfile, open_flags, &w);
1097 num_images = wimlib_get_num_images(w);
1098 if (num_images != 1) {
1099 imagex_error("The file `%s' contains %d images; Please "
1100 "select one", wimfile, num_images);
1101 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1103 ret = WIMLIB_ERR_INVALID_IMAGE;
1108 image = wimlib_resolve_image(w, argv[1]);
1112 ret = verify_image_exists_and_is_single(image);
1116 ret = wimlib_mount(w, image, dir, mount_flags);
1118 imagex_error("Failed to mount image %d from `%s' on `%s'",
1119 image, wimfile, dir);
1127 /* Split a WIM into a spanned set */
1128 static int imagex_split(int argc, const char **argv)
1131 int flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1132 unsigned long part_size;
1134 for_opt(c, split_options) {
1137 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1151 part_size = strtoul(argv[2], NULL, 10) * (1 << 20);
1152 return wimlib_split(argv[0], argv[1], part_size, flags);
1155 /* Unmounts an image. */
1156 static int imagex_unmount(int argc, const char **argv)
1159 int unmount_flags = 0;
1162 for_opt(c, unmount_options) {
1165 unmount_flags |= WIMLIB_UNMOUNT_FLAG_COMMIT;
1168 unmount_flags |= WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY;
1182 ret = wimlib_unmount(argv[0], unmount_flags);
1184 imagex_error("Failed to unmount `%s'", argv[0]);
1188 struct imagex_command {
1190 int (*func)(int , const char **);
1194 static struct imagex_command imagex_commands[] = {
1195 {"append", imagex_append, APPEND},
1196 {"apply", imagex_apply, APPLY},
1197 {"capture", imagex_capture, CAPTURE},
1198 {"delete", imagex_delete, DELETE},
1199 {"dir", imagex_dir, DIR},
1200 {"export", imagex_export, EXPORT},
1201 {"info", imagex_info, INFO},
1202 {"join", imagex_join, JOIN},
1203 {"mount", imagex_mount_rw_or_ro, MOUNT},
1204 {"mountrw", imagex_mount_rw_or_ro, MOUNTRW},
1205 {"split", imagex_split, SPLIT},
1206 {"unmount", imagex_unmount, UNMOUNT},
1209 #define for_imagex_command(p) for (p = &imagex_commands[0]; \
1210 p != &imagex_commands[ARRAY_LEN(imagex_commands)]; p++)
1212 static void help_or_version(int argc, const char **argv)
1216 struct imagex_command *cmd;
1218 for (i = 1; i < argc; i++) {
1226 if (strcmp(p, "help") == 0 || (*p == '?' && *(p + 1) == '\0')) {
1227 for_imagex_command(cmd) {
1228 if (strcmp(cmd->name, argv[1]) == 0) {
1236 if (strcmp(p, "version") == 0) {
1244 int main(int argc, const char **argv)
1246 struct imagex_command *cmd;
1250 imagex_error("No command specified");
1255 help_or_version(argc, argv);
1259 wimlib_set_print_errors(true);
1261 for_imagex_command(cmd) {
1262 if (strcmp(cmd->name, *argv) == 0) {
1263 ret = cmd->func(argc, argv);
1265 imagex_error("Exiting with error code %d:\n"
1267 wimlib_get_error_string(ret));
1273 imagex_error("Unrecognized command: `%s'", argv[0]);