]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
Support for splitting WIMs
[wimlib] / programs / imagex.c
index 6dcc62d3b63dbcb29704a95e443294a046bb760c..d6d57d19b56c06cc87c0de465bdb02d393a8e095 100644 (file)
@@ -48,6 +48,7 @@ enum imagex_op_type {
        JOIN,
        MOUNT,
        MOUNTRW,
+       SPLIT,
        UNMOUNT,
 };
 
@@ -93,13 +94,15 @@ static const char *usage_strings[] = {
 "        [NEW_DESC] [--boot] [--check] [--header] [--lookup-table]\n"
 "        [--xml] [--extract-xml FILE] [--metadata]\n",
 [JOIN] = 
-"    imagex join [--check] --output WIMFILE SPLIT_WIM...\n",
+"    imagex join [--check] WIMFILE SPLIT_WIM...\n",
 [MOUNT] = 
 "    imagex mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n"
 "        [--check] [--debug]\n",
 [MOUNTRW] = 
 "    imagex mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
 "        [--check] [--debug]\n",
+[SPLIT] = 
+"    imagex split WIMFILE SPLIT_WIMFILE PART_SIZE [--check]\n",
 [UNMOUNT] = 
 "    imagex unmount DIRECTORY [--commit] [--check]\n",
 };
@@ -162,7 +165,6 @@ static const struct option info_options[] = {
 
 static const struct option join_options[] = {
        {"check", no_argument, NULL, 'c'},
-       {"output", required_argument, NULL, 'o'},
        {NULL, 0, NULL, 0},
 };
 
@@ -172,6 +174,11 @@ static const struct option mount_options[] = {
        {NULL, 0, NULL, 0},
 };
 
+static const struct option split_options[] = {
+       {"check", no_argument, NULL, 'c'},
+       {NULL, 0, NULL, 0},
+};
+
 static const struct option unmount_options[] = {
        {"commit", no_argument, NULL, 'c'},
        {"check", no_argument, NULL, 'C'},
@@ -1004,16 +1011,13 @@ static int imagex_join(int argc, const char **argv)
        int flags = WIMLIB_OPEN_FLAG_SPLIT_OK | WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
        int image;
        int ret;
-       const char *output_path = NULL;
+       const char *output_path;
 
        for_opt(c, join_options) {
                switch (c) {
                case 'c':
                        flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
                        break;
-               case 'o':
-                       output_path = optarg;
-                       break;
                default:
                        goto err;
                }
@@ -1022,15 +1026,12 @@ static int imagex_join(int argc, const char **argv)
        argv += optind;
 
        if (argc < 2) {
-               imagex_error("Must specify at least two split WIM "
+               imagex_error("Must specify at least one split WIM "
                                "(.swm) parts to join!\n");
                goto err;
        }
-       if (!output_path) {
-               imagex_error("Must specify output_path!\n");
-               goto err;
-       }
-       return wimlib_join(argv, argc, output_path, flags);
+       output_path = argv[0];
+       return wimlib_join(++argv, --argc, output_path, flags);
 err:
        usage(JOIN);
        return -1;
@@ -1109,6 +1110,34 @@ done:
        return ret;
 }
 
+/* Split a WIM into a spanned set */
+static int imagex_split(int argc, const char **argv)
+{
+       int c;
+       int flags = WIMLIB_OPEN_FLAG_SHOW_PROGRESS;
+       unsigned long part_size;
+
+       for_opt(c, split_options) {
+               switch (c) {
+               case 'c':
+                       flags |= WIMLIB_OPEN_FLAG_CHECK_INTEGRITY;
+                       break;
+               default:
+                       usage(SPLIT);
+                       return -1;
+               }
+       }
+       argc -= optind;
+       argv += optind;
+
+       if (argc != 3) {
+               usage(SPLIT);
+               return -1;
+       }
+       part_size = strtoul(argv[2], NULL, 10) * (1 << 20);
+       return wimlib_split(argv[0], argv[1], part_size, flags);
+}
+
 /* Unmounts an image. */
 static int imagex_unmount(int argc, const char **argv)
 {
@@ -1159,6 +1188,7 @@ static struct imagex_command imagex_commands[] = {
        {"join",    imagex_join,           JOIN},
        {"mount",   imagex_mount_rw_or_ro, MOUNT},
        {"mountrw", imagex_mount_rw_or_ro, MOUNTRW},
+       {"split",   imagex_split,          SPLIT},
        {"unmount", imagex_unmount,        UNMOUNT},
 };