Author: hbelusca
Date: Wed May 31 00:18:13 2017
New Revision: 74710
URL:
http://svn.reactos.org/svn/reactos?rev=74710&view=rev
Log:
[SETUPLIB]: Additions for filesup.c:
- In DoesFileExist(): Call NtOpenFile with FILE_GENERIC_READ instead of the more generic
GENERIC_READ access right.
- OpenAndMapFile(): Add support for opening & mapping files with write access (to be
used latter).
Modified:
branches/setup_improvements/base/setup/lib/filesup.c
branches/setup_improvements/base/setup/lib/filesup.h
Modified: branches/setup_improvements/base/setup/lib/filesup.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/filesup.c [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/filesup.c [iso-8859-1] Wed May 31 00:18:13
2017
@@ -200,7 +200,7 @@
NULL);
Status = NtOpenFile(&FileHandle,
- GENERIC_READ | SYNCHRONIZE,
+ FILE_GENERIC_READ, // Contains SYNCHRONIZE
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_READ | FILE_SHARE_WRITE,
@@ -326,19 +326,23 @@
NTSTATUS
OpenAndMapFile(
- IN HANDLE RootDirectory OPTIONAL,
- IN PCWSTR PathNameToFile,
+ IN HANDLE RootDirectory OPTIONAL,
+ IN PCWSTR PathNameToFile,
OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL
OUT PHANDLE SectionHandle,
OUT PVOID* BaseAddress,
- OUT PULONG FileSize OPTIONAL)
+ OUT PULONG FileSize OPTIONAL,
+ IN BOOLEAN ReadWriteAccess)
{
NTSTATUS Status;
UNICODE_STRING FileName;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
+ ULONG SectionPageProtection;
SIZE_T ViewSize;
PVOID ViewBase;
+
+ /* Open the file */
RtlInitUnicodeString(&FileName, PathNameToFile);
@@ -352,7 +356,8 @@
*SectionHandle = NULL;
Status = NtOpenFile(FileHandle,
- GENERIC_READ | SYNCHRONIZE,
+ FILE_GENERIC_READ | // Contains SYNCHRONIZE
+ (ReadWriteAccess ? FILE_GENERIC_WRITE : 0),
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_READ,
@@ -390,12 +395,16 @@
/* Map the file in memory */
+ SectionPageProtection = (ReadWriteAccess ? PAGE_READWRITE : PAGE_READONLY);
+
/* Create the section */
Status = NtCreateSection(SectionHandle,
- SECTION_MAP_READ,
+ STANDARD_RIGHTS_REQUIRED | SECTION_QUERY |
+ SECTION_MAP_READ |
+ (ReadWriteAccess ? SECTION_MAP_WRITE : 0),
NULL,
NULL,
- PAGE_READONLY,
+ SectionPageProtection,
SEC_COMMIT /* | SEC_IMAGE (_NO_EXECUTE) */,
*FileHandle);
if (!NT_SUCCESS(Status))
@@ -417,7 +426,7 @@
&ViewSize,
ViewShare,
0,
- PAGE_READONLY);
+ SectionPageProtection);
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to map a view for file '%wZ', Status
0x%08lx\n", &FileName, Status);
Modified: branches/setup_improvements/base/setup/lib/filesup.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/filesup.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/filesup.h [iso-8859-1] Wed May 31 00:18:13
2017
@@ -69,12 +69,13 @@
NTSTATUS
OpenAndMapFile(
- IN HANDLE RootDirectory OPTIONAL,
- IN PCWSTR PathNameToFile,
+ IN HANDLE RootDirectory OPTIONAL,
+ IN PCWSTR PathNameToFile,
OUT PHANDLE FileHandle, // IN OUT PHANDLE OPTIONAL
OUT PHANDLE SectionHandle,
OUT PVOID* BaseAddress,
- OUT PULONG FileSize OPTIONAL);
+ OUT PULONG FileSize OPTIONAL,
+ IN BOOLEAN ReadWriteAccess);
BOOLEAN
UnMapFile(