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/textfile.h"
39 #include "wimlib/xml.h"
40 #include "wimlib/wim.h"
41 #include "wimlib/wimboot.h"
44 ctx_save_data_source_id(struct apply_ctx *ctx, u64 data_source_id)
46 ctx->private[0] = data_source_id & 0xFFFFFFFF;
47 ctx->private[1] = data_source_id >> 32;
51 ctx_get_data_source_id(const struct apply_ctx *ctx)
53 return (u32)ctx->private[0] | ((u64)(u32)ctx->private[1] << 32);
57 set_prepopulate_pats(struct apply_ctx *ctx, struct string_set *s)
59 ctx->private[2] = (intptr_t)s;
62 static struct string_set *
63 alloc_prepopulate_pats(struct apply_ctx *ctx)
65 struct string_set *s = CALLOC(1, sizeof(*s));
66 set_prepopulate_pats(ctx, s);
70 static struct string_set *
71 get_prepopulate_pats(struct apply_ctx *ctx)
73 return (struct string_set *)(ctx->private[2]);
77 free_prepopulate_pats(struct apply_ctx *ctx)
81 s = get_prepopulate_pats(ctx);
86 set_prepopulate_pats(ctx, NULL);
88 FREE((void *)ctx->private[3]);
89 ctx->private[3] = (intptr_t)NULL;
93 load_prepopulate_pats(struct apply_ctx *ctx)
96 struct wim_dentry *dentry;
97 struct wim_lookup_table_entry *lte;
99 const tchar *path = WIMLIB_WIM_PATH_SEPARATOR_STRING T("Windows")
100 WIMLIB_WIM_PATH_SEPARATOR_STRING T("System32")
101 WIMLIB_WIM_PATH_SEPARATOR_STRING T("WimBootCompress.ini");
104 struct text_file_section sec;
106 dentry = get_dentry(ctx->wim, path, WIMLIB_CASE_INSENSITIVE);
108 (dentry->d_inode->i_attributes & (FILE_ATTRIBUTE_DIRECTORY |
109 FILE_ATTRIBUTE_REPARSE_POINT |
110 FILE_ATTRIBUTE_ENCRYPTED)) ||
111 !(lte = inode_unnamed_lte(dentry->d_inode, ctx->wim->lookup_table)))
113 WARNING("%"TS" does not exist in WIM image!", path);
114 return WIMLIB_ERR_PATH_DOES_NOT_EXIST;
117 ret = read_full_stream_into_alloc_buf(lte, &buf);
121 s = alloc_prepopulate_pats(ctx);
124 return WIMLIB_ERR_NOMEM;
127 sec.name = T("PrepopulateList");
130 ret = do_load_text_file(path, buf, lte->size, &mem, &sec, 1,
131 LOAD_TEXT_FILE_REMOVE_QUOTES |
132 LOAD_TEXT_FILE_NO_WARNINGS,
136 free_prepopulate_pats(ctx);
139 ctx->private[3] = (intptr_t)mem;
144 in_prepopulate_list(struct wim_dentry *dentry,
145 struct apply_ctx *ctx)
147 struct string_set *pats;
150 pats = get_prepopulate_pats(ctx);
153 path = dentry_full_path(dentry);
157 return match_pattern(path, path_basename(path), pats);
161 win32_start_extract(const wchar_t *path, struct apply_ctx *ctx)
165 bool supports_SetFileShortName;
167 ret = win32_get_vol_flags(path, &vol_flags, &supports_SetFileShortName);
171 ctx->supported_features.archive_files = 1;
172 ctx->supported_features.hidden_files = 1;
173 ctx->supported_features.system_files = 1;
175 if (vol_flags & FILE_FILE_COMPRESSION)
176 ctx->supported_features.compressed_files = 1;
178 if (vol_flags & FILE_SUPPORTS_ENCRYPTION) {
179 ctx->supported_features.encrypted_files = 1;
180 ctx->supported_features.encrypted_directories = 1;
183 ctx->supported_features.not_context_indexed_files = 1;
185 if (vol_flags & FILE_SUPPORTS_SPARSE_FILES)
186 ctx->supported_features.sparse_files = 1;
188 if (vol_flags & FILE_NAMED_STREAMS)
189 ctx->supported_features.named_data_streams = 1;
191 if (vol_flags & FILE_SUPPORTS_HARD_LINKS)
192 ctx->supported_features.hard_links = 1;
194 if (vol_flags & FILE_SUPPORTS_REPARSE_POINTS) {
195 ctx->supported_features.reparse_points = 1;
196 if (win32func_CreateSymbolicLinkW)
197 ctx->supported_features.symlink_reparse_points = 1;
200 if (vol_flags & FILE_PERSISTENT_ACLS)
201 ctx->supported_features.security_descriptors = 1;
203 if (supports_SetFileShortName)
204 ctx->supported_features.short_names = 1;
206 if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT) {
208 ret = load_prepopulate_pats(ctx);
209 if (ret == WIMLIB_ERR_NOMEM)
214 if (!wim_info_get_wimboot(ctx->wim->wim_info,
215 ctx->wim->current_image))
216 WARNING("Image is not marked as WIMBoot compatible!");
218 ret = wimboot_alloc_data_source_id(ctx->wim->filename,
219 ctx->wim->current_image,
220 path, &data_source_id);
222 free_prepopulate_pats(ctx);
226 ctx_save_data_source_id(ctx, data_source_id);
233 win32_finish_extract(struct apply_ctx *ctx)
235 free_prepopulate_pats(ctx);
239 /* Delete a non-directory file, working around Windows quirks. */
241 win32_delete_file_wrapper(const wchar_t *path)
246 if (DeleteFile(path))
249 err = GetLastError();
250 attrib = GetFileAttributes(path);
251 if ((attrib != INVALID_FILE_ATTRIBUTES) &&
252 (attrib & FILE_ATTRIBUTE_READONLY))
254 /* Try again with FILE_ATTRIBUTE_READONLY cleared. */
255 attrib &= ~FILE_ATTRIBUTE_READONLY;
256 if (SetFileAttributes(path, attrib)) {
257 if (DeleteFile(path))
260 err = GetLastError();
269 /* Create a normal file, overwriting one already present. */
271 win32_create_file(const wchar_t *path, struct apply_ctx *ctx, u64 *cookie_ret)
277 * WRITE_OWNER and WRITE_DAC privileges are required for some reason,
278 * even through we're creating a new file.
280 * FILE_FLAG_OPEN_REPARSE_POINT is required to prevent an existing
281 * reparse point from redirecting the creation of the new file
282 * (potentially to an arbitrary location).
284 * CREATE_ALWAYS could be used instead of CREATE_NEW. However, there
285 * are quirks that would need to be handled (e.g. having to set
286 * FILE_ATTRIBUTE_HIDDEN and/or FILE_ATTRIBUTE_SYSTEM if the existing
287 * file had them specified, and/or having to clear
288 * FILE_ATTRIBUTE_READONLY on the existing file). It's simpler to just
289 * call win32_delete_file_wrapper() to delete the existing file in such
290 * a way that already handles the FILE_ATTRIBUTE_READONLY quirk.
293 h = CreateFile(path, WRITE_OWNER | WRITE_DAC, 0, NULL, CREATE_NEW,
294 FILE_FLAG_BACKUP_SEMANTICS |
295 FILE_FLAG_OPEN_REPARSE_POINT, NULL);
296 if (h == INVALID_HANDLE_VALUE) {
297 DWORD err = GetLastError();
299 if (err == ERROR_FILE_EXISTS && win32_delete_file_wrapper(path))
301 set_errno_from_win32_error(err);
302 return WIMLIB_ERR_OPEN;
309 win32_create_directory(const wchar_t *path, struct apply_ctx *ctx,
312 if (!CreateDirectory(path, NULL))
313 if (GetLastError() != ERROR_ALREADY_EXISTS)
318 set_errno_from_GetLastError();
319 return WIMLIB_ERR_MKDIR;
323 win32_create_hardlink(const wchar_t *oldpath, const wchar_t *newpath,
324 struct apply_ctx *ctx)
326 if (!CreateHardLink(newpath, oldpath, NULL)) {
327 if (GetLastError() != ERROR_ALREADY_EXISTS)
329 if (!win32_delete_file_wrapper(newpath))
331 if (!CreateHardLink(newpath, oldpath, NULL))
337 set_errno_from_GetLastError();
338 return WIMLIB_ERR_LINK;
342 win32_create_symlink(const wchar_t *oldpath, const wchar_t *newpath,
343 struct apply_ctx *ctx)
345 if (!(*win32func_CreateSymbolicLinkW)(newpath, oldpath, 0)) {
346 if (GetLastError() != ERROR_ALREADY_EXISTS)
348 if (!win32_delete_file_wrapper(newpath))
350 if (!(*win32func_CreateSymbolicLinkW)(newpath, oldpath, 0))
356 set_errno_from_GetLastError();
357 return WIMLIB_ERR_LINK;
361 win32_extract_wim_chunk(const void *buf, size_t len, void *arg)
363 HANDLE h = (HANDLE)arg;
364 DWORD nbytes_written;
366 if (unlikely(!WriteFile(h, buf, len, &nbytes_written, NULL)))
368 if (unlikely(nbytes_written != len))
373 set_errno_from_GetLastError();
374 return WIMLIB_ERR_WRITE;
378 win32_extract_stream(const wchar_t *path, const wchar_t *stream_name,
379 size_t stream_name_nchars,
380 struct wim_lookup_table_entry *lte, struct apply_ctx *ctx)
382 DWORD creationDisposition = OPEN_EXISTING;
383 wchar_t *stream_path = (wchar_t*)path;
387 if (stream_name_nchars) {
388 creationDisposition = CREATE_ALWAYS;
389 stream_path = alloca(sizeof(wchar_t) *
391 wcslen(stream_name) + 1));
392 tsprintf(stream_path, L"%ls:%ls", path, stream_name);
395 h = CreateFile(stream_path, FILE_WRITE_DATA, 0, NULL,
396 creationDisposition, FILE_FLAG_BACKUP_SEMANTICS |
397 FILE_FLAG_OPEN_REPARSE_POINT,
399 if (h == INVALID_HANDLE_VALUE)
404 goto out_close_handle;
405 ret = extract_stream(lte, lte->size, win32_extract_wim_chunk, h);
414 set_errno_from_GetLastError();
415 return WIMLIB_ERR_WRITE;
419 win32_extract_unnamed_stream(file_spec_t file,
420 struct wim_lookup_table_entry *lte,
421 struct apply_ctx *ctx,
422 struct wim_dentry *dentry)
424 if (ctx->extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT
426 && lte->resource_location == RESOURCE_IN_WIM
427 && lte->rspec->wim == ctx->wim
428 && !in_prepopulate_list(dentry, ctx))
430 return wimboot_set_pointer(file.path,
431 ctx_get_data_source_id(ctx),
435 return win32_extract_stream(file.path, NULL, 0, lte, ctx);
439 win32_extract_named_stream(file_spec_t file, const wchar_t *stream_name,
440 size_t stream_name_nchars,
441 struct wim_lookup_table_entry *lte, struct apply_ctx *ctx)
443 return win32_extract_stream(file.path, stream_name,
444 stream_name_nchars, lte, ctx);
447 struct win32_encrypted_extract_ctx {
448 const struct wim_lookup_table_entry *lte;
453 win32_encrypted_import_cb(unsigned char *data, void *_import_ctx,
454 unsigned long *len_p)
456 struct win32_encrypted_extract_ctx *import_ctx = _import_ctx;
457 unsigned long len = *len_p;
458 const struct wim_lookup_table_entry *lte = import_ctx->lte;
460 len = min(len, lte->size - import_ctx->offset);
462 if (read_partial_wim_stream_into_buf(lte, len, import_ctx->offset, data))
463 return ERROR_READ_FAULT;
465 import_ctx->offset += len;
467 return ERROR_SUCCESS;
471 win32_extract_encrypted_stream(const wchar_t *path,
472 struct wim_lookup_table_entry *lte,
473 struct apply_ctx *ctx)
478 struct win32_encrypted_extract_ctx extract_ctx;
480 err = OpenEncryptedFileRaw(path, CREATE_FOR_IMPORT, &file_ctx);
481 if (err != ERROR_SUCCESS) {
482 set_errno_from_win32_error(err);
483 ret = WIMLIB_ERR_OPEN;
487 extract_ctx.lte = lte;
488 extract_ctx.offset = 0;
489 err = WriteEncryptedFileRaw(win32_encrypted_import_cb, &extract_ctx,
491 if (err != ERROR_SUCCESS) {
492 set_errno_from_win32_error(err);
493 ret = WIMLIB_ERR_WRITE;
499 CloseEncryptedFileRaw(file_ctx);
505 win32_set_special_file_attributes(const wchar_t *path, u32 attributes)
509 USHORT compression_format = COMPRESSION_FORMAT_DEFAULT;
510 DWORD bytes_returned;
512 h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
513 if (h == INVALID_HANDLE_VALUE)
516 if (attributes & FILE_ATTRIBUTE_SPARSE_FILE)
517 if (!DeviceIoControl(h, FSCTL_SET_SPARSE,
520 &bytes_returned, NULL))
521 goto error_close_handle;
523 if (attributes & FILE_ATTRIBUTE_COMPRESSED)
524 if (!DeviceIoControl(h, FSCTL_SET_COMPRESSION,
525 &compression_format, sizeof(USHORT),
527 &bytes_returned, NULL))
528 goto error_close_handle;
533 if (attributes & FILE_ATTRIBUTE_ENCRYPTED)
534 if (!EncryptFile(path))
540 err = GetLastError();
548 win32_set_file_attributes(const wchar_t *path, u32 attributes,
549 struct apply_ctx *ctx, unsigned pass)
551 u32 special_attributes =
552 FILE_ATTRIBUTE_REPARSE_POINT |
553 FILE_ATTRIBUTE_DIRECTORY |
554 FILE_ATTRIBUTE_SPARSE_FILE |
555 FILE_ATTRIBUTE_COMPRESSED |
556 FILE_ATTRIBUTE_ENCRYPTED;
557 u32 actual_attributes;
559 /* Delay setting FILE_ATTRIBUTE_READONLY on the initial pass (when files
560 * are created, but data not extracted); otherwise the system will
561 * refuse access to the file even if the process has SeRestorePrivilege.
564 attributes &= ~FILE_ATTRIBUTE_READONLY;
566 if (!SetFileAttributes(path, attributes & ~special_attributes))
572 if (attributes & (FILE_ATTRIBUTE_SPARSE_FILE |
573 FILE_ATTRIBUTE_ENCRYPTED |
574 FILE_ATTRIBUTE_COMPRESSED))
575 if (!win32_set_special_file_attributes(path, attributes))
578 /* If file is not supposed to be encrypted or compressed, remove
579 * defaulted encrypted or compressed attributes (from creating file in
580 * encrypted or compressed directory). */
581 actual_attributes = GetFileAttributes(path);
582 if (actual_attributes == INVALID_FILE_ATTRIBUTES)
585 if ((actual_attributes & FILE_ATTRIBUTE_ENCRYPTED) &&
586 !(attributes & FILE_ATTRIBUTE_ENCRYPTED))
587 if (!DecryptFile(path, 0))
589 if ((actual_attributes & FILE_ATTRIBUTE_COMPRESSED) &&
590 !(attributes & FILE_ATTRIBUTE_COMPRESSED))
593 DWORD bytes_returned;
594 USHORT compression_format = COMPRESSION_FORMAT_NONE;
596 h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
597 if (h == INVALID_HANDLE_VALUE)
600 if (!DeviceIoControl(h, FSCTL_SET_COMPRESSION,
601 &compression_format, sizeof(USHORT),
603 &bytes_returned, NULL))
605 DWORD err = GetLastError();
618 set_errno_from_GetLastError();
619 return WIMLIB_ERR_SET_ATTRIBUTES;
623 win32_set_reparse_data(const wchar_t *path, const u8 *rpbuf, u16 rpbuflen,
624 struct apply_ctx *ctx)
628 DWORD bytes_returned;
630 h = win32_open_existing_file(path, GENERIC_WRITE);
631 if (h == INVALID_HANDLE_VALUE)
634 if (!DeviceIoControl(h, FSCTL_SET_REPARSE_POINT,
635 (void*)rpbuf, rpbuflen,
636 NULL, 0, &bytes_returned, NULL))
637 goto error_close_handle;
645 err = GetLastError();
649 set_errno_from_GetLastError();
650 return WIMLIB_ERR_WRITE; /* XXX: need better error code */
654 win32_set_short_name(const wchar_t *path, const wchar_t *short_name,
655 size_t short_name_nchars, struct apply_ctx *ctx)
660 h = win32_open_existing_file(path, GENERIC_WRITE | DELETE);
661 if (h == INVALID_HANDLE_VALUE)
664 if (short_name_nchars) {
665 if (!SetFileShortName(h, short_name))
666 goto error_close_handle;
667 } else if (running_on_windows_7_or_later()) {
668 if (!SetFileShortName(h, L""))
669 goto error_close_handle;
678 err = GetLastError();
682 set_errno_from_GetLastError();
683 return WIMLIB_ERR_WRITE; /* XXX: need better error code */
687 do_win32_set_security_descriptor(HANDLE h, const wchar_t *path,
688 SECURITY_INFORMATION info,
689 PSECURITY_DESCRIPTOR desc)
692 if (func_NtSetSecurityObject) {
693 return (*func_RtlNtStatusToDosError)(
694 (*func_NtSetSecurityObject)(h, info, desc));
697 if (SetFileSecurity(path, info, desc))
698 return ERROR_SUCCESS;
700 return GetLastError();
704 * Set an arbitrary security descriptor on an arbitrary file (or directory),
705 * working around bugs and design flaws in the Windows operating system.
707 * On success, return 0. On failure, return WIMLIB_ERR_SET_SECURITY and set
708 * errno. Note: if WIMLIB_EXTRACT_FLAG_STRICT_ACLS is not set in
709 * ctx->extract_flags, this function succeeds iff any part of the security
710 * descriptor was successfully set.
713 win32_set_security_descriptor(const wchar_t *path, const u8 *desc,
714 size_t desc_size, struct apply_ctx *ctx)
716 SECURITY_INFORMATION info;
720 /* We really just want to set entire the security descriptor as-is, but
721 * all available APIs require specifying the specific parts of the
722 * descriptor being set. Start out by requesting all parts be set. If
723 * permissions problems are encountered, fall back to omitting some
724 * parts (first the SACL, then the DACL, then the owner), unless the
725 * WIMLIB_EXTRACT_FLAG_STRICT_ACLS flag has been enabled. */
726 info = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION |
727 DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
729 h = INVALID_HANDLE_VALUE;
731 /* Prefer NtSetSecurityObject() to SetFileSecurity(). SetFileSecurity()
732 * itself necessarily uses NtSetSecurityObject() as the latter is the
733 * underlying system call for setting security information, but
734 * SetFileSecurity() opens the handle with NtCreateFile() without
735 * FILE_OPEN_FILE_BACKUP_INTENT. Hence, access checks are done and due
736 * to the Windows security model, even a process running as the
737 * Administrator can have access denied. (Of course, this not mentioned
738 * in the MS "documentation".) */
741 if (func_NtSetSecurityObject) {
742 DWORD dwDesiredAccess;
744 /* Open a handle for NtSetSecurityObject() with as many relevant
745 * access rights as possible.
747 * We don't know which rights will be actually granted. It
748 * could be less than what is needed to actually assign the full
749 * security descriptor, especially if the process is running as
750 * a non-Administrator. However, by default we just do the best
751 * we can, unless WIMLIB_EXTRACT_FLAG_STRICT_ACLS has been
752 * enabled. The MAXIMUM_ALLOWED access right is seemingly
753 * designed for this use case; however, it does not work
754 * properly in all cases: it can cause CreateFile() to fail with
755 * ERROR_ACCESS_DENIED, even though by definition
756 * MAXIMUM_ALLOWED access only requests access rights that are
757 * *not* denied. (Needless to say, MS does not document this
760 dwDesiredAccess = WRITE_DAC |
762 ACCESS_SYSTEM_SECURITY;
766 h = win32_open_existing_file(path, dwDesiredAccess);
767 if (h != INVALID_HANDLE_VALUE)
769 err = GetLastError();
770 if (err == ERROR_ACCESS_DENIED ||
771 err == ERROR_PRIVILEGE_NOT_HELD)
773 /* Don't increment partial_security_descriptors
774 * here or check WIMLIB_EXTRACT_FLAG_STRICT_ACLS
775 * here. It will be done later if needed; here
776 * we are just trying to get as many relevant
777 * access rights as possible. */
778 if (dwDesiredAccess & ACCESS_SYSTEM_SECURITY) {
779 dwDesiredAccess &= ~ACCESS_SYSTEM_SECURITY;
782 if (dwDesiredAccess & WRITE_DAC) {
783 dwDesiredAccess &= ~WRITE_DAC;
786 if (dwDesiredAccess & WRITE_OWNER) {
787 dwDesiredAccess &= ~WRITE_OWNER;
791 /* Other error, or couldn't open the file even with no
792 * access rights specified. Something else must be
794 set_errno_from_win32_error(err);
795 return WIMLIB_ERR_SET_SECURITY;
800 /* Try setting the security descriptor. */
804 err = do_win32_set_security_descriptor(h, path, info,
805 (PSECURITY_DESCRIPTOR)desc);
806 if (err == ERROR_SUCCESS) {
811 /* Failed to set the requested parts of the security descriptor.
812 * If the error was permissions-related, try to set fewer parts
813 * of the security descriptor, unless
814 * WIMLIB_EXTRACT_FLAG_STRICT_ACLS is enabled. */
815 if ((err == ERROR_PRIVILEGE_NOT_HELD ||
816 err == ERROR_ACCESS_DENIED) &&
817 !(ctx->extract_flags & WIMLIB_EXTRACT_FLAG_STRICT_ACLS))
819 if (info & SACL_SECURITY_INFORMATION) {
820 info &= ~SACL_SECURITY_INFORMATION;
821 ctx->partial_security_descriptors++;
824 if (info & DACL_SECURITY_INFORMATION) {
825 info &= ~DACL_SECURITY_INFORMATION;
828 if (info & OWNER_SECURITY_INFORMATION) {
829 info &= ~OWNER_SECURITY_INFORMATION;
832 /* Nothing left except GROUP, and if we removed it we
833 * wouldn't have anything at all. */
835 /* No part of the security descriptor could be set, or
836 * WIMLIB_EXTRACT_FLAG_STRICT_ACLS is enabled and the full
837 * security descriptor could not be set. */
838 if (!(info & SACL_SECURITY_INFORMATION))
839 ctx->partial_security_descriptors--;
840 set_errno_from_win32_error(err);
841 ret = WIMLIB_ERR_SET_SECURITY;
845 /* Close handle opened for NtSetSecurityObject(). */
847 if (func_NtSetSecurityObject)
854 win32_set_timestamps(const wchar_t *path, u64 creation_time,
855 u64 last_write_time, u64 last_access_time,
856 struct apply_ctx *ctx)
860 FILETIME creationTime = {.dwLowDateTime = creation_time & 0xffffffff,
861 .dwHighDateTime = creation_time >> 32};
862 FILETIME lastAccessTime = {.dwLowDateTime = last_access_time & 0xffffffff,
863 .dwHighDateTime = last_access_time >> 32};
864 FILETIME lastWriteTime = {.dwLowDateTime = last_write_time & 0xffffffff,
865 .dwHighDateTime = last_write_time >> 32};
867 h = win32_open_existing_file(path, FILE_WRITE_ATTRIBUTES);
868 if (h == INVALID_HANDLE_VALUE)
871 if (!SetFileTime(h, &creationTime, &lastAccessTime, &lastWriteTime))
872 goto error_close_handle;
880 err = GetLastError();
884 set_errno_from_GetLastError();
885 return WIMLIB_ERR_SET_TIMESTAMPS;
888 const struct apply_operations win32_apply_ops = {
891 .target_is_root = win32_path_is_root_of_drive,
892 .start_extract = win32_start_extract,
893 .finish_extract = win32_finish_extract,
894 .abort_extract = win32_finish_extract,
895 .create_file = win32_create_file,
896 .create_directory = win32_create_directory,
897 .create_hardlink = win32_create_hardlink,
898 .create_symlink = win32_create_symlink,
899 .extract_unnamed_stream = win32_extract_unnamed_stream,
900 .extract_named_stream = win32_extract_named_stream,
901 .extract_encrypted_stream = win32_extract_encrypted_stream,
902 .set_file_attributes = win32_set_file_attributes,
903 .set_reparse_data = win32_set_reparse_data,
904 .set_short_name = win32_set_short_name,
905 .set_security_descriptor = win32_set_security_descriptor,
906 .set_timestamps = win32_set_timestamps,
908 .path_prefix = L"\\\\?\\",
909 .path_prefix_nchars = 4,
910 .path_separator = L'\\',
913 .requires_realtarget_in_paths = 1,
914 .realpath_works_on_nonexisting_files = 1,
915 .root_directory_is_special = 1,
916 .requires_final_set_attributes_pass = 1,
917 .extract_encrypted_stream_creates_file = 1,
918 .requires_short_name_reordering = 1, /* TODO: check if this is really needed */
921 #endif /* __WIN32__ */