]> wimlib.net Git - wimlib/commitdiff
Win32 capture/apply: Simplify opening existing files
authorEric Biggers <ebiggers3@gmail.com>
Sun, 18 Aug 2013 16:45:20 +0000 (11:45 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sun, 18 Aug 2013 16:45:58 +0000 (11:45 -0500)
include/wimlib/win32_common.h
src/win32_apply.c
src/win32_capture.c
src/win32_common.c

index 0d594f6a831ddf6bad4e20723579522949e77718..499dad4faae0062543b5a3fa2614b770ec9b853f 100644 (file)
@@ -30,9 +30,6 @@ win32_get_vol_flags(const wchar_t *path, unsigned *vol_flags_ret,
 extern HANDLE
 win32_open_existing_file(const wchar_t *path, DWORD dwDesiredAccess);
 
-extern HANDLE
-win32_open_file_data_only(const wchar_t *path);
-
 /* Vista and later */
 extern HANDLE (WINAPI *win32func_FindFirstStreamW)(LPCWSTR lpFileName,
                                                   STREAM_INFO_LEVELS InfoLevel,
index adf605b961bfd8e54f1bed59b30a0b40212e9176..4a0a8a46d77ad22b41edf0354127ffb5ed61f520 100644 (file)
@@ -301,10 +301,7 @@ win32_set_special_file_attributes(const wchar_t *path, u32 attributes)
        USHORT compression_format = COMPRESSION_FORMAT_DEFAULT;
        DWORD bytes_returned;
 
-       h = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
@@ -388,10 +385,7 @@ win32_set_file_attributes(const wchar_t *path, u32 attributes,
                DWORD bytes_returned;
                USHORT compression_format = COMPRESSION_FORMAT_NONE;
 
-               h = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
-                              OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                             FILE_FLAG_OPEN_REPARSE_POINT,
-                              NULL);
+               h = win32_open_existing_file(path, GENERIC_READ | GENERIC_WRITE);
                if (h == INVALID_HANDLE_VALUE)
                        goto error;
 
@@ -425,10 +419,7 @@ win32_set_reparse_data(const wchar_t *path, const u8 *rpbuf, u16 rpbuflen,
        DWORD err;
        DWORD bytes_returned;
 
-       h = CreateFile(path, GENERIC_WRITE, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, GENERIC_WRITE);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
@@ -458,10 +449,7 @@ win32_set_short_name(const wchar_t *path, const wchar_t *short_name,
        HANDLE h;
        DWORD err;
 
-       h = CreateFile(path, GENERIC_WRITE | DELETE, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, GENERIC_WRITE | DELETE);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
@@ -516,10 +504,7 @@ win32_set_security_descriptor(const wchar_t *path, const u8 *desc,
        h = INVALID_HANDLE_VALUE;
 
 #ifdef WITH_NTDLL
-       h = CreateFile(path, MAXIMUM_ALLOWED, 0, NULL, OPEN_EXISTING,
-                      FILE_FLAG_BACKUP_SEMANTICS |
-                              FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, MAXIMUM_ALLOWED);
        if (h == INVALID_HANDLE_VALUE) {
                ERROR_WITH_ERRNO("Can't open %ls (%u)", path, GetLastError());
                goto error;
@@ -581,10 +566,7 @@ win32_set_timestamps(const wchar_t *path, u64 creation_time,
        FILETIME lastWriteTime = {.dwLowDateTime = last_write_time & 0xffffffff,
                                  .dwHighDateTime = last_write_time >> 32};
 
-       h = CreateFile(path, FILE_WRITE_ATTRIBUTES, 0, NULL,
-                      OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
-                                     FILE_FLAG_OPEN_REPARSE_POINT,
-                      NULL);
+       h = win32_open_existing_file(path, FILE_WRITE_ATTRIBUTES);
        if (h == INVALID_HANDLE_VALUE)
                goto error;
 
index 2489d9bdea0b03625406a00abd2d35b3c93aae00..986a4d1b7593da2492294ce5168cb6dcedf6e708 100644 (file)
@@ -90,7 +90,8 @@ read_win32_file_prefix(const struct wim_lookup_table_entry *lte,
        DWORD err;
        u64 bytes_remaining;
 
-       HANDLE hFile = win32_open_file_data_only(lte->file_on_disk);
+       HANDLE hFile = win32_open_existing_file(lte->file_on_disk,
+                                               FILE_READ_DATA);
        if (hFile == INVALID_HANDLE_VALUE) {
                set_errno_from_GetLastError();
                ERROR_WITH_ERRNO("Failed to open \"%ls\"", lte->file_on_disk);
index d59796b9d4494a662eb8497d7624e2a0c611c1f1..051720a255ef9d15f3ebda96a050c25aa39f961c 100644 (file)
@@ -512,12 +512,6 @@ win32_open_existing_file(const wchar_t *path, DWORD dwDesiredAccess)
                           NULL /* hTemplateFile */);
 }
 
-HANDLE
-win32_open_file_data_only(const wchar_t *path)
-{
-       return win32_open_existing_file(path, FILE_READ_DATA);
-}
-
 #ifndef WITH_NTDLL
 /* Pointers to functions that are not available on all targetted versions of
  * Windows (XP and later).  NOTE: The WINAPI annotations seem to be important; I