X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fwimboot.c;h=cdd74d9468f267dece137673db408ec30a838068;hb=82b8e9da4931a731976c3998f2464d4e690502e8;hp=7ee67f96b3c1a4d825dc236d4b2db58b2db46f45;hpb=ad8c3f70361e25b7c1bbc46d4429749c7215fa12;p=wimlib diff --git a/src/wimboot.c b/src/wimboot.c index 7ee67f96..cdd74d94 100644 --- a/src/wimboot.c +++ b/src/wimboot.c @@ -29,13 +29,12 @@ * along with wimlib; if not, see http://www.gnu.org/licenses/. */ +#ifdef __WIN32__ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#ifdef __WIN32__ - #include "wimlib/win32_common.h" #include "wimlib/win32.h" #include "wimlib/assert.h" @@ -49,8 +48,7 @@ static HANDLE open_file(const wchar_t *device_name, DWORD desiredAccess) { return CreateFile(device_name, desiredAccess, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, OPEN_EXISTING, + FILE_SHARE_VALID_FLAGS, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); } @@ -312,7 +310,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_GID_LEN], + const u8 wim_guid[WIM_GUID_LEN], int image, u64 new_data_source_id, const PARTITION_INFORMATION_EX *part_info, @@ -360,8 +358,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_GID_LEN); - memcpy(new_entry_1->guid, wim_guid, WIM_GID_LEN); + BUILD_BUG_ON(sizeof(new_entry_1->guid) != WIM_GUID_LEN); + memcpy(new_entry_1->guid, wim_guid, WIM_GUID_LEN); p += sizeof(struct WimOverlay_dat_entry_1); @@ -457,7 +455,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_GID_LEN], + const u8 wim_guid[WIM_GUID_LEN], int image, void **new_contents_ret, u32 *new_contents_size_ret, @@ -612,8 +610,8 @@ retry: if (wimlib_print_errors) { print_byte_field((const u8 *)hdr, sizeof(struct WimOverlay_dat_header), - stderr); - fputc('\n', stderr); + wimlib_error_file); + fputc('\n', wimlib_error_file); } ret = WIMLIB_ERR_UNSUPPORTED; goto out_free_contents; @@ -683,8 +681,9 @@ retry: path, i, entry_1->data_source_id); if (wimlib_print_errors) { print_byte_field((const u8 *)entry_2->wim_file_name, - wim_file_name_length, stderr); - fputc('\n', stderr); + wim_file_name_length, + wimlib_error_file); + fputc('\n', wimlib_error_file); } ret = WIMLIB_ERR_UNSUPPORTED; goto out_free_contents; @@ -721,8 +720,8 @@ retry: if (wimlib_print_errors) { print_byte_field((const u8 *)entry_2, entry_1->entry_2_length, - stderr); - fputc('\n', stderr); + wimlib_error_file); + fputc('\n', wimlib_error_file); } ret = WIMLIB_ERR_UNSUPPORTED; goto out_free_contents; @@ -757,7 +756,7 @@ out_free_contents: */ static int update_wimoverlay_manually(const wchar_t *drive, const wchar_t *wim_path, - const u8 wim_guid[WIM_GID_LEN], + const u8 wim_guid[WIM_GUID_LEN], int image, u64 *data_source_id_ret) { wchar_t path_main[] = L"A:\\System Volume Information\\WimOverlay.dat"; @@ -808,6 +807,7 @@ update_wimoverlay_manually(const wchar_t *drive, const wchar_t *wim_path, if (ret) { ERROR_WITH_ERRNO("Can't rename \"%ls\" => \"%ls\"", path_main, path_wimlib_backup); + ret = WIMLIB_ERR_RENAME; goto out_free_new_contents; } } @@ -817,6 +817,7 @@ update_wimoverlay_manually(const wchar_t *drive, const wchar_t *wim_path, if (ret) { ERROR_WITH_ERRNO("Can't rename \"%ls\" => \"%ls\"", path_new, path_main); + ret = WIMLIB_ERR_RENAME; } out_free_new_contents: FREE(new_contents); @@ -830,26 +831,6 @@ out: return ret; } -static int -win32_get_drive_path(const wchar_t *file_path, wchar_t drive_path[7]) -{ - tchar *file_abspath; - - file_abspath = realpath(file_path, NULL); - if (!file_abspath) - return WIMLIB_ERR_NOMEM; - - if (file_abspath[0] == L'\0' || file_abspath[1] != L':') { - ERROR("\"%ls\": Path format not recognized", file_abspath); - FREE(file_abspath); - return WIMLIB_ERR_UNSUPPORTED; - } - - wsprintf(drive_path, L"\\\\.\\%lc:", file_abspath[0]); - FREE(file_abspath); - return 0; -} - /* Try to attach an instance of the Windows Overlay File System Filter Driver to * the specified drive (such as C:) */ static bool @@ -902,7 +883,7 @@ try_to_attach_wof(const wchar_t *drive) * @image * Number of the image in the WIM being applied. * @target - * Path to the target drive. + * Path to the target directory. * @data_source_id_ret * On success, an identifier for the backing WIM file will be returned * here. @@ -911,7 +892,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_GID_LEN], + const u8 wim_guid[WIM_GUID_LEN], int image, const wchar_t *target, u64 *data_source_id_ret, bool *wof_running_ret) { @@ -1043,8 +1024,10 @@ out: * This turns it into a reparse point that redirects accesses to it, to the * corresponding resource in the WIM archive. * - * @path - * Path to extracted file (already created). + * @h + * Open handle to the file, with GENERIC_WRITE access. + * @printable_name + * Printable representation of the path to the file. * @lte * Unnamed data stream of the file. * @data_source_id @@ -1058,24 +1041,15 @@ out: * Returns 0 on success, or a positive error code on failure. */ int -wimboot_set_pointer(const wchar_t *path, +wimboot_set_pointer(HANDLE h, + const wchar_t *printable_name, const struct wim_lookup_table_entry *lte, u64 data_source_id, const u8 lookup_table_hash[SHA1_HASH_SIZE], bool wof_running) { - HANDLE h; DWORD bytes_returned; - int ret; - - - /* Open the file */ - h = win32_open_existing_file(path, GENERIC_WRITE); - if (h == INVALID_HANDLE_VALUE) { - set_errno_from_GetLastError(); - ret = WIMLIB_ERR_OPEN; - goto out; - } + DWORD err; if (wof_running) { /* The WOF driver is running. We can create the reparse point @@ -1097,7 +1071,8 @@ wimboot_set_pointer(const wchar_t *path, /* lookup_table_hash is not necessary */ if (!DeviceIoControl(h, FSCTL_SET_EXTERNAL_BACKING, - &in, sizeof(in), NULL, 0, &bytes_returned, NULL)) + &in, sizeof(in), NULL, 0, + &bytes_returned, NULL)) goto fail; } else { @@ -1155,21 +1130,14 @@ wimboot_set_pointer(const wchar_t *path, goto fail; } - ret = 0; -out_close_handle: - CloseHandle(h); -out: - return ret; + return 0; fail: - { - DWORD err = GetLastError(); - set_errno_from_win32_error(err); - ERROR_WITH_ERRNO("\"%ls\": Couldn't set WIMBoot pointer data " - "(err=0x%08"PRIx32")", path, (u32)err); - ret = WIMLIB_ERR_WIMBOOT; - goto out_close_handle; - } + err = GetLastError(); + set_errno_from_win32_error(err); + ERROR_WITH_ERRNO("\"%ls\": Couldn't set WIMBoot pointer data " + "(err=%"PRIu32")", printable_name, (u32)err); + return WIMLIB_ERR_WIMBOOT; } #endif /* __WIN32__ */