X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwimboot.c;h=d4643d67e516ff2a9392a978ae0aa855105d674d;hp=2b6a2415181ec7c7d1b90d34798eecb6bf1038bc;hb=211f0c729ab69879e28398d1d71d0a6bc01ed2c8;hpb=f18b7fc3361c4daac0ddd104af65a8eff8466fec diff --git a/src/wimboot.c b/src/wimboot.c index 2b6a2415..d4643d67 100644 --- a/src/wimboot.c +++ b/src/wimboot.c @@ -36,8 +36,9 @@ #include "wimlib/win32_common.h" #include "wimlib/assert.h" +#include "wimlib/blob_table.h" +#include "wimlib/inode.h" #include "wimlib/error.h" -#include "wimlib/lookup_table.h" #include "wimlib/util.h" #include "wimlib/wimboot.h" #include "wimlib/win32.h" @@ -94,8 +95,8 @@ query_partition_and_disk_info(const wchar_t *path, h = open_file(vol_name, GENERIC_READ); if (h == INVALID_HANDLE_VALUE) { - ERROR("\"%ls\": Can't open volume device (err=%"PRIu32")", - vol_name, (u32)GetLastError()); + win32_error(GetLastError(), L"\"%ls\": Can't open volume device", + vol_name); ret = WIMLIB_ERR_OPEN; goto out; } @@ -103,8 +104,8 @@ query_partition_and_disk_info(const wchar_t *path, if (!query_device(h, IOCTL_DISK_GET_PARTITION_INFO_EX, part_info, sizeof(PARTITION_INFORMATION_EX))) { - ERROR("\"%ls\": Can't get partition info (err=%"PRIu32")", - vol_name, (u32)GetLastError()); + win32_error(GetLastError(), + L"\"%ls\": Can't get partition info", vol_name); ret = WIMLIB_ERR_READ; goto out; } @@ -122,8 +123,9 @@ query_partition_and_disk_info(const wchar_t *path, extents, extents_size)) break; if (GetLastError() != ERROR_MORE_DATA) { - ERROR("\"%ls\": Can't get volume extent info (err=%"PRIu32")", - vol_name, (u32)GetLastError()); + win32_error(GetLastError(), + L"\"%ls\": Can't get volume extent info", + vol_name); ret = WIMLIB_ERR_READ; goto out; } @@ -146,8 +148,8 @@ query_partition_and_disk_info(const wchar_t *path, h = open_file(disk_name, GENERIC_READ); if (h == INVALID_HANDLE_VALUE) { - ERROR("\"%ls\": Can't open disk device (err=%"PRIu32")", - disk_name, (u32)GetLastError()); + win32_error(GetLastError(), + L"\"%ls\": Can't open disk device", disk_name); ret = WIMLIB_ERR_OPEN; goto out; } @@ -165,8 +167,8 @@ query_partition_and_disk_info(const wchar_t *path, drive_info, drive_info_size)) break; if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - ERROR("\"%ls\": Can't get disk info (err=%"PRIu32")", - disk_name, (u32)GetLastError()); + win32_error(GetLastError(), + L"\"%ls\": Can't get disk info", disk_name); ret = WIMLIB_ERR_READ; goto out; } @@ -185,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))) @@ -291,23 +293,24 @@ write_wimoverlay_dat(const wchar_t *path, const void *contents, u32 size) h = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (h == INVALID_HANDLE_VALUE) { - set_errno_from_GetLastError(); - ERROR_WITH_ERRNO("\"%ls\": Can't open file for writing", path); + win32_error(GetLastError(), + L"\"%ls\": Can't open file for writing", path); return WIMLIB_ERR_OPEN; } + SetLastError(0); if (!WriteFile(h, contents, size, &bytes_written, NULL) || bytes_written != size) { - set_errno_from_GetLastError(); - ERROR_WITH_ERRNO("\"%ls\": Can't write file", path); + win32_error(GetLastError(), + L"\"%ls\": Can't write file", path); CloseHandle(h); return WIMLIB_ERR_WRITE; } if (!CloseHandle(h)) { - set_errno_from_GetLastError(); - ERROR_WITH_ERRNO("\"%ls\": Can't close handle", path); + win32_error(GetLastError(), + L"\"%ls\": Can't close handle", path); return WIMLIB_ERR_WRITE; } @@ -344,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, @@ -392,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); @@ -435,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; @@ -489,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, @@ -593,13 +596,11 @@ retry: err = err2; } } - set_errno_from_win32_error(err); - ERROR_WITH_ERRNO("\"%ls\": Can't open for reading", path); + win32_error(err, L"\"%ls\": Can't open for reading", path); return WIMLIB_ERR_OPEN; } if (!GetFileInformationByHandle(h, &info)) { - set_errno_from_GetLastError(); - ERROR_WITH_ERRNO("\"%ls\": Can't query metadata", path); + win32_error(GetLastError(), L"\"%ls\": Can't query metadata", path); CloseHandle(h); return WIMLIB_ERR_STAT; } @@ -613,11 +614,11 @@ retry: return WIMLIB_ERR_NOMEM; } + SetLastError(0); if (!ReadFile(h, contents, info.nFileSizeLow, &bytes_read, NULL) || bytes_read != info.nFileSizeLow) { - set_errno_from_GetLastError(); - ERROR_WITH_ERRNO("\"%ls\": Can't read data", path); + win32_error(GetLastError(), L"\"%ls\": Can't read data", path); CloseHandle(h); ret = WIMLIB_ERR_READ; goto out_free_contents; @@ -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"; @@ -926,7 +927,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) { @@ -983,8 +984,8 @@ retry_ioctl: h = open_file(drive_path, GENERIC_WRITE); if (h == INVALID_HANDLE_VALUE) { - set_errno_from_GetLastError(); - ERROR_WITH_ERRNO("Failed to open \"%ls\"", drive_path + 4); + win32_error(GetLastError(), + L"Failed to open \"%ls\"", drive_path + 4); ret = WIMLIB_ERR_OPEN; goto out_free_in; } @@ -1006,17 +1007,14 @@ retry_ioctl: ret = WIMLIB_ERR_UNSUPPORTED; goto out_close_handle; } else { - set_errno_from_win32_error(err); - ERROR_WITH_ERRNO("Failed to add overlay source \"%ls\" " - "to volume \"%ls\" (err=0x%08"PRIx32")", - wim_path, drive_path + 4, (u32)err); + win32_error(err, L"Failed to add overlay source \"%ls\" " + "to volume \"%ls\"", wim_path, drive_path + 4); ret = WIMLIB_ERR_WIMBOOT; goto out_close_handle; } } if (bytes_returned != sizeof(data_source_id)) { - set_errno_from_win32_error(ERROR_INVALID_DATA); ret = WIMLIB_ERR_WIMBOOT; ERROR("Unexpected result size when adding " "overlay source \"%ls\" to volume \"%ls\"", @@ -1060,12 +1058,12 @@ out: * * @h * Open handle to the file, with GENERIC_WRITE access. - * @lte - * Unnamed data stream of the file. + * @blob + * The blob for the unnamed data stream of the file. * @data_source_id * Allocated identifier for the WIM data source on the destination volume. - * @lookup_table_hash - * SHA-1 message digest of the WIM's lookup table. + * @blob_table_hash + * SHA-1 message digest of the WIM's blob table. * @wof_running * %true if the WOF driver appears to be available and working; %false if * not. @@ -1074,13 +1072,12 @@ out: */ bool wimboot_set_pointer(HANDLE h, - const struct wim_lookup_table_entry *lte, + const struct blob_descriptor *blob, u64 data_source_id, - const u8 lookup_table_hash[SHA1_HASH_SIZE], + const u8 blob_table_hash[SHA1_HASH_SIZE], bool wof_running) { DWORD bytes_returned; - DWORD err; if (wof_running) { /* The WOF driver is running. We can create the reparse point @@ -1100,9 +1097,9 @@ wimboot_set_pointer(HANDLE h, in.wim_info.version = WIM_PROVIDER_CURRENT_VERSION; in.wim_info.flags = 0; in.wim_info.data_source_id = data_source_id; - copy_hash(in.wim_info.resource_hash, lte->hash); + copy_hash(in.wim_info.unnamed_data_stream_hash, blob->hash); - /* lookup_table_hash is not necessary */ + /* blob_table_hash is not necessary */ if (!DeviceIoControl(h, FSCTL_SET_EXTERNAL_BACKING, &in, sizeof(in), NULL, 0, @@ -1138,11 +1135,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; @@ -1152,11 +1149,11 @@ wimboot_set_pointer(HANDLE h, in.wim_info.version = 2; in.wim_info.flags = 0; in.wim_info.data_source_id = data_source_id; - copy_hash(in.wim_info.resource_hash, lte->hash); - copy_hash(in.wim_info.wim_lookup_table_hash, lookup_table_hash); - in.wim_info.stream_uncompressed_size = lte->size; - in.wim_info.stream_compressed_size = lte->rspec->size_in_wim; - in.wim_info.stream_offset_in_wim = lte->rspec->offset_in_wim; + 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_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, &in, sizeof(in), NULL, 0, &bytes_returned, NULL)) @@ -1171,7 +1168,7 @@ wimboot_set_pointer(HANDLE h, return false; if (!SetFilePointerEx(h, - (LARGE_INTEGER){ .QuadPart = lte->size}, + (LARGE_INTEGER){ .QuadPart = blob->size}, NULL, FILE_BEGIN)) return false;