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] [--flags EDITIONID]\n",
80 " imagex apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all] DIRECTORY [--check]\n"
81 " [--hardlink] [--symlink] [--verbose]\n",
83 " imagex capture DIRECTORY WIMFILE [\"IMAGE_NAME\"] [\"DESCRIPTION\"]\n"
84 " l [--boot] [--check] [--compress[=TYPE]]\n"
85 " [--flags \"EditionID\"] [--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] [--stream-interface=INTERFACE]\n",
104 " imagex mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
105 " [--check] [--debug] [--stream-interface=INTERFACE]\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 {"flags", required_argument, NULL, 'f'},
124 static const struct option apply_options[] = {
125 {"check", no_argument, NULL, 'c'},
126 {"hardlink", no_argument, NULL, 'h'},
127 {"symlink", no_argument, NULL, 's'},
128 {"verbose", no_argument, NULL, 'v'},
129 {"ntfs", no_argument, NULL, 'N'},
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 {"flags", required_argument, NULL, 'f'},
137 {"verbose", no_argument, NULL,'v'},
138 {"ntfs", no_argument, NULL, 'N'},
141 static const struct option delete_options[] = {
142 {"check", no_argument, NULL, 'c'},
146 static const struct option export_options[] = {
147 {"boot", no_argument, NULL, 'b'},
148 {"check", no_argument , NULL, 'c'},
149 {"compress", optional_argument, NULL, 'x'},
153 static const struct option info_options[] = {
154 {"boot", no_argument, NULL, 'b'},
155 {"check", no_argument, NULL, 'c'},
156 {"header", no_argument, NULL, 'h'},
157 {"lookup-table", no_argument, NULL, 'l'},
158 {"xml", no_argument, NULL, 'x'},
159 {"extract-xml", required_argument, NULL, 'X'},
160 {"metadata", no_argument, NULL, 'm'},
164 static const struct option join_options[] = {
165 {"check", no_argument, NULL, 'c'},
169 static const struct option mount_options[] = {
170 {"check", no_argument, NULL, 'c'},
171 {"debug", no_argument, NULL, 'd'},
172 {"stream-interface", required_argument, NULL, 's'},
176 static const struct option split_options[] = {
177 {"check", no_argument, NULL, 'c'},
181 static const struct option unmount_options[] = {
182 {"commit", no_argument, NULL, 'c'},
183 {"check", no_argument, NULL, 'C'},
188 /* Print formatted error message to stderr. */
189 static void imagex_error(const char *format, ...)
192 va_start(va, format);
193 fputs("ERROR: ", stderr);
194 vfprintf(stderr, format, va);
199 /* Print formatted error message to stderr. */
200 static void imagex_error_with_errno(const char *format, ...)
202 int errno_save = errno;
204 va_start(va, format);
205 fputs("ERROR: ", stderr);
206 vfprintf(stderr, format, va);
207 fprintf(stderr, ": %s\n", strerror(errno_save));
212 static inline void version()
214 static const char *s =
215 "imagex (" PACKAGE ") " PACKAGE_VERSION "\n"
216 "Copyright (C) 2012 Eric Biggers\n"
217 "License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
218 "This is free software: you are free to change and redistribute it.\n"
219 "There is NO WARRANTY, to the extent permitted by law.\n"
221 "Report bugs to "PACKAGE_BUGREPORT".\n";
225 static inline void usage(int cmd)
227 puts("IMAGEX: Usage:");
228 fputs(usage_strings[cmd], stdout);
231 static void usage_all()
233 puts("IMAGEX: Usage:");
234 for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
235 fputs(usage_strings[i], stdout);
236 static const char *extra =
238 " imagex --version\n"
240 " The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
242 fputs(extra, stdout);
245 static int verify_image_exists(int image)
247 if (image == WIM_NO_IMAGE) {
248 imagex_error("Not a valid image");
249 return WIMLIB_ERR_INVALID_IMAGE;
254 static int verify_image_is_single(int image)
256 if (image == WIM_ALL_IMAGES) {
257 imagex_error("Cannot specify all images for this action");
258 return WIMLIB_ERR_INVALID_IMAGE;
263 static int verify_image_exists_and_is_single(int image)
266 ret = verify_image_exists(image);
268 ret = verify_image_is_single(image);
272 static int get_compression_type(const char *optarg)
275 return WIM_COMPRESSION_TYPE_LZX;
276 if (strcasecmp(optarg, "maximum") == 0 || strcasecmp(optarg, "lzx") == 0)
277 return WIM_COMPRESSION_TYPE_LZX;
278 else if (strcasecmp(optarg, "fast") == 0 || strcasecmp(optarg, "xpress") == 0)
279 return WIM_COMPRESSION_TYPE_XPRESS;
280 else if (strcasecmp(optarg, "none") == 0)
281 return WIM_COMPRESSION_TYPE_NONE;
283 imagex_error("Invalid compression type `%s'! Must be "
284 "\"maximum\", \"fast\", or \"none\".", optarg);
285 return WIM_COMPRESSION_TYPE_INVALID;
289 static int imagex_append(int argc, const char **argv)
292 const char *flags_element = NULL;
293 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
294 int add_image_flags = 0;
295 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
303 for_opt(c, append_options) {
306 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
309 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
310 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
313 flags_element = optarg;
322 if (argc < 2 || argc > 4) {
328 name = (argc >= 3) ? argv[2] : path_basename(dir);
329 desc = (argc >= 4) ? argv[3] : NULL;
331 ret = wimlib_open_wim(wimfile, open_flags, &w);
335 ret = wimlib_add_image(w, dir, name, desc,
336 flags_element, add_image_flags);
339 ret = wimlib_overwrite(w, write_flags);
345 /* Extract one image, or all images, from a WIM file into a directory. */
346 static int imagex_apply(int argc, const char **argv)
349 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
356 const char *image_num_or_name;
357 int extract_flags = 0;
359 for_opt(c, apply_options) {
362 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
365 extract_flags |= WIMLIB_EXTRACT_FLAG_HARDLINK;
368 extract_flags |= WIMLIB_EXTRACT_FLAG_SYMLINK;
371 extract_flags |= WIMLIB_EXTRACT_FLAG_VERBOSE;
374 extract_flags |= WIMLIB_EXTRACT_FLAG_NTFS;
383 if (argc != 2 && argc != 3) {
390 image_num_or_name = "1";
393 image_num_or_name = argv[1];
397 ret = wimlib_open_wim(wimfile, open_flags, &w);
401 image = wimlib_resolve_image(w, image_num_or_name);
402 ret = verify_image_exists(image);
406 num_images = wimlib_get_num_images(w);
407 if (argc == 2 && num_images != 1) {
408 imagex_error("`%s' contains %d images; Please select one "
409 "(or all)", wimfile, num_images);
414 ret = wimlib_extract_image(w, image, dir, extract_flags);
421 /* Create a WIM file from a directory. */
422 static int imagex_capture(int argc, const char **argv)
425 int add_image_flags = 0;
426 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
427 int compression_type = WIM_COMPRESSION_TYPE_NONE;
428 const char *flags_element = NULL;
436 for_opt(c, capture_options) {
439 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_BOOT;
442 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
445 compression_type = get_compression_type(optarg);
446 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
450 flags_element = optarg;
453 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_VERBOSE;
456 add_image_flags |= WIMLIB_ADD_IMAGE_FLAG_NTFS;
466 if (argc < 2 || argc > 4) {
472 name = (argc >= 3) ? argv[2] : dir;
473 desc = (argc >= 4) ? argv[3] : NULL;
475 ret = wimlib_create_new_wim(compression_type, &w);
479 ret = wimlib_add_image(w, dir, name, desc, flags_element,
482 imagex_error("Failed to add the image `%s'", dir);
486 ret = wimlib_write(w, wimfile, WIM_ALL_IMAGES, write_flags);
488 imagex_error("Failed to write the WIM file `%s'", wimfile);
494 /* Remove image(s) from a WIM. */
495 static int imagex_delete(int argc, const char **argv)
498 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
499 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
501 const char *image_num_or_name;
506 for_opt(c, delete_options) {
509 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
510 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
522 imagex_error("Must specify a WIM file");
524 imagex_error("Must specify an image");
529 image_num_or_name = argv[1];
531 ret = wimlib_open_wim(wimfile, open_flags, &w);
535 image = wimlib_resolve_image(w, image_num_or_name);
537 ret = verify_image_exists(image);
541 ret = wimlib_delete_image(w, image);
543 imagex_error("Failed to delete image from `%s'", wimfile);
547 ret = wimlib_overwrite(w, write_flags);
549 imagex_error("Failed to write the file `%s' with image "
557 /* Print the files contained in an image(s) in a WIM file. */
558 static int imagex_dir(int argc, const char **argv)
568 imagex_error("Must specify a WIM file");
573 imagex_error("Too many arguments");
579 ret = wimlib_open_wim(wimfile, WIMLIB_OPEN_FLAG_SPLIT_OK, &w);
583 part_number = wimlib_get_part_number(w, NULL);
584 if (part_number != 1) {
585 imagex_error("`%s' is part %d of a split WIM! Specify the "
586 "first part to see the files",
587 wimfile, part_number);
588 ret = WIMLIB_ERR_SPLIT_UNSUPPORTED;
593 image = wimlib_resolve_image(w, argv[2]);
594 ret = verify_image_exists(image);
598 /* Image was not specified. If the WIM only contains one image,
599 * choose that one; otherwise, print an error. */
600 num_images = wimlib_get_num_images(w);
601 if (num_images != 1) {
602 imagex_error("The file `%s' contains %d images; Please "
603 "select one.", wimfile, num_images);
611 ret = wimlib_print_files(w, image);
617 /* Exports one, or all, images from a WIM file to a new WIM file or an existing
619 static int imagex_export(int argc, const char **argv)
622 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
623 int export_flags = 0;
624 int write_flags = WIMLIB_WRITE_FLAG_SHOW_PROGRESS;
625 int compression_type = WIM_COMPRESSION_TYPE_NONE;
626 bool compression_type_specified = false;
627 const char *src_wimfile;
628 const char *src_image_num_or_name;
629 const char *dest_wimfile;
630 const char *dest_name;
631 const char *dest_desc;
632 WIMStruct *src_w = NULL;
633 WIMStruct *dest_w = NULL;
639 for_opt(c, export_options) {
642 export_flags |= WIMLIB_EXPORT_FLAG_BOOT;
645 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
646 write_flags |= WIMLIB_WRITE_FLAG_CHECK_INTEGRITY;
649 compression_type = get_compression_type(optarg);
650 if (compression_type == WIM_COMPRESSION_TYPE_INVALID)
652 compression_type_specified = true;
661 if (argc < 3 || argc > 5) {
665 src_wimfile = argv[0];
666 src_image_num_or_name = argv[1];
667 dest_wimfile = argv[2];
668 dest_name = (argc >= 4) ? argv[3] : NULL;
669 dest_desc = (argc >= 5) ? argv[4] : NULL;
670 ret = wimlib_open_wim(src_wimfile, open_flags, &src_w);
674 /* Determine if the destination is an existing file or not.
675 * If so, we try to append the exported image(s) to it; otherwise, we
676 * create a new WIM containing the exported image(s). */
677 if (stat(dest_wimfile, &stbuf) == 0) {
679 /* Destination file exists. */
680 if (!S_ISREG(stbuf.st_mode)) {
681 imagex_error("`%s' is not a regular file",
685 ret = wimlib_open_wim(dest_wimfile, open_flags, &dest_w);
689 if (compression_type_specified && compression_type !=
690 wimlib_get_compression_type(dest_w)) {
691 imagex_error("Cannot specify a compression type that is "
692 "not the same as that used in the "
696 compression_type = wimlib_get_compression_type(dest_w);
699 /* dest_wimfile is not an existing file, so create a new WIM. */
700 if (errno == ENOENT) {
701 ret = wimlib_create_new_wim(compression_type, &dest_w);
705 imagex_error_with_errno("Cannot stat file `%s'",
711 image = wimlib_resolve_image(src_w, src_image_num_or_name);
712 ret = verify_image_exists(image);
716 ret = wimlib_export_image(src_w, image, dest_w, dest_name, dest_desc,
723 ret = wimlib_write(dest_w, dest_wimfile, WIM_ALL_IMAGES,
726 ret = wimlib_overwrite(dest_w, write_flags);
733 /* Prints information about a WIM file; also can mark an image as bootable,
734 * change the name of an image, or change the description of an image. */
735 static int imagex_info(int argc, const char **argv)
741 bool lookup_table = false;
743 bool metadata = false;
744 bool short_header = true;
745 const char *xml_out_file = NULL;
747 const char *image_num_or_name = "all";
748 const char *new_name = NULL;
749 const char *new_desc = NULL;
754 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS |
755 WIMLIB_OPEN_FLAG_SPLIT_OK;
759 for_opt(c, info_options) {
769 short_header = false;
773 short_header = false;
777 short_header = false;
780 xml_out_file = optarg;
781 short_header = false;
785 short_header = false;
795 if (argc == 0 || argc > 4) {
801 image_num_or_name = argv[1];
811 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
813 ret = wimlib_open_wim(wimfile, open_flags, &w);
817 part_number = wimlib_get_part_number(w, &total_parts);
819 /*if (total_parts > 1 && part_number > 1) {*/
820 /*printf("Warning: this is part %d of a %d-part split WIM.\n"*/
821 /*" Select the first part if you want to see information\n"*/
822 /*" about images in the WIM.\n", */
823 /*part_number, total_parts);*/
826 image = wimlib_resolve_image(w, image_num_or_name);
827 if (image == WIM_NO_IMAGE && strcmp(image_num_or_name, "0") != 0) {
828 imagex_error("The image `%s' does not exist",
831 imagex_error("If you would like to set the boot "
832 "index to 0, specify image \"0\" with "
834 ret = WIMLIB_ERR_INVALID_IMAGE;
838 if (image == WIM_ALL_IMAGES && wimlib_get_num_images(w) > 1) {
840 imagex_error("Cannot specify the --boot flag "
841 "without specifying a specific "
842 "image in a multi-image WIM");
843 ret = WIMLIB_ERR_INVALID_IMAGE;
847 imagex_error("Cannot specify the NEW_NAME "
848 "without specifying a specific "
849 "image in a multi-image WIM");
850 ret = WIMLIB_ERR_INVALID_IMAGE;
855 /* Operations that print information are separated from operations that
856 * recreate the WIM file. */
857 if (!new_name && !boot) {
859 if (image == WIM_NO_IMAGE) {
860 imagex_error("`%s' is not a valid image",
862 ret = WIMLIB_ERR_INVALID_IMAGE;
866 if (image == WIM_ALL_IMAGES && short_header)
867 wimlib_print_wim_information(w);
870 wimlib_print_header(w);
873 if (total_parts != 1) {
874 printf("Warning: Only showing the lookup table "
875 "for part %d of a %d-part WIM.\n",
876 part_number, total_parts);
878 wimlib_print_lookup_table(w);
882 ret = wimlib_extract_xml_data(w, stdout);
888 fp = fopen(xml_out_file, "wb");
890 imagex_error_with_errno("Failed to open the "
896 ret = wimlib_extract_xml_data(w, fp);
897 if (fclose(fp) != 0) {
898 imagex_error("Failed to close the file `%s'",
908 wimlib_print_available_images(w, image);
911 if (total_parts != 1 && part_number != 1) {
912 imagex_error("Select part 1 of this %d-part WIM "
913 "to see the image metadata",
915 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
917 ret = wimlib_print_metadata(w, image);
922 if (total_parts != 1) {
923 imagex_error("Modifying a split WIM is not supported.");
926 if (image == WIM_ALL_IMAGES)
929 if (image == WIM_NO_IMAGE && new_name) {
930 imagex_error("Cannot specify new_name (`%s') when "
931 "using image 0", new_name);
936 if (image == wimlib_get_boot_idx(w)) {
937 printf("Image %d is already marked as "
938 "bootable.\n", image);
941 printf("Marking image %d as bootable.\n",
943 wimlib_set_boot_idx(w, image);
947 if (strcmp(wimlib_get_image_name(w, image),
949 printf("Image %d is already named \"%s\".\n",
953 printf("Changing the name of image %d to "
954 "\"%s\".\n", image, new_name);
955 ret = wimlib_set_image_name(w, image, new_name);
961 const char *old_desc;
962 old_desc = wimlib_get_image_description(w, image);
963 if (old_desc && strcmp(old_desc, new_desc) == 0) {
964 printf("The description of image %d is already "
965 "\"%s\".\n", image, new_desc);
968 printf("Changing the description of image %d "
969 "to \"%s\".\n", image, new_desc);
970 ret = wimlib_set_image_descripton(w, image,
977 /* Only call wimlib_overwrite_xml_and_header() if something
978 * actually needs to be changed. */
979 if (boot || new_name || new_desc ||
980 check != wimlib_has_integrity_table(w)) {
982 ret = wimlib_overwrite_xml_and_header(w, check ?
983 WIMLIB_WRITE_FLAG_CHECK_INTEGRITY |
984 WIMLIB_WRITE_FLAG_SHOW_PROGRESS : 0);
986 printf("The file `%s' was not modified because nothing "
987 "needed to be done.\n", wimfile);
997 /* Join split WIMs into one part WIM */
998 static int imagex_join(int argc, const char **argv)
1001 int flags = WIMLIB_OPEN_FLAG_SPLIT_OK | WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1002 const char *output_path;
1004 for_opt(c, join_options) {
1007 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1017 imagex_error("Must specify at least one split WIM (.swm) parts "
1021 output_path = argv[0];
1022 return wimlib_join(++argv, --argc, output_path, flags);
1028 /* Mounts an image using a FUSE mount. */
1029 static int imagex_mount_rw_or_ro(int argc, const char **argv)
1032 int mount_flags = 0;
1033 int open_flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1034 const char *wimfile;
1041 if (strcmp(argv[0], "mountrw") == 0)
1042 mount_flags |= WIMLIB_MOUNT_FLAG_READWRITE;
1043 for_opt(c, mount_options) {
1046 open_flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1049 mount_flags |= WIMLIB_MOUNT_FLAG_DEBUG;
1052 if (strcasecmp(optarg, "none") == 0)
1053 mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE;
1054 else if (strcasecmp(optarg, "xattr") == 0)
1055 mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR;
1056 else if (strcasecmp(optarg, "windows") == 0)
1057 mount_flags |= WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS;
1059 imagex_error("Unknown stream interface \"%s\"", optarg);
1069 if (argc != 2 && argc != 3)
1074 ret = wimlib_open_wim(wimfile, open_flags, &w);
1080 num_images = wimlib_get_num_images(w);
1081 if (num_images != 1) {
1082 imagex_error("The file `%s' contains %d images; Please "
1083 "select one", wimfile, num_images);
1084 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1086 ret = WIMLIB_ERR_INVALID_IMAGE;
1091 image = wimlib_resolve_image(w, argv[1]);
1095 ret = verify_image_exists_and_is_single(image);
1099 ret = wimlib_mount(w, image, dir, mount_flags);
1101 imagex_error("Failed to mount image %d from `%s' on `%s'",
1102 image, wimfile, dir);
1109 usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
1114 /* Split a WIM into a spanned set */
1115 static int imagex_split(int argc, const char **argv)
1118 int flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
1119 unsigned long part_size;
1121 for_opt(c, split_options) {
1124 flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
1138 part_size = strtoul(argv[2], NULL, 10) * (1 << 20);
1139 return wimlib_split(argv[0], argv[1], part_size, flags);
1142 /* Unmounts an image. */
1143 static int imagex_unmount(int argc, const char **argv)
1146 int unmount_flags = 0;
1149 for_opt(c, unmount_options) {
1152 unmount_flags |= WIMLIB_UNMOUNT_FLAG_COMMIT;
1155 unmount_flags |= WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY;
1169 ret = wimlib_unmount(argv[0], unmount_flags);
1171 imagex_error("Failed to unmount `%s'", argv[0]);
1175 struct imagex_command {
1177 int (*func)(int , const char **);
1181 static struct imagex_command imagex_commands[] = {
1182 {"append", imagex_append, APPEND},
1183 {"apply", imagex_apply, APPLY},
1184 {"capture", imagex_capture, CAPTURE},
1185 {"delete", imagex_delete, DELETE},
1186 {"dir", imagex_dir, DIR},
1187 {"export", imagex_export, EXPORT},
1188 {"info", imagex_info, INFO},
1189 {"join", imagex_join, JOIN},
1190 {"mount", imagex_mount_rw_or_ro, MOUNT},
1191 {"mountrw", imagex_mount_rw_or_ro, MOUNTRW},
1192 {"split", imagex_split, SPLIT},
1193 {"unmount", imagex_unmount, UNMOUNT},
1196 #define for_imagex_command(p) for (p = &imagex_commands[0]; \
1197 p != &imagex_commands[ARRAY_LEN(imagex_commands)]; p++)
1199 static void help_or_version(int argc, const char **argv)
1203 struct imagex_command *cmd;
1205 for (i = 1; i < argc; i++) {
1213 if (strcmp(p, "help") == 0 || (*p == '?' && *(p + 1) == '\0')) {
1214 for_imagex_command(cmd) {
1215 if (strcmp(cmd->name, argv[1]) == 0) {
1223 if (strcmp(p, "version") == 0) {
1231 int main(int argc, const char **argv)
1233 struct imagex_command *cmd;
1237 imagex_error("No command specified");
1242 help_or_version(argc, argv);
1246 wimlib_set_print_errors(true);
1248 for_imagex_command(cmd) {
1249 if (strcmp(cmd->name, *argv) == 0) {
1250 ret = cmd->func(argc, argv);
1252 imagex_error("Exiting with error code %d:\n"
1254 wimlib_get_error_string(ret));
1260 imagex_error("Unrecognized command: `%s'", argv[0]);
1264 /*#ifndef WITH_NTFS_3G*/
1265 /*ERROR("wimlib was not compiled with support for NTFS-3g, so we cannot extract");*/
1266 /*ERROR("a WIM to a NTFS filesystem while preserving NTFS-specific metadata.");*/
1267 /*ERROR("Please apply the WIM to a directory rather than a block device, ");*/
1268 /*ERROR("and without the NTFS flag; or compile in support for NTFS-3g.");*/
1269 /*return WIMLIB_ERR_UNSUPPORTED;*/