]> wimlib.net Git - wimlib/blobdiff - src/win32_vss.c
mount_image.c: add fallback definitions of RENAME_* constants
[wimlib] / src / win32_vss.c
index 914cd9127267a69b215ea0895b8f28e51b4ce82b..6f5a28eaf128728f7675d22186cd9b69ba7296bb 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
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public License
- * along with this file; if not, see http://www.gnu.org/licenses/.
+ * along with this file; if not, see https://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;
 }
@@ -355,53 +356,55 @@ request_vss_snapshot(IVssBackupComponents *vss, wchar_t *volume,
 
        res = vss->vtable->InitializeForBackup(vss, NULL);
        if (FAILED(res)) {
-               ERROR("IVssBackupComponents.InitializeForBackup() error: %x", res);
-               return false;
-       }
-
-       res = vss->vtable->SetContext(vss, VSS_CTX_BACKUP);
-       if (FAILED(res)) {
-               ERROR("IVssBackupComponents.SetContext() error: %x", res);
+               ERROR("IVssBackupComponents.InitializeForBackup() error: %x",
+                     (u32)res);
                return false;
        }
 
        res = vss->vtable->SetBackupState(vss, FALSE, TRUE, VSS_BT_COPY, FALSE);
        if (FAILED(res)) {
-               ERROR("IVssBackupComponents.SetBackupState() error: %x", res);
+               ERROR("IVssBackupComponents.SetBackupState() error: %x",
+                     (u32)res);
                return false;
        }
 
        res = vss->vtable->StartSnapshotSet(vss, snapshot_id);
        if (FAILED(res)) {
-               ERROR("IVssBackupComponents.StartSnapshotSet() error: %x", res);
+               ERROR("IVssBackupComponents.StartSnapshotSet() error: %x",
+                     (u32)res);
                return false;
        }
 
        res = vss->vtable->AddToSnapshotSet(vss, volume, (GUID){}, snapshot_id);
        if (FAILED(res)) {
-               ERROR("IVssBackupComponents.AddToSnapshotSet() error: %x", res);
+               ERROR("IVssBackupComponents.AddToSnapshotSet() error: %x",
+                     (u32)res);
                return false;
        }
 
        res = vss->vtable->PrepareForBackup(vss, &async);
        if (FAILED(res)) {
-               ERROR("IVssBackupComponents.PrepareForBackup() error: %x", res);
+               ERROR("IVssBackupComponents.PrepareForBackup() error: %x",
+                     (u32)res);
                return false;
        }
        res = wait_and_release(async);
        if (FAILED(res)) {
-               ERROR("IVssAsync.Wait() error while preparing for backup: %x", res);
+               ERROR("IVssAsync.Wait() error while preparing for backup: %x",
+                     (u32)res);
                return false;
        }
 
        res = vss->vtable->DoSnapshotSet(vss, &async);
        if (FAILED(res)) {
-               ERROR("IVssBackupComponents.DoSnapshotSet() error: %x", res);
+               ERROR("IVssBackupComponents.DoSnapshotSet() error: %x",
+                     (u32)res);
                return false;
        }
        res = wait_and_release(async);
        if (FAILED(res)) {
-               ERROR("IVssAsync.Wait() error while doing snapshot set: %x", res);
+               ERROR("IVssAsync.Wait() error while doing snapshot set: %x",
+                     (u32)res);
                return false;
        }
 
@@ -461,7 +464,7 @@ vss_create_snapshot(const wchar_t *source, UNICODE_STRING *vss_path_ret,
 
        res = (*func_CreateVssBackupComponentsInternal)(&vss);
        if (FAILED(res)) {
-               ERROR("CreateVssBackupComponents error: %x", res);
+               ERROR("CreateVssBackupComponents error: %x", (u32)res);
                goto vss_err;
        }
 
@@ -472,7 +475,8 @@ vss_create_snapshot(const wchar_t *source, UNICODE_STRING *vss_path_ret,
 
        res = vss->vtable->GetSnapshotProperties(vss, snapshot_id, &snapshot->props);
        if (FAILED(res)) {
-               ERROR("IVssBackupComponents.GetSnapshotProperties() error: %x", res);
+               ERROR("IVssBackupComponents.GetSnapshotProperties() error: %x",
+                     (u32)res);
                goto vss_err;
        }
 
@@ -521,4 +525,4 @@ out:
        return ret;
 }
 
-#endif /* __WIN32__ */
+#endif /* _WIN32 */