2 * win32_apply.c - Windows-specific code for applying files from a WIM image.
6 * Copyright (C) 2013 Eric Biggers
8 * This file is part of wimlib, a library for working with WIM files.
10 * wimlib is free software; you can redistribute it and/or modify it under the
11 * terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 3 of the License, or (at your option)
15 * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
16 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 * A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with wimlib; if not, see http://www.gnu.org/licenses/.
30 #include "wimlib/win32_common.h"
32 #include "wimlib/apply.h"
33 #include "wimlib/capture.h"
34 #include "wimlib/dentry.h"
35 #include "wimlib/error.h"
36 #include "wimlib/lookup_table.h"
37 #include "wimlib/paths.h"
38 #include "wimlib/resource.h"
39 #include "wimlib/textfile.h"
40 #include "wimlib/xml.h"
41 #include "wimlib/wim.h"
42 #include "wimlib/wimboot.h"
44 struct win32_apply_private_data {
46 struct string_set *prepopulate_pats;
47 void *mem_prepopulate_pats;
48 u8 wim_lookup_table_hash[SHA1_HASH_SIZE];
52 static struct win32_apply_private_data *
53 get_private_data(struct apply_ctx *ctx)
55 BUILD_BUG_ON(sizeof(ctx->private) < sizeof(struct win32_apply_private_data));
56 return (struct win32_apply_private_data *)(ctx->private);
60 free_prepopulate_pats(struct win32_apply_private_data *dat)
62 if (dat->prepopulate_pats) {
63 FREE(dat->prepopulate_pats->strings);
64 FREE(dat->prepopulate_pats);
65 dat->prepopulate_pats = NULL;
68 if (dat->mem_prepopulate_pats) {
69 FREE(dat->mem_prepopulate_pats);
70 dat->mem_prepopulate_pats = NULL;
75 load_prepopulate_pats(struct apply_ctx *ctx)
78 struct wim_dentry *dentry;
79 struct wim_lookup_table_entry *lte;
81 const tchar *path = WIMLIB_WIM_PATH_SEPARATOR_STRING T("Windows")
82 WIMLIB_WIM_PATH_SEPARATOR_STRING T("System32")
83 WIMLIB_WIM_PATH_SEPARATOR_STRING T("WimBootCompress.ini");
86 struct text_file_section sec;
87 struct win32_apply_private_data *dat = get_private_data(ctx);
89 dentry = get_dentry(ctx->wim, path, WIMLIB_CASE_INSENSITIVE);
91 (dentry->d_inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
92 FILE_ATTRIBUTE_REPARSE_POINT |
93 FILE_ATTRIBUTE_ENCRYPTED)) ||
94 !(lte = inode_unnamed_lte(dentry->d_inode, ctx->wim->lookup_table)))
96 WARNING("%"TS" does not exist in WIM image!", path);
97 return WIMLIB_ERR_PATH_DOES_NOT_EXIST;
100 ret = read_full_stream_into_alloc_buf(lte, &buf);
104 s = CALLOC(1, sizeof(struct string_set));
107 return WIMLIB_ERR_NOMEM;
110 sec.name = T("PrepopulateList");
113 ret = do_load_text_file(path, buf, lte->size, &mem, &sec, 1,
114 LOAD_TEXT_FILE_REMOVE_QUOTES |
115 LOAD_TEXT_FILE_NO_WARNINGS,
122 dat->prepopulate_pats = s;
123 dat->mem_prepopulate_pats = mem;
128 in_prepopulate_list(struct wim_dentry *dentry, struct apply_ctx *ctx)
130 struct string_set *pats;
133 pats = get_private_data(ctx)->prepopulate_pats;
136 path = dentry_full_path(dentry);
140 return match_pattern(path, path_basename(path), pats);
144 hash_lookup_table(WIMStruct *wim, u8 hash[SHA1_HASH_SIZE])
146 return wim_reshdr_to_hash(&wim->hdr.lookup_table_reshdr, wim, hash);
150 win32_start_extract(const wchar_t *path, struct apply_ctx *ctx)
154 bool supports_SetFileShortName;
155 struct win32_apply_private_data *dat = get_private_data(ctx);
157 ret = win32_get_vol_flags(path, &vol_flags, &supports_SetFileShortName);
161 ctx->supported_features.archive_files = 1;
162 ctx->supported_features.hidden_files = 1;
163 ctx->supported_features.system_files = 1;
165 if (vol_flags & FILE_FILE_COMPRESSION)
166 ctx->supported_features.compressed_files = 1;
168 if (vol_flags & FILE_SUPPORTS_ENCRYPTION) {
169 ctx->supported_features.encrypted_files = 1;
170 ctx->supported_features.encrypted_directories = 1;
173 ctx->supported_features.not_context_indexed_files = 1;
175 if (vol_flags & FILE_SUPPORTS_SPARSE_FILES)
176 ctx->supported_features.sparse_files = 1;
178 if (vol_flags & FILE_NAMED_STREAMS)
179 ctx->supported_features.named_data_streams = 1;
181 if (vol_flags & FILE_SUPPORTS_HARD_LINKS)
182 ctx->supported_features.hard_links = 1;
184 if (vol_flags & FILE_SUPPORTS_REPARSE_POINTS) {
185 ctx->supported_features.reparse_points = 1;
186 if (win32func_CreateSymbolicLinkW)
187 ctx->supported_features.symlink_reparse_points = 1;
190 if (vol_flags & FILE_PERSISTENT_ACLS)
191 ctx->supported_features.security_descriptors = 1;
193 if (supports_SetFileShortName)
194 ctx->supported_features.short_names = 1;
196 if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT) {
198 ret = load_prepopulate_pats(ctx);
199 if (ret == WIMLIB_ERR_NOMEM)
202 if (!wim_info_get_wimboot(ctx->wim->wim_info,
203 ctx->wim->current_image))
204 WARNING("Image is not marked as WIMBoot compatible!");
207 ret = hash_lookup_table(ctx->wim, dat->wim_lookup_table_hash);
211 ret = wimboot_alloc_data_source_id(ctx->wim->filename,
213 ctx->wim->current_image,
215 &dat->data_source_id,
224 free_prepopulate_pats(dat);
229 win32_finish_extract(struct apply_ctx *ctx)
231 free_prepopulate_pats(get_private_data(ctx));
235 /* Delete a non-directory file, working around Windows quirks. */
237 win32_delete_file_wrapper(const wchar_t *path)
242 if (DeleteFile(path))
245 err = GetLastError();
246 attrib = GetFileAttributes(path);
247 if ((attrib != INVALID_FILE_ATTRIBUTES) &&
248 (attrib & FILE_ATTRIBUTE_READONLY))
250 /* Try again with FILE_ATTRIBUTE_READONLY cleared. */
251 attrib &= ~FILE_ATTRIBUTE_READONLY;
252 if (SetFileAttributes(path, attrib)) {
253 if (DeleteFile(path))
256 err = GetLastError();
265 /* Create a normal file, overwriting one already present. */
267 win32_create_file(const wchar_t *path, struct apply_ctx *ctx, u64 *cookie_ret)
273 * WRITE_OWNER and WRITE_DAC privileges are required for some reason,
274 * even through we're creating a new file.
276 * FILE_FLAG_OPEN_REPARSE_POINT is required to prevent an existing
277 * reparse point from redirecting the creation of the new file
278 * (potentially to an arbitrary location).
280 * CREATE_ALWAYS could be used instead of CREATE_NEW. However, there
281 * are quirks that would need to be handled (e.g. having to set
282 * FILE_ATTRIBUTE_HIDDEN and/or FILE_ATTRIBUTE_SYSTEM if the existing
283 * file had them specified, and/or having to clear
284 * FILE_ATTRIBUTE_READONLY on the existing file). It's simpler to just
285 * call win32_delete_file_wrapper() to delete the existing file in such
286 * a way that already handles the FILE_ATTRIBUTE_READONLY quirk.
289 h = CreateFile(path, WRITE_OWNER | WRITE_DAC, 0, NULL, CREATE_NEW,
290 FILE_FLAG_BACKUP_SEMANTICS |
291 FILE_FLAG_OPEN_REPARSE_POINT, NULL);
292 if (h == INVALID_HANDLE_VALUE) {
293 DWORD err = GetLastError();
295 if (err == ERROR_FILE_EXISTS && win32_delete_file_wrapper(path))
297 set_errno_from_win32_error(err);
298 return WIMLIB_ERR_OPEN;
305 win32_create_directory(const wchar_t *path, struct apply_ctx *ctx,
308 if (!CreateDirectory(path, NULL))
309 if (GetLastError() != ERROR_ALREADY_EXISTS)
314 set_errno_from_GetLastError();
315 return WIMLIB_ERR_MKDIR;
319 win32_create_hardlink(const wchar_t *oldpath, const wchar_t *newpath,
320 struct apply_ctx *ctx)
322 if (!CreateHardLink(newpath, oldpath, NULL)) {
323 if (GetLastError() != ERROR_ALREADY_EXISTS)
325 if (!win32_delete_file_wrapper(newpath))
327 if (!CreateHardLink(newpath, oldpath, NULL))
333 set_errno_from_GetLastError();
334 return WIMLIB_ERR_LINK;
338 win32_create_symlink(const wchar_t *oldpath, const wchar_t *newpath,
339 struct apply_ctx *ctx)
341 if (!(*win32func_CreateSymbolicLinkW)(newpath, oldpath, 0)) {
342 if (GetLastError() != ERROR_ALREADY_EXISTS)
344 if (!win32_delete_file_wrapper(newpath))
346 if (!(*win32func_CreateSymbolicLinkW)(newpath, oldpath, 0))
352 set_errno_from_GetLastError();
353 return WIMLIB_ERR_LINK;
357 win32_extract_wim_chunk(const void *buf, size_t len, void *arg)
359 HANDLE h = (HANDLE)arg;
360 DWORD nbytes_written;
362 if (unlikely(!WriteFile(h, buf, len, &nbytes_written, NULL)))
364 if (unlikely(nbytes_written != len))
369 set_errno_from_GetLastError();
370 return WIMLIB_ERR_WRITE;
374 win32_extract_stream(const wchar_t *path, const wchar_t *stream_name,
375 size_t stream_name_nchars,
376 struct wim_lookup_table_entry *lte, struct apply_ctx *ctx)
378 DWORD creationDisposition = OPEN_EXISTING;
379 wchar_t *stream_path = (wchar_t*)path;
383 if (stream_name_nchars) {
384 creationDisposition = CREATE_ALWAYS;
385 stream_path = alloca(sizeof(wchar_t) *
387 wcslen(stream_name) + 1));
388 tsprintf(stream_path, L"%ls:%ls", path, stream_name);
391 h = CreateFile(stream_path, FILE_WRITE_DATA, 0, NULL,
392 creationDisposition, FILE_FLAG_BACKUP_SEMANTICS |
393 FILE_FLAG_OPEN_REPARSE_POINT,
395 if (h == INVALID_HANDLE_VALUE)
400 goto out_close_handle;
401 ret = extract_stream(lte, lte->size, win32_extract_wim_chunk, h);
410 set_errno_from_GetLastError();
411 return WIMLIB_ERR_WRITE;
415 win32_extract_unnamed_stream(file_spec_t file,
416 struct wim_lookup_table_entry *lte,
417 struct apply_ctx *ctx,
418 struct wim_dentry *dentry)
420 if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT
422 && lte->resource_location == RESOURCE_IN_WIM
423 && lte->rspec->wim == ctx->wim
424 && lte->size == lte->rspec->uncompressed_size
425 && !in_prepopulate_list(dentry, ctx))
427 const struct win32_apply_private_data *dat;
429 dat = get_private_data(ctx);
430 return wimboot_set_pointer(file.path, lte,
432 dat->wim_lookup_table_hash,
436 return win32_extract_stream(file.path, NULL, 0, lte, ctx);
440 win32_extract_named_stream(file_spec_t file, const wchar_t *stream_name,
441 size_t stream_name_nchars,
442 struct wim_lookup_table_entry *lte, struct apply_ctx *ctx)
444 return win32_extract_stream(file.path, stream_name,
445 stream_name_nchars, lte, ctx);
448 struct win32_encrypted_extract_ctx {
449 const struct wim_lookup_table_entry *lte;
454 win32_encrypted_import_cb(unsigned char *data, void *_import_ctx,
455 unsigned long *len_p)
457 struct win32_encrypted_extract_ctx *import_ctx = _import_ctx;
458 unsigned long len = *len_p;
459 const struct wim_lookup_table_entry *lte = import_ctx->lte;
461 len = min(len, lte->size - import_ctx->offset);
463 if (read_partial_wim_stream_into_buf(lte, len, import_ctx->offset, data))
464 return ERROR_READ_FAULT;
466 import_ctx->offset += len;
468 return ERROR_SUCCESS;
472 win32_extract_encrypted_stream(const wchar_t *path,
473 struct wim_lookup_table_entry *lte,
474 struct apply_ctx *ctx)
479 struct win32_encrypted_extract_ctx extract_ctx;
481 err = OpenEncryptedFileRaw(path, CREATE_FOR_IMPORT, &file_ctx);
482 if (err != ERROR_SUCCESS) {
483 set_errno_from_win32_error(err);
484 ret = WIMLIB_ERR_OPEN;
488 extract_ctx.lte = lte;
489 extract_ctx.offset = 0;
490 err = WriteEncryptedFileRaw(win32_encrypted_import_cb, &extract_ctx,
492 if (err != ERROR_SUCCESS) {
493 set_errno_from_win32_error(err);
494 ret = WIMLIB_ERR_WRITE;
500 CloseEncryptedFileRaw(file_ctx);
506 win32_set_special_file_attributes(const wchar_t *path, u32 attributes)
510 USHORT compression_format = COMPRESSION_FORMAT_DEFAULT;
511 DWORD bytes_returned;
513 h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
514 if (h == INVALID_HANDLE_VALUE)
517 if (attributes & FILE_ATTRIBUTE_SPARSE_FILE)
518 if (!DeviceIoControl(h, FSCTL_SET_SPARSE,
521 &bytes_returned, NULL))
522 goto error_close_handle;
524 if (attributes & FILE_ATTRIBUTE_COMPRESSED)
525 if (!DeviceIoControl(h, FSCTL_SET_COMPRESSION,
526 &compression_format, sizeof(USHORT),
528 &bytes_returned, NULL))
529 goto error_close_handle;
534 if (attributes & FILE_ATTRIBUTE_ENCRYPTED)
535 if (!EncryptFile(path))
541 err = GetLastError();
549 win32_set_file_attributes(const wchar_t *path, u32 attributes,
550 struct apply_ctx *ctx, unsigned pass)
552 u32 special_attributes =
553 FILE_ATTRIBUTE_REPARSE_POINT |
554 FILE_ATTRIBUTE_DIRECTORY |
555 FILE_ATTRIBUTE_SPARSE_FILE |
556 FILE_ATTRIBUTE_COMPRESSED |
557 FILE_ATTRIBUTE_ENCRYPTED;
558 u32 actual_attributes;
560 /* Delay setting FILE_ATTRIBUTE_READONLY on the initial pass (when files
561 * are created, but data not extracted); otherwise the system will
562 * refuse access to the file even if the process has SeRestorePrivilege.
565 attributes &= ~FILE_ATTRIBUTE_READONLY;
567 if (!SetFileAttributes(path, attributes & ~special_attributes))
573 if (attributes & (FILE_ATTRIBUTE_SPARSE_FILE |
574 FILE_ATTRIBUTE_ENCRYPTED |
575 FILE_ATTRIBUTE_COMPRESSED))
576 if (!win32_set_special_file_attributes(path, attributes))
579 /* If file is not supposed to be encrypted or compressed, remove
580 * defaulted encrypted or compressed attributes (from creating file in
581 * encrypted or compressed directory). */
582 actual_attributes = GetFileAttributes(path);
583 if (actual_attributes == INVALID_FILE_ATTRIBUTES)
586 if ((actual_attributes & FILE_ATTRIBUTE_ENCRYPTED) &&
587 !(attributes & FILE_ATTRIBUTE_ENCRYPTED))
588 if (!DecryptFile(path, 0))
590 if ((actual_attributes & FILE_ATTRIBUTE_COMPRESSED) &&
591 !(attributes & FILE_ATTRIBUTE_COMPRESSED))
594 DWORD bytes_returned;
595 USHORT compression_format = COMPRESSION_FORMAT_NONE;
597 h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
598 if (h == INVALID_HANDLE_VALUE)
601 if (!DeviceIoControl(h, FSCTL_SET_COMPRESSION,
602 &compression_format, sizeof(USHORT),
604 &bytes_returned, NULL))
606 DWORD err = GetLastError();
619 set_errno_from_GetLastError();
620 return WIMLIB_ERR_SET_ATTRIBUTES;
624 win32_set_reparse_data(const wchar_t *path, const u8 *rpbuf, u16 rpbuflen,
625 struct apply_ctx *ctx)
629 DWORD bytes_returned;
631 h = win32_open_existing_file(path, GENERIC_WRITE);
632 if (h == INVALID_HANDLE_VALUE)
635 if (!DeviceIoControl(h, FSCTL_SET_REPARSE_POINT,
636 (void*)rpbuf, rpbuflen,
637 NULL, 0, &bytes_returned, NULL))
638 goto error_close_handle;
646 err = GetLastError();
650 set_errno_from_GetLastError();
651 return WIMLIB_ERR_WRITE; /* XXX: need better error code */
655 win32_set_short_name(const wchar_t *path, const wchar_t *short_name,
656 size_t short_name_nchars, struct apply_ctx *ctx)
661 h = win32_open_existing_file(path, GENERIC_WRITE | DELETE);
662 if (h == INVALID_HANDLE_VALUE)
665 if (short_name_nchars) {
666 if (!SetFileShortName(h, short_name))
667 goto error_close_handle;
668 } else if (running_on_windows_7_or_later()) {
669 if (!SetFileShortName(h, L""))
670 goto error_close_handle;
679 err = GetLastError();
683 set_errno_from_GetLastError();
684 return WIMLIB_ERR_WRITE; /* XXX: need better error code */
688 do_win32_set_security_descriptor(HANDLE h, const wchar_t *path,
689 SECURITY_INFORMATION info,
690 PSECURITY_DESCRIPTOR desc)
693 if (func_NtSetSecurityObject) {
694 return (*func_RtlNtStatusToDosError)(
695 (*func_NtSetSecurityObject)(h, info, desc));
698 if (SetFileSecurity(path, info, desc))
699 return ERROR_SUCCESS;
701 return GetLastError();
705 * Set an arbitrary security descriptor on an arbitrary file (or directory),
706 * working around bugs and design flaws in the Windows operating system.
708 * On success, return 0. On failure, return WIMLIB_ERR_SET_SECURITY and set
709 * errno. Note: if WIMLIB_EXTRACT_FLAG_STRICT_ACLS is not set in
710 * ctx->extract_flags, this function succeeds iff any part of the security
711 * descriptor was successfully set.
714 win32_set_security_descriptor(const wchar_t *path, const u8 *desc,
715 size_t desc_size, struct apply_ctx *ctx)
717 SECURITY_INFORMATION info;
721 /* We really just want to set entire the security descriptor as-is, but
722 * all available APIs require specifying the specific parts of the
723 * descriptor being set. Start out by requesting all parts be set. If
724 * permissions problems are encountered, fall back to omitting some
725 * parts (first the SACL, then the DACL, then the owner), unless the
726 * WIMLIB_EXTRACT_FLAG_STRICT_ACLS flag has been enabled. */
727 info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
728 DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
730 h = INVALID_HANDLE_VALUE;
732 /* Prefer NtSetSecurityObject() to SetFileSecurity(). SetFileSecurity()
733 * itself necessarily uses NtSetSecurityObject() as the latter is the
734 * underlying system call for setting security information, but
735 * SetFileSecurity() opens the handle with NtCreateFile() without
736 * FILE_OPEN_FILE_BACKUP_INTENT. Hence, access checks are done and due
737 * to the Windows security model, even a process running as the
738 * Administrator can have access denied. (Of course, this not mentioned
739 * in the MS "documentation".) */
742 if (func_NtSetSecurityObject) {
743 DWORD dwDesiredAccess;
745 /* Open a handle for NtSetSecurityObject() with as many relevant
746 * access rights as possible.
748 * We don't know which rights will be actually granted. It
749 * could be less than what is needed to actually assign the full
750 * security descriptor, especially if the process is running as
751 * a non-Administrator. However, by default we just do the best
752 * we can, unless WIMLIB_EXTRACT_FLAG_STRICT_ACLS has been
753 * enabled. The MAXIMUM_ALLOWED access right is seemingly
754 * designed for this use case; however, it does not work
755 * properly in all cases: it can cause CreateFile() to fail with
756 * ERROR_ACCESS_DENIED, even though by definition
757 * MAXIMUM_ALLOWED access only requests access rights that are
758 * *not* denied. (Needless to say, MS does not document this
761 dwDesiredAccess = WRITE_DAC |
763 ACCESS_SYSTEM_SECURITY;
767 h = win32_open_existing_file(path, dwDesiredAccess);
768 if (h != INVALID_HANDLE_VALUE)
770 err = GetLastError();
771 if (err == ERROR_ACCESS_DENIED ||
772 err == ERROR_PRIVILEGE_NOT_HELD)
774 /* Don't increment partial_security_descriptors
775 * here or check WIMLIB_EXTRACT_FLAG_STRICT_ACLS
776 * here. It will be done later if needed; here
777 * we are just trying to get as many relevant
778 * access rights as possible. */
779 if (dwDesiredAccess & ACCESS_SYSTEM_SECURITY) {
780 dwDesiredAccess &= ~ACCESS_SYSTEM_SECURITY;
783 if (dwDesiredAccess & WRITE_DAC) {
784 dwDesiredAccess &= ~WRITE_DAC;
787 if (dwDesiredAccess & WRITE_OWNER) {
788 dwDesiredAccess &= ~WRITE_OWNER;
792 /* Other error, or couldn't open the file even with no
793 * access rights specified. Something else must be
795 set_errno_from_win32_error(err);
796 return WIMLIB_ERR_SET_SECURITY;
801 /* Try setting the security descriptor. */
805 err = do_win32_set_security_descriptor(h, path, info,
806 (PSECURITY_DESCRIPTOR)desc);
807 if (err == ERROR_SUCCESS) {
812 /* Failed to set the requested parts of the security descriptor.
813 * If the error was permissions-related, try to set fewer parts
814 * of the security descriptor, unless
815 * WIMLIB_EXTRACT_FLAG_STRICT_ACLS is enabled. */
816 if ((err == ERROR_PRIVILEGE_NOT_HELD ||
817 err == ERROR_ACCESS_DENIED) &&
818 !(ctx->extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_ACLS))
820 if (info & SACL_SECURITY_INFORMATION) {
821 info &= ~SACL_SECURITY_INFORMATION;
822 ctx->partial_security_descriptors++;
825 if (info & DACL_SECURITY_INFORMATION) {
826 info &= ~DACL_SECURITY_INFORMATION;
829 if (info & OWNER_SECURITY_INFORMATION) {
830 info &= ~OWNER_SECURITY_INFORMATION;
833 /* Nothing left except GROUP, and if we removed it we
834 * wouldn't have anything at all. */
836 /* No part of the security descriptor could be set, or
837 * WIMLIB_EXTRACT_FLAG_STRICT_ACLS is enabled and the full
838 * security descriptor could not be set. */
839 if (!(info & SACL_SECURITY_INFORMATION))
840 ctx->partial_security_descriptors--;
841 set_errno_from_win32_error(err);
842 ret = WIMLIB_ERR_SET_SECURITY;
846 /* Close handle opened for NtSetSecurityObject(). */
848 if (func_NtSetSecurityObject)
855 win32_set_timestamps(const wchar_t *path, u64 creation_time,
856 u64 last_write_time, u64 last_access_time,
857 struct apply_ctx *ctx)
861 FILETIME creationTime = {.dwLowDateTime = creation_time & 0xffffffff,
862 .dwHighDateTime = creation_time >> 32};
863 FILETIME lastAccessTime = {.dwLowDateTime = last_access_time & 0xffffffff,
864 .dwHighDateTime = last_access_time >> 32};
865 FILETIME lastWriteTime = {.dwLowDateTime = last_write_time & 0xffffffff,
866 .dwHighDateTime = last_write_time >> 32};
868 h = win32_open_existing_file(path, FILE_WRITE_ATTRIBUTES);
869 if (h == INVALID_HANDLE_VALUE)
872 if (!SetFileTime(h, &creationTime, &lastAccessTime, &lastWriteTime))
873 goto error_close_handle;
881 err = GetLastError();
885 set_errno_from_GetLastError();
886 return WIMLIB_ERR_SET_TIMESTAMPS;
889 const struct apply_operations win32_apply_ops = {
892 .target_is_root = win32_path_is_root_of_drive,
893 .start_extract = win32_start_extract,
894 .finish_extract = win32_finish_extract,
895 .abort_extract = win32_finish_extract,
896 .create_file = win32_create_file,
897 .create_directory = win32_create_directory,
898 .create_hardlink = win32_create_hardlink,
899 .create_symlink = win32_create_symlink,
900 .extract_unnamed_stream = win32_extract_unnamed_stream,
901 .extract_named_stream = win32_extract_named_stream,
902 .extract_encrypted_stream = win32_extract_encrypted_stream,
903 .set_file_attributes = win32_set_file_attributes,
904 .set_reparse_data = win32_set_reparse_data,
905 .set_short_name = win32_set_short_name,
906 .set_security_descriptor = win32_set_security_descriptor,
907 .set_timestamps = win32_set_timestamps,
909 .path_prefix = L"\\\\?\\",
910 .path_prefix_nchars = 4,
911 .path_separator = L'\\',
914 .requires_realtarget_in_paths = 1,
915 .realpath_works_on_nonexisting_files = 1,
916 .root_directory_is_special = 1,
917 .requires_final_set_attributes_pass = 1,
918 .extract_encrypted_stream_creates_file = 1,
919 .requires_short_name_reordering = 1, /* TODO: check if this is really needed */
922 #endif /* __WIN32__ */