]> wimlib.net Git - wimlib/blobdiff - src/wimboot.c
system compression: try to attach WOF if compression fails
[wimlib] / src / wimboot.c
index b06816e28c4a6986a45fe37114f5cd99876ee28e..467f9fb389c5dcd967cfb65e14bacae9e724d7e4 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "wimlib/assert.h"
 #include "wimlib/blob_table.h"
+#include "wimlib/inode.h"
 #include "wimlib/error.h"
 #include "wimlib/util.h"
 #include "wimlib/wimboot.h"
@@ -186,8 +187,8 @@ query_partition_and_disk_info(const wchar_t *path,
        }
 
        if (part_info->PartitionStyle == PARTITION_STYLE_GPT) {
-               BUILD_BUG_ON(sizeof(part_info->Gpt.PartitionId) !=
-                            sizeof(drive_info->Gpt.DiskId));
+               STATIC_ASSERT(sizeof(part_info->Gpt.PartitionId) ==
+                             sizeof(drive_info->Gpt.DiskId));
                if (!memcmp(&part_info->Gpt.PartitionId,
                            &drive_info->Gpt.DiskId,
                            sizeof(drive_info->Gpt.DiskId)))
@@ -346,7 +347,7 @@ static u8 *
 fill_in_wimoverlay_dat(u8 *buf,
                       const struct WimOverlay_dat_header *old_hdr,
                       const wchar_t *wim_path,
-                      const u8 wim_guid[WIM_GUID_LEN],
+                      const u8 wim_guid[GUID_SIZE],
                       int image,
                       u64 new_data_source_id,
                       const PARTITION_INFORMATION_EX *part_info,
@@ -394,8 +395,8 @@ fill_in_wimoverlay_dat(u8 *buf,
        new_entry_1->entry_2_length = new_entry_2_size;
        new_entry_1->wim_type = WIM_BOOT_NOT_OS_WIM;
        new_entry_1->wim_index = image;
-       BUILD_BUG_ON(sizeof(new_entry_1->guid) != WIM_GUID_LEN);
-       memcpy(new_entry_1->guid, wim_guid, WIM_GUID_LEN);
+       STATIC_ASSERT(sizeof(new_entry_1->guid) == GUID_SIZE);
+       copy_guid(new_entry_1->guid, wim_guid);
 
        p += sizeof(struct WimOverlay_dat_entry_1);
 
@@ -437,21 +438,21 @@ fill_in_wimoverlay_dat(u8 *buf,
                new_entry_2->disk.mbr.padding[1] = 0x00000000;
                new_entry_2->disk.mbr.padding[2] = 0x00000000;
        } else {
-               BUILD_BUG_ON(sizeof(new_entry_2->partition.gpt.part_unique_guid) !=
-                            sizeof(part_info->Gpt.PartitionId));
+               STATIC_ASSERT(sizeof(new_entry_2->partition.gpt.part_unique_guid) ==
+                             sizeof(part_info->Gpt.PartitionId));
                memcpy(new_entry_2->partition.gpt.part_unique_guid,
                       &part_info->Gpt.PartitionId,
                       sizeof(part_info->Gpt.PartitionId));
                new_entry_2->partition_table_type = WIMOVERLAY_PARTITION_TYPE_GPT;
 
-               BUILD_BUG_ON(sizeof(new_entry_2->disk.gpt.disk_guid) !=
-                            sizeof(disk_info->Gpt.DiskId));
+               STATIC_ASSERT(sizeof(new_entry_2->disk.gpt.disk_guid) ==
+                             sizeof(disk_info->Gpt.DiskId));
                memcpy(new_entry_2->disk.gpt.disk_guid,
                       &disk_info->Gpt.DiskId,
                       sizeof(disk_info->Gpt.DiskId));
 
-               BUILD_BUG_ON(sizeof(new_entry_2->disk.gpt.disk_guid) !=
-                            sizeof(new_entry_2->partition.gpt.part_unique_guid));
+               STATIC_ASSERT(sizeof(new_entry_2->disk.gpt.disk_guid) ==
+                             sizeof(new_entry_2->partition.gpt.part_unique_guid));
        }
        new_entry_2->unknown_0x58[0] = 0x00000000;
        new_entry_2->unknown_0x58[1] = 0x00000000;
@@ -491,7 +492,7 @@ fill_in_wimoverlay_dat(u8 *buf,
 static int
 prepare_wimoverlay_dat(const struct WimOverlay_dat_header *old_hdr,
                       const wchar_t *wim_path,
-                      const u8 wim_guid[WIM_GUID_LEN],
+                      const u8 wim_guid[GUID_SIZE],
                       int image,
                       void **new_contents_ret,
                       u32 *new_contents_size_ret,
@@ -790,7 +791,7 @@ out_free_contents:
  */
 static int
 update_wimoverlay_manually(const wchar_t *drive, const wchar_t *wim_path,
-                          const u8 wim_guid[WIM_GUID_LEN],
+                          const u8 wim_guid[GUID_SIZE],
                           int image, u64 *data_source_id_ret)
 {
        wchar_t path_main[] = L"A:\\System Volume Information\\WimOverlay.dat";
@@ -865,47 +866,6 @@ out:
        return ret;
 }
 
-/* Try to attach an instance of the Windows Overlay File System Filter Driver to
- * the specified drive (such as C:)  */
-static bool
-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)
-                       retval = true;
-       } else {
-               WARNING("FilterAttach() does not exist in Fltlib.dll");
-       }
-
-       FreeLibrary(fltlib);
-
-       return retval;
-}
-
 /*
  * Allocate a WOF data source ID for a WIM file.
  *
@@ -926,7 +886,7 @@ try_to_attach_wof(const wchar_t *drive)
  */
 int
 wimboot_alloc_data_source_id(const wchar_t *wim_path,
-                            const u8 wim_guid[WIM_GUID_LEN],
+                            const u8 wim_guid[GUID_SIZE],
                             int image, const wchar_t *target,
                             u64 *data_source_id_ret, bool *wof_running_ret)
 {
@@ -1000,7 +960,7 @@ retry_ioctl:
                                CloseHandle(h);
                                h = INVALID_HANDLE_VALUE;
                                tried_to_attach_wof = true;
-                               if (try_to_attach_wof(drive_path + 4))
+                               if (win32_try_to_attach_wof(drive_path + 4))
                                        goto retry_ioctl;
                        }
                        ret = WIMLIB_ERR_UNSUPPORTED;
@@ -1134,11 +1094,11 @@ wimboot_set_pointer(HANDLE h,
                        struct wim_provider_rpdata wim_info;
                } in;
 
-               BUILD_BUG_ON(sizeof(in) != 8 +
-                            sizeof(struct wof_external_info) +
-                            sizeof(struct wim_provider_rpdata));
+               STATIC_ASSERT(sizeof(in) == 8 +
+                             sizeof(struct wof_external_info) +
+                             sizeof(struct wim_provider_rpdata));
 
-               in.hdr.rptag = WIMLIB_REPARSE_TAG_WOF;
+               in.hdr.rptag = WIM_IO_REPARSE_TAG_WOF;
                in.hdr.rpdatalen = sizeof(in) - sizeof(in.hdr);
                in.hdr.rpreserved = 0;
 
@@ -1150,8 +1110,8 @@ wimboot_set_pointer(HANDLE h,
                in.wim_info.data_source_id = data_source_id;
                copy_hash(in.wim_info.unnamed_data_stream_hash, blob->hash);
                copy_hash(in.wim_info.blob_table_hash, blob_table_hash);
-               in.wim_info.unnamed_data_stream_uncompressed_size = blob->size;
-               in.wim_info.unnamed_data_stream_compressed_size = blob->rdesc->size_in_wim;
+               in.wim_info.unnamed_data_stream_size = blob->size;
+               in.wim_info.unnamed_data_stream_size_in_wim = blob->rdesc->size_in_wim;
                in.wim_info.unnamed_data_stream_offset_in_wim = blob->rdesc->offset_in_wim;
 
                if (!DeviceIoControl(h, FSCTL_SET_REPARSE_POINT,