ReactOS 0.4.15-dev-8109-gd7be748
cmwraprs.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/config/cmwraprs.c
5 * PURPOSE: Configuration Manager - Wrappers for Hive Operations
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "ntoskrnl.h"
12#define NDEBUG
13#include "debug.h"
14
15/* FUNCTIONS *****************************************************************/
16
22{
25
26 /* Create the event */
28 NULL,
30 NULL,
31 NULL);
32 Status = ZwCreateEvent(EventHandle,
36 FALSE);
37 if (!NT_SUCCESS(Status)) return Status;
38
39 /* Get a pointer to the object itself */
42 NULL,
44 (PVOID*)Event,
45 NULL);
47
48 /* Return status */
49 return Status;
50}
51
55 IN BOOLEAN Paged,
56 IN ULONG Tag)
57{
59 Size,
60 Tag);
61}
62
63VOID
66 IN ULONG Quota)
67{
69}
70
73CmpFileRead(IN PHHIVE RegistryHive,
78{
79 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
80 HANDLE HiveHandle = CmHive->FileHandles[FileType];
81 LARGE_INTEGER _FileOffset;
84
85 /* Just return success if no file is associated with this hive */
86 if (HiveHandle == NULL)
87 return TRUE;
88
89 _FileOffset.QuadPart = *FileOffset;
90 Status = ZwReadFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
91 Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
92 /* We do synchronous I/O for simplicity - see CmpOpenHiveFiles. */
94 return NT_SUCCESS(Status) ? TRUE : FALSE;
95}
96
99CmpFileWrite(IN PHHIVE RegistryHive,
104{
105 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
106 HANDLE HiveHandle = CmHive->FileHandles[FileType];
107 LARGE_INTEGER _FileOffset;
110
111 /* Just return success if no file is associated with this hive */
112 if (HiveHandle == NULL)
113 return TRUE;
114
115 /* Don't do anything if we're not supposed to */
116 if (CmpNoWrite)
117 return TRUE;
118
119 _FileOffset.QuadPart = *FileOffset;
120 Status = ZwWriteFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
121 Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
122 /* We do synchronous I/O for simplicity - see CmpOpenHiveFiles.
123 * Windows optimizes here by starting an async write for each 64k chunk,
124 * then waiting for all writes to complete at once.
125 */
127 return NT_SUCCESS(Status) ? TRUE : FALSE;
128}
129
131NTAPI
133 _In_ PHHIVE RegistryHive,
136 _In_ ULONG OldFileSize)
137{
138 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
139 HANDLE HiveHandle = CmHive->FileHandles[FileType];
140 FILE_END_OF_FILE_INFORMATION EndOfFileInfo;
141 FILE_ALLOCATION_INFORMATION FileAllocationInfo;
143 BOOLEAN HardErrors;
145
146 /* Just return success if no file is associated with this hive */
147 if (HiveHandle == NULL)
148 {
149 DPRINT1("No hive handle associated with the given hive\n");
150 return TRUE;
151 }
152
153 /*
154 * Disable hard errors so that we don't deadlock
155 * when touching with the hive files.
156 */
157 HardErrors = IoSetThreadHardErrorMode(FALSE);
158
159 EndOfFileInfo.EndOfFile.QuadPart = FileSize;
160 Status = ZwSetInformationFile(HiveHandle,
162 &EndOfFileInfo,
165 if (!NT_SUCCESS(Status))
166 {
167 DPRINT1("ZwSetInformationFile failed to set new size of end of file (Status 0x%lx)\n", Status);
168 IoSetThreadHardErrorMode(HardErrors);
169 return FALSE;
170 }
171
172 FileAllocationInfo.AllocationSize.QuadPart = FileSize;
173 Status = ZwSetInformationFile(HiveHandle,
175 &FileAllocationInfo,
178 if (!NT_SUCCESS(Status))
179 {
180 DPRINT1("ZwSetInformationFile failed to set new of allocation file (Status 0x%lx)\n", Status);
181 IoSetThreadHardErrorMode(HardErrors);
182 return FALSE;
183 }
184
185 /* Reset the hard errors back */
186 IoSetThreadHardErrorMode(HardErrors);
187 return TRUE;
188}
189
191NTAPI
192CmpFileFlush(IN PHHIVE RegistryHive,
196{
197 PCMHIVE CmHive = (PCMHIVE)RegistryHive;
198 HANDLE HiveHandle = CmHive->FileHandles[FileType];
201
202 /* Just return success if no file is associated with this hive */
203 if (HiveHandle == NULL)
204 return TRUE;
205
206 /* Don't do anything if we're not supposed to */
207 if (CmpNoWrite)
208 return TRUE;
209
211
212 /* This operation is always synchronous */
215
216 return NT_SUCCESS(Status) ? TRUE : FALSE;
217}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
Definition: bufpool.h:45
struct _CMHIVE * PCMHIVE
BOOLEAN CmpNoWrite
Definition: cmsysini.c:30
BOOLEAN NTAPI CmpFileWrite(IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, IN PVOID Buffer, IN SIZE_T BufferLength)
Definition: cmwraprs.c:99
VOID NTAPI CmpFree(IN PVOID Ptr, IN ULONG Quota)
Definition: cmwraprs.c:65
BOOLEAN NTAPI CmpFileSetSize(_In_ PHHIVE RegistryHive, _In_ ULONG FileType, _In_ ULONG FileSize, _In_ ULONG OldFileSize)
Definition: cmwraprs.c:132
BOOLEAN NTAPI CmpFileFlush(IN PHHIVE RegistryHive, IN ULONG FileType, IN OUT PLARGE_INTEGER FileOffset, IN ULONG Length)
Definition: cmwraprs.c:192
NTSTATUS NTAPI CmpCreateEvent(IN EVENT_TYPE EventType, OUT PHANDLE EventHandle, OUT PKEVENT *Event)
Definition: cmwraprs.c:19
PVOID NTAPI CmpAllocate(IN SIZE_T Size, IN BOOLEAN Paged, IN ULONG Tag)
Definition: cmwraprs.c:54
BOOLEAN NTAPI CmpFileRead(IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, OUT PVOID Buffer, IN SIZE_T BufferLength)
Definition: cmwraprs.c:73
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
@ FileEndOfFileInformation
Definition: from_kernel.h:81
@ FileAllocationInformation
Definition: from_kernel.h:80
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define ASSERT(a)
Definition: mode.c:44
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _In_
Definition: ms_sal.h:308
#define KernelMode
Definition: asm.h:34
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE EventType
Definition: exfuncs.h:167
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
enum _EVENT_TYPE EVENT_TYPE
BOOLEAN NTAPI IoSetThreadHardErrorMode(IN BOOLEAN HardErrorEnabled)
Definition: error.c:726
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_PENDING
Definition: ntstatus.h:82
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
Definition: cmlib.h:316
HANDLE FileHandles[HFILE_TYPE_MAX]
Definition: cmlib.h:318
LARGE_INTEGER AllocationSize
Definition: winternl.h:688
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065
_In_ WDFDEVICE _In_ WDF_SPECIAL_FILE_TYPE FileType
Definition: wdfdevice.h:2741
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:857
NTSYSAPI NTSTATUS NTAPI ZwFlushBuffersFile(_In_ HANDLE FileHandle, _Out_ PIO_STATUS_BLOCK IoStatusBlock)