]> wimlib.net Git - wimlib/blobdiff - src/win32_common.c
Add experimental support for Windows VSS
[wimlib] / src / win32_common.c
index aa5be3778adb9b7b3afaa74ee6481271a658f3c1..b8ac2197827998bd32d4c38c41018056854e84f3 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "wimlib/error.h"
 #include "wimlib/util.h"
+#include "wimlib/win32_vss.h"
 
 static bool
 win32_modify_privilege(const wchar_t *privilege, bool enable)
@@ -316,6 +317,8 @@ out_drop_privs:
 void
 win32_global_cleanup(void)
 {
+       vss_global_cleanup();
+
        if (acquired_privileges)
                win32_release_capture_and_apply_privileges();
 
@@ -379,6 +382,51 @@ win32_get_drive_path(const wchar_t *file_path, wchar_t drive_path[7])
        return 0;
 }
 
+/* Try to attach an instance of the Windows Overlay File System Filter Driver to
+ * the specified drive (such as C:)  */
+bool
+win32_try_to_attach_wof(const wchar_t *drive)
+{
+       HMODULE fltlib;
+       bool retval = false;
+
+       /* Use FilterAttach() from Fltlib.dll.  */
+
+       fltlib = LoadLibrary(L"Fltlib.dll");
+
+       if (!fltlib) {
+               WARNING("Failed to load Fltlib.dll");
+               return retval;
+       }
+
+       HRESULT (WINAPI *func_FilterAttach)(LPCWSTR lpFilterName,
+                                           LPCWSTR lpVolumeName,
+                                           LPCWSTR lpInstanceName,
+                                           DWORD dwCreatedInstanceNameLength,
+                                           LPWSTR lpCreatedInstanceName);
+
+       func_FilterAttach = (void *)GetProcAddress(fltlib, "FilterAttach");
+
+       if (func_FilterAttach) {
+               HRESULT res;
+
+               res = (*func_FilterAttach)(L"wof", drive, NULL, 0, NULL);
+
+               if (res != S_OK)
+                       res = (*func_FilterAttach)(L"wofadk", drive, NULL, 0, NULL);
+
+               if (res == S_OK)
+                       retval = true;
+       } else {
+               WARNING("FilterAttach() does not exist in Fltlib.dll");
+       }
+
+       FreeLibrary(fltlib);
+
+       return retval;
+}
+
+
 static void
 windows_msg(u32 code, const wchar_t *format, va_list va,
            bool is_ntstatus, bool is_error)
@@ -404,9 +452,11 @@ retry:
        if (n >= buflen)
                goto realloc;
 
-       ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-                           NULL,
-                           is_ntstatus ? (*func_RtlNtStatusToDosError)(code) : code,
+       ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
+                               FORMAT_MESSAGE_IGNORE_INSERTS |
+                               (is_ntstatus ? FORMAT_MESSAGE_FROM_HMODULE : 0),
+                           (is_ntstatus ? ntdll_spec.handle : NULL),
+                           code,
                            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                            &buf[n],
                            buflen - n,