]> wimlib.net Git - wimlib/blobdiff - src/win32_vss.c
compiler.h: remove _unused_attribute
[wimlib] / src / win32_vss.c
index 6e5d3ebc5f2e21fa9f2882208c203b64be58fa91..cab05663f420b1565c0eb4caa37bc02015014979 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * win32_vss.c - Experimental Windows-specific code for creating VSS (Volume
- * Shadow Copy Service) snapshots.
+ * win32_vss.c - Windows-specific code for creating VSS (Volume Shadow Copy
+ * Service) snapshots.
  */
 
 /*
- * Copyright (C) 2015 Eric Biggers
+ * Copyright (C) 2015-2023 Eric Biggers
  *
  * This file is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the Free
@@ -20,7 +20,7 @@
  * along with this file; if not, see http://www.gnu.org/licenses/.
  */
 
-#ifdef __WIN32__
+#ifdef _WIN32
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
@@ -29,9 +29,9 @@
 #include "wimlib/win32_common.h"
 
 #include <cguid.h>
-#include <pthread.h>
 
 #include "wimlib/error.h"
+#include "wimlib/threads.h"
 #include "wimlib/util.h"
 #include "wimlib/win32_vss.h"
 
@@ -215,7 +215,7 @@ struct IVssBackupComponentsVTable {
  *----------------------------------------------------------------------------*/
 
 static bool vss_initialized;
-static pthread_mutex_t vss_initialization_mutex = PTHREAD_MUTEX_INITIALIZER;
+static struct mutex vss_initialization_mutex = MUTEX_INITIALIZER;
 
 /* vssapi.dll  */
 static HANDLE hVssapi;
@@ -285,15 +285,15 @@ vss_global_init(void)
        if (vss_initialized)
                return true;
 
-       pthread_mutex_lock(&vss_initialization_mutex);
+       mutex_lock(&vss_initialization_mutex);
        if (!vss_initialized)
                vss_initialized = vss_global_init_impl();
-       pthread_mutex_unlock(&vss_initialization_mutex);
+       mutex_unlock(&vss_initialization_mutex);
 
        if (vss_initialized)
                return true;
        ERROR("The Volume Shadow Copy Service (VSS) API could not be "
-             "initialized. Probably it isn't supported on this computer.");
+             "initialized.");
        return false;
 }
 
@@ -303,14 +303,14 @@ vss_global_cleanup(void)
        if (!vss_initialized)
                return;
 
-       pthread_mutex_lock(&vss_initialization_mutex);
+       mutex_lock(&vss_initialization_mutex);
        if (vss_initialized) {
                (*func_CoUninitialize)();
                FreeLibrary(hOle32);
                FreeLibrary(hVssapi);
                vss_initialized = false;
        }
-       pthread_mutex_unlock(&vss_initialization_mutex);
+       mutex_unlock(&vss_initialization_mutex);
 }
 
 /*----------------------------------------------------------------------------*
@@ -342,6 +342,7 @@ static HRESULT
 wait_and_release(IVssAsync *async)
 {
        HRESULT res = async->vtable->Wait(async, INFINITE);
+
        async->vtable->Release(async);
        return res;
 }
@@ -359,12 +360,6 @@ request_vss_snapshot(IVssBackupComponents *vss, wchar_t *volume,
                return false;
        }
 
-       res = vss->vtable->SetContext(vss, VSS_CTX_BACKUP);
-       if (FAILED(res)) {
-               ERROR("IVssBackupComponents.SetContext() error: %x", res);
-               return false;
-       }
-
        res = vss->vtable->SetBackupState(vss, FALSE, TRUE, VSS_BT_COPY, FALSE);
        if (FAILED(res)) {
                ERROR("IVssBackupComponents.SetBackupState() error: %x", res);
@@ -408,6 +403,15 @@ request_vss_snapshot(IVssBackupComponents *vss, wchar_t *volume,
        return true;
 }
 
+static bool
+is_wow64(void)
+{
+       BOOL wow64 = FALSE;
+       if (sizeof(size_t) == 4)
+               IsWow64Process(GetCurrentProcess(), &wow64);
+       return wow64;
+}
+
 /*
  * Create a VSS snapshot of the specified @volume.  Return the NT namespace path
  * to the snapshot root directory in @vss_path_ret and a handle to the snapshot
@@ -494,8 +498,16 @@ vss_create_snapshot(const wchar_t *source, UNICODE_STRING *vss_path_ret,
 
 vss_err:
        ret = WIMLIB_ERR_SNAPSHOT_FAILURE;
-       ERROR("A problem occurred while creating a VSS snapshot of \"%ls\".\n"
-             "        Aborting the operation.", volume);
+       if (is_wow64()) {
+               ERROR("64-bit Windows doesn't allow 32-bit applications to "
+                     "create VSS snapshots.\n"
+                     "        Run the 64-bit version of this application "
+                     "instead.");
+       } else {
+               ERROR("A problem occurred while creating a VSS snapshot of "
+                     "\"%ls\".\n"
+                     "        Aborting the operation.", volume);
+       }
 err:
        if (snapshot)
                vss_delete_snapshot(&snapshot->base);
@@ -504,4 +516,4 @@ out:
        return ret;
 }
 
-#endif /* __WIN32__ */
+#endif /* _WIN32 */