]> wimlib.net Git - wimlib/blobdiff - programs/imagex.c
Fix problem where HAVE_NTFS_MNT_RDONLY would not get defined
[wimlib] / programs / imagex.c
index 85026c82adddd52d722588afe72008891ff6e45e..854be037e42ac281dd25eba5685f017bee191d69 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h" /* Need for PACKAGE_VERSION, etc. */
+#endif
+
 #include "wimlib.h"
 #include "wimlib_tchar.h"
 
 #include "wimlib.h"
 #include "wimlib_tchar.h"
 
@@ -40,7 +43,7 @@
 #include <locale.h>
 
 #ifdef HAVE_ALLOCA_H
 #include <locale.h>
 
 #ifdef HAVE_ALLOCA_H
-#include <alloca.h>
+#  include <alloca.h>
 #endif
 
 #ifdef __WIN32__
 #endif
 
 #ifdef __WIN32__
@@ -80,7 +83,7 @@ enum imagex_op_type {
 };
 
 static void usage(int cmd_type);
 };
 
 static void usage(int cmd_type);
-static void usage_all();
+static void usage_all(void);
 
 static bool imagex_be_quiet = false;
 
 
 static bool imagex_be_quiet = false;
 
@@ -165,7 +168,7 @@ IMAGEX_PROGNAME" split WIMFILE SPLIT_WIMFILE PART_SIZE_MB [--check]\n"
 ),
 [UNMOUNT] =
 T(
 ),
 [UNMOUNT] =
 T(
-IMAGEX_PROGNAME" unmount DIRECTORY [--commit] [--check] [--rebuild]\n"
+IMAGEX_PROGNAME" unmount DIRECTORY [--commit] [--check] [--rebuild] [--lazy]\n"
 ),
 [UPDATE] =
 T(
 ),
 [UPDATE] =
 T(
@@ -179,14 +182,15 @@ IMAGEX_PROGNAME" update WIMFILE [IMAGE_NUM | IMAGE_NAME] [--check] [--rebuild]\n
 static void
 recommend_man_page(const tchar *cmd_name)
 {
 static void
 recommend_man_page(const tchar *cmd_name)
 {
+       const tchar *format_str;
 #ifdef __WIN32__
 #ifdef __WIN32__
-       tprintf(T("See "IMAGEX_PROGNAME"-%"TS".pdf in the "
-                 "doc directory for more details.\n"),
-               cmd_name);
+       format_str = T("See "IMAGEX_PROGNAME"%"TS"%"TS".pdf in the "
+                      "doc directory for more details.\n");
 #else
 #else
-       tprintf(T("Try `man "IMAGEX_PROGNAME"-%"TS"' "
-                 "for more details.\n"), cmd_name);
+       format_str = T("Try `man "IMAGEX_PROGNAME"%"TS"%"TS"' "
+                      "for more details.\n");
 #endif
 #endif
+       tprintf(format_str, *cmd_name ? T("-") : T(""), cmd_name);
 }
 
 enum {
 }
 
 enum {
@@ -204,6 +208,7 @@ enum {
        IMAGEX_FORCE_OPTION,
        IMAGEX_HARDLINK_OPTION,
        IMAGEX_HEADER_OPTION,
        IMAGEX_FORCE_OPTION,
        IMAGEX_HARDLINK_OPTION,
        IMAGEX_HEADER_OPTION,
+       IMAGEX_LAZY_OPTION,
        IMAGEX_LOOKUP_TABLE_OPTION,
        IMAGEX_METADATA_OPTION,
        IMAGEX_NORPFIX_OPTION,
        IMAGEX_LOOKUP_TABLE_OPTION,
        IMAGEX_METADATA_OPTION,
        IMAGEX_NORPFIX_OPTION,
@@ -331,6 +336,7 @@ static const struct option unmount_options[] = {
        {T("commit"),  no_argument, NULL, IMAGEX_COMMIT_OPTION},
        {T("check"),   no_argument, NULL, IMAGEX_CHECK_OPTION},
        {T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION},
        {T("commit"),  no_argument, NULL, IMAGEX_COMMIT_OPTION},
        {T("check"),   no_argument, NULL, IMAGEX_CHECK_OPTION},
        {T("rebuild"), no_argument, NULL, IMAGEX_REBUILD_OPTION},
+       {T("lazy"),    no_argument, NULL, IMAGEX_LAZY_OPTION},
        {NULL, 0, NULL, 0},
 };
 
        {NULL, 0, NULL, 0},
 };
 
@@ -2780,9 +2786,13 @@ imagex_optimize(int argc, tchar **argv)
 
        wimfile = argv[0];
 
 
        wimfile = argv[0];
 
+       ret = file_writable(wimfile);
+       if (ret)
+               return ret;
+
        ret = wimlib_open_wim(wimfile, open_flags, &w,
                              imagex_progress_func);
        ret = wimlib_open_wim(wimfile, open_flags, &w,
                              imagex_progress_func);
-       if (ret != 0)
+       if (ret)
                return ret;
 
        old_size = file_get_size(argv[0]);
                return ret;
 
        old_size = file_get_size(argv[0]);
@@ -2880,6 +2890,9 @@ imagex_unmount(int argc, tchar **argv)
                case IMAGEX_REBUILD_OPTION:
                        unmount_flags |= WIMLIB_UNMOUNT_FLAG_REBUILD;
                        break;
                case IMAGEX_REBUILD_OPTION:
                        unmount_flags |= WIMLIB_UNMOUNT_FLAG_REBUILD;
                        break;
+               case IMAGEX_LAZY_OPTION:
+                       unmount_flags |= WIMLIB_UNMOUNT_FLAG_LAZY;
+                       break;
                default:
                        usage(UNMOUNT);
                        return -1;
                default:
                        usage(UNMOUNT);
                        return -1;
@@ -2983,6 +2996,11 @@ imagex_update(int argc, tchar **argv)
        if (argc < 1 || argc > 2)
                goto out_usage;
        wimfile = argv[0];
        if (argc < 1 || argc > 2)
                goto out_usage;
        wimfile = argv[0];
+
+       ret = file_writable(wimfile);
+       if (ret)
+               goto out;
+
        ret = wimlib_open_wim(wimfile, open_flags, &wim, imagex_progress_func);
        if (ret)
                goto out;
        ret = wimlib_open_wim(wimfile, open_flags, &wim, imagex_progress_func);
        if (ret)
                goto out;
@@ -3109,7 +3127,7 @@ static const struct imagex_command imagex_commands[] = {
 };
 
 static void
 };
 
 static void
-version()
+version(void)
 {
        static const tchar *s =
        T(
 {
        static const tchar *s =
        T(
@@ -3172,7 +3190,7 @@ usage(int cmd_type)
 }
 
 static void
 }
 
 static void
-usage_all()
+usage_all(void)
 {
        tfputs(T("Usage:\n"), stdout);
        for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
 {
        tfputs(T("Usage:\n"), stdout);
        for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
@@ -3184,9 +3202,9 @@ usage_all()
 "\n"
 "    The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
 "\n"
 "\n"
 "    The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
 "\n"
-"    Try `man "IMAGEX_PROGNAME"' for more information.\n"
        );
        tfputs(extra, stdout);
        );
        tfputs(extra, stdout);
+       recommend_man_page(T(""));
 }
 
 /* Entry point for wimlib's ImageX implementation.  On UNIX the command
 }
 
 /* Entry point for wimlib's ImageX implementation.  On UNIX the command