]> wimlib.net Git - wimlib/commitdiff
wimboot_set_pointer(): No unnecessary file open
authorEric Biggers <ebiggers3@gmail.com>
Wed, 27 Aug 2014 04:09:18 +0000 (23:09 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 27 Aug 2014 04:09:18 +0000 (23:09 -0500)
include/wimlib/wimboot.h
src/wimboot.c
src/win32_apply.c

index 6be4fae204d6c294b8a9a435abe3bec19e023dde..a1039017d942e777be54a395b4a9377ce494b230 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _WIMBOOT_H_
 #define _WIMBOOT_H_
 
 #ifndef _WIMBOOT_H_
 #define _WIMBOOT_H_
 
+#include "wimlib/win32_common.h"
 #include "wimlib/sha1.h"
 #include "wimlib/types.h"
 #include "wimlib/header.h"
 #include "wimlib/sha1.h"
 #include "wimlib/types.h"
 #include "wimlib/header.h"
@@ -14,7 +15,7 @@ wimboot_alloc_data_source_id(const wchar_t *wim_path,
                             bool *wof_running_ret);
 
 extern int
                             bool *wof_running_ret);
 
 extern int
-wimboot_set_pointer(OBJECT_ATTRIBUTES *attr,
+wimboot_set_pointer(HANDLE h,
                    const wchar_t *printable_path,
                    const struct wim_lookup_table_entry *lte,
                    u64 data_source_id,
                    const wchar_t *printable_path,
                    const struct wim_lookup_table_entry *lte,
                    u64 data_source_id,
index 514ff8c5b53c1122fbe70f48f80b90c04ad3abd9..cdd74d9468f267dece137673db408ec30a838068 100644 (file)
@@ -1024,10 +1024,10 @@ out:
  * This turns it into a reparse point that redirects accesses to it, to the
  * corresponding resource in the WIM archive.
  *
  * This turns it into a reparse point that redirects accesses to it, to the
  * corresponding resource in the WIM archive.
  *
- * @attr
- *     Object attributes that specify the path to the file.
+ * @h
+ *     Open handle to the file, with GENERIC_WRITE access.
  * @printable_name
  * @printable_name
- *     Printable representation of the path encoded in @attr.
+ *     Printable representation of the path to the file.
  * @lte
  *     Unnamed data stream of the file.
  * @data_source_id
  * @lte
  *     Unnamed data stream of the file.
  * @data_source_id
@@ -1041,30 +1041,16 @@ out:
  * Returns 0 on success, or a positive error code on failure.
  */
 int
  * Returns 0 on success, or a positive error code on failure.
  */
 int
-wimboot_set_pointer(OBJECT_ATTRIBUTES *attr,
+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)
 {
                    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)
 {
-       int ret;
-       HANDLE h = NULL;
-       NTSTATUS status;
-       IO_STATUS_BLOCK iosb;
        DWORD bytes_returned;
        DWORD err;
 
        DWORD bytes_returned;
        DWORD err;
 
-       status = (*func_NtOpenFile)(&h, GENERIC_WRITE | SYNCHRONIZE, attr,
-                                   &iosb, FILE_SHARE_VALID_FLAGS,
-                                   FILE_OPEN_FOR_BACKUP_INTENT |
-                                       FILE_OPEN_REPARSE_POINT |
-                                       FILE_SYNCHRONOUS_IO_NONALERT);
-       if (!NT_SUCCESS(status)) {
-               SetLastError((*func_RtlNtStatusToDosError)(status));
-               goto fail;
-       }
-
        if (wof_running) {
                /* The WOF driver is running.  We can create the reparse point
                 * using FSCTL_SET_EXTERNAL_BACKING.  */
        if (wof_running) {
                /* The WOF driver is running.  We can create the reparse point
                 * using FSCTL_SET_EXTERNAL_BACKING.  */
@@ -1144,20 +1130,14 @@ wimboot_set_pointer(OBJECT_ATTRIBUTES *attr,
                        goto fail;
        }
 
                        goto fail;
        }
 
-       ret = 0;
-       goto out;
+       return 0;
 
 fail:
        err = GetLastError();
        set_errno_from_win32_error(err);
        ERROR_WITH_ERRNO("\"%ls\": Couldn't set WIMBoot pointer data "
                         "(err=%"PRIu32")", printable_name, (u32)err);
 
 fail:
        err = GetLastError();
        set_errno_from_win32_error(err);
        ERROR_WITH_ERRNO("\"%ls\": Couldn't set WIMBoot pointer data "
                         "(err=%"PRIu32")", printable_name, (u32)err);
-       ret = WIMLIB_ERR_WIMBOOT;
-out:
-       if (h)
-               (*func_NtClose)(h);
-       return ret;
-
+       return WIMLIB_ERR_WIMBOOT;
 }
 
 #endif /* __WIN32__ */
 }
 
 #endif /* __WIN32__ */
index 03f2449b72ad83fd202e576a710d62244b562f3c..eb80f27cecdfc645ae92c6ac7b92bc2e2fa41592 100644 (file)
@@ -361,7 +361,7 @@ win32_will_externally_back(struct wim_dentry *dentry, struct apply_ctx *_ctx)
 }
 
 static int
 }
 
 static int
-set_external_backing(struct wim_dentry *dentry, struct win32_apply_ctx *ctx)
+set_external_backing(HANDLE h, struct wim_dentry *dentry, struct win32_apply_ctx *ctx)
 {
        int ret;
 
 {
        int ret;
 
@@ -386,7 +386,7 @@ set_external_backing(struct wim_dentry *dentry, struct win32_apply_ctx *ctx)
                                     &info, ctx->common.progctx);
        } else {
                /* Externally backing.  */
                                     &info, ctx->common.progctx);
        } else {
                /* Externally backing.  */
-               return wimboot_set_pointer(&ctx->attr,
+               return wimboot_set_pointer(h,
                                           current_path(ctx),
                                           inode_unnamed_lte_resolved(dentry->d_inode),
                                           ctx->wimboot.data_source_id,
                                           current_path(ctx),
                                           inode_unnamed_lte_resolved(dentry->d_inode),
                                           ctx->wimboot.data_source_id,
@@ -1427,7 +1427,7 @@ create_nondirectory(const struct wim_inode *inode, struct win32_apply_ctx *ctx)
 
        /* "WIMBoot" extraction: set external backing by the WIM file if needed.  */
        if (!ret && unlikely(ctx->common.extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT))
 
        /* "WIMBoot" extraction: set external backing by the WIM file if needed.  */
        if (!ret && unlikely(ctx->common.extract_flags & WIMLIB_EXTRACT_FLAG_WIMBOOT))
-               ret = set_external_backing(first_dentry, ctx);
+               ret = set_external_backing(h, first_dentry, ctx);
 
        (*func_NtClose)(h);
        return ret;
 
        (*func_NtClose)(h);
        return ret;