ReactOS  0.4.14-dev-77-gd9e7c48
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 
18 NTAPI
21  OUT PKEVENT *Event)
22 {
25 
26  /* Create the event */
28  NULL,
30  NULL,
31  NULL);
32  Status = ZwCreateEvent(EventHandle,
35  EventType,
36  FALSE);
37  if (!NT_SUCCESS(Status)) return Status;
38 
39  /* Get a pointer to the object itself */
42  NULL,
43  KernelMode,
44  (PVOID*)Event,
45  NULL);
47 
48  /* Return status */
49  return Status;
50 }
51 
52 PVOID
53 NTAPI
55  IN BOOLEAN Paged,
56  IN ULONG Tag)
57 {
59  Size,
60  Tag);
61 }
62 
63 VOID
64 NTAPI
66  IN ULONG Quota)
67 {
68  ExFreePool(Ptr);
69 }
70 
71 BOOLEAN
72 NTAPI
73 CmpFileRead(IN PHHIVE RegistryHive,
74  IN ULONG FileType,
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  return NT_SUCCESS(Status) ? TRUE : FALSE;
93 }
94 
95 BOOLEAN
96 NTAPI
97 CmpFileWrite(IN PHHIVE RegistryHive,
98  IN ULONG FileType,
100  IN PVOID Buffer,
102 {
103  PCMHIVE CmHive = (PCMHIVE)RegistryHive;
104  HANDLE HiveHandle = CmHive->FileHandles[FileType];
105  LARGE_INTEGER _FileOffset;
108 
109  /* Just return success if no file is associated with this hive */
110  if (HiveHandle == NULL)
111  return TRUE;
112 
113  /* Don't do anything if we're not supposed to */
114  if (CmpNoWrite)
115  return TRUE;
116 
117  _FileOffset.QuadPart = *FileOffset;
118  Status = ZwWriteFile(HiveHandle, NULL, NULL, NULL, &IoStatusBlock,
119  Buffer, (ULONG)BufferLength, &_FileOffset, NULL);
120  return NT_SUCCESS(Status) ? TRUE : FALSE;
121 }
122 
123 BOOLEAN
124 NTAPI
125 CmpFileSetSize(IN PHHIVE RegistryHive,
126  IN ULONG FileType,
127  IN ULONG FileSize,
128  IN ULONG OldFileSize)
129 {
130  PCMHIVE CmHive = (PCMHIVE)RegistryHive;
131  HANDLE HiveHandle = CmHive->FileHandles[FileType];
132  FILE_END_OF_FILE_INFORMATION EndOfFileInfo;
133  FILE_ALLOCATION_INFORMATION FileAllocationInfo;
136 
137  /* Just return success if no file is associated with this hive */
138  if (HiveHandle == NULL)
139  return TRUE;
140 
141  EndOfFileInfo.EndOfFile.QuadPart = FileSize;
142  Status = ZwSetInformationFile(HiveHandle,
143  &IoStatusBlock,
144  &EndOfFileInfo,
147  if (!NT_SUCCESS(Status)) return FALSE;
148 
149  FileAllocationInfo.AllocationSize.QuadPart = FileSize;
150  Status = ZwSetInformationFile(HiveHandle,
151  &IoStatusBlock,
152  &FileAllocationInfo,
155  if (!NT_SUCCESS(Status)) return FALSE;
156 
157  return TRUE;
158 }
159 
160 BOOLEAN
161 NTAPI
162 CmpFileFlush(IN PHHIVE RegistryHive,
163  IN ULONG FileType,
165  IN ULONG Length)
166 {
167  PCMHIVE CmHive = (PCMHIVE)RegistryHive;
168  HANDLE HiveHandle = CmHive->FileHandles[FileType];
171 
172  /* Just return success if no file is associated with this hive */
173  if (HiveHandle == NULL)
174  return TRUE;
175 
176  /* Don't do anything if we're not supposed to */
177  if (CmpNoWrite)
178  return TRUE;
179 
180  Status = ZwFlushBuffersFile(HiveHandle, &IoStatusBlock);
181  return NT_SUCCESS(Status) ? TRUE : FALSE;
182 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
struct _CMHIVE * PCMHIVE
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwFlushBuffersFile(_In_ HANDLE FileHandle, _Out_ PIO_STATUS_BLOCK IoStatusBlock)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LONG NTSTATUS
Definition: precomp.h:26
LARGE_INTEGER AllocationSize
Definition: winternl.h:688
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:496
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
HANDLE FileHandles[HFILE_TYPE_MAX]
Definition: cm.h:394
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
PVOID NTAPI CmpAllocate(IN SIZE_T Size, IN BOOLEAN Paged, IN ULONG Tag)
Definition: cmwraprs.c:54
enum _EVENT_TYPE EVENT_TYPE
BOOLEAN NTAPI CmpFileFlush(IN PHHIVE RegistryHive, IN ULONG FileType, IN OUT PLARGE_INTEGER FileOffset, IN ULONG Length)
Definition: cmwraprs.c:162
BOOLEAN CmpNoWrite
Definition: cmsysini.c:29
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI CmpFree(IN PVOID Ptr, IN ULONG Quota)
Definition: cmwraprs.c:65
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI CmpFileRead(IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, OUT PVOID Buffer, IN SIZE_T BufferLength)
Definition: cmwraprs.c:73
ULONG_PTR SIZE_T
Definition: typedefs.h:78
NTSTATUS NTAPI CmpCreateEvent(IN EVENT_TYPE EventType, OUT PHANDLE EventHandle, OUT PKEVENT *Event)
Definition: cmwraprs.c:19
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
static PCMHIVE CmHive
Definition: registry.c:28
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
BOOLEAN NTAPI CmpFileWrite(IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, IN PVOID Buffer, IN SIZE_T BufferLength)
Definition: cmwraprs.c:97
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_ EVENT_TYPE EventType
Definition: exfuncs.h:165
BOOLEAN NTAPI CmpFileSetSize(IN PHHIVE RegistryHive, IN ULONG FileType, IN ULONG FileSize, IN ULONG OldFileSize)
Definition: cmwraprs.c:125
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
Definition: cm.h:391
LONGLONG QuadPart
Definition: typedefs.h:112
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855