mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:23:05 +00:00
[SETUPLIB] Additions for filesup.c and inicache.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). svn path=/branches/setup_improvements/; revision=74710 - Split IniCacheLoad() and IniCacheSave() into: themselves & IniCacheLoadByHandle() and IniCacheSaveByHandle(), respectively, so that we can load & save INI files if we already have an opened handle to them. svn path=/branches/setup_improvements/; revision=74711
This commit is contained in:
parent
6b6163a5d9
commit
7f5428633b
4 changed files with 131 additions and 87 deletions
|
@ -179,7 +179,7 @@ DoesFileExist(
|
|||
NULL);
|
||||
|
||||
Status = NtOpenFile(&FileHandle,
|
||||
GENERIC_READ | SYNCHRONIZE,
|
||||
FILE_GENERIC_READ, // Contains SYNCHRONIZE
|
||||
&ObjectAttributes,
|
||||
&IoStatusBlock,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
|
@ -305,20 +305,24 @@ Quit:
|
|||
|
||||
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);
|
||||
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
|
@ -331,7 +335,8 @@ OpenAndMapFile(
|
|||
*SectionHandle = NULL;
|
||||
|
||||
Status = NtOpenFile(FileHandle,
|
||||
GENERIC_READ | SYNCHRONIZE,
|
||||
FILE_GENERIC_READ | // Contains SYNCHRONIZE
|
||||
(ReadWriteAccess ? FILE_GENERIC_WRITE : 0),
|
||||
&ObjectAttributes,
|
||||
&IoStatusBlock,
|
||||
FILE_SHARE_READ,
|
||||
|
@ -369,12 +374,16 @@ OpenAndMapFile(
|
|||
|
||||
/* 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))
|
||||
|
@ -396,7 +405,7 @@ OpenAndMapFile(
|
|||
&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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue