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)
9 /* INCLUDES ******************************************************************/
15 /* FUNCTIONS *****************************************************************/
19 CmpCreateEvent(IN EVENT_TYPE EventType
,
20 OUT PHANDLE EventHandle
,
24 OBJECT_ATTRIBUTES ObjectAttributes
;
26 /* Create the event */
27 InitializeObjectAttributes(&ObjectAttributes
,
29 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
32 Status
= ZwCreateEvent(EventHandle
,
37 if (!NT_SUCCESS(Status
)) return Status
;
39 /* Get a pointer to the object itself */
40 Status
= ObReferenceObjectByHandle(*EventHandle
,
46 if (!NT_SUCCESS(Status
)) ZwClose(*EventHandle
);
54 CmpAllocate(IN SIZE_T Size
,
58 return ExAllocatePoolWithTag(Paged
? PagedPool
: NonPagedPool
,
73 CmpFileRead(IN PHHIVE RegistryHive
,
77 IN SIZE_T BufferLength
)
79 PCMHIVE CmHive
= (PCMHIVE
)RegistryHive
;
80 HANDLE HiveHandle
= CmHive
->FileHandles
[FileType
];
81 LARGE_INTEGER _FileOffset
;
82 IO_STATUS_BLOCK IoStatusBlock
;
85 /* Just return success if no file is associated with this hive */
86 if (HiveHandle
== NULL
)
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
;
97 CmpFileWrite(IN PHHIVE RegistryHive
,
101 IN SIZE_T BufferLength
)
103 PCMHIVE CmHive
= (PCMHIVE
)RegistryHive
;
104 HANDLE HiveHandle
= CmHive
->FileHandles
[FileType
];
105 LARGE_INTEGER _FileOffset
;
106 IO_STATUS_BLOCK IoStatusBlock
;
109 /* Just return success if no file is associated with this hive */
110 if (HiveHandle
== NULL
)
113 /* Don't do anything if we're not supposed to */
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
;
125 CmpFileSetSize(IN PHHIVE RegistryHive
,
128 IN ULONG OldFileSize
)
130 PCMHIVE CmHive
= (PCMHIVE
)RegistryHive
;
131 HANDLE HiveHandle
= CmHive
->FileHandles
[FileType
];
132 FILE_END_OF_FILE_INFORMATION EndOfFileInfo
;
133 FILE_ALLOCATION_INFORMATION FileAllocationInfo
;
134 IO_STATUS_BLOCK IoStatusBlock
;
137 /* Just return success if no file is associated with this hive */
138 if (HiveHandle
== NULL
)
141 EndOfFileInfo
.EndOfFile
.QuadPart
= FileSize
;
142 Status
= ZwSetInformationFile(HiveHandle
,
145 sizeof(FILE_END_OF_FILE_INFORMATION
),
146 FileEndOfFileInformation
);
147 if (!NT_SUCCESS(Status
)) return FALSE
;
149 FileAllocationInfo
.AllocationSize
.QuadPart
= FileSize
;
150 Status
= ZwSetInformationFile(HiveHandle
,
153 sizeof(FILE_ALLOCATION_INFORMATION
),
154 FileAllocationInformation
);
155 if (!NT_SUCCESS(Status
)) return FALSE
;
162 CmpFileFlush(IN PHHIVE RegistryHive
,
164 IN OUT PLARGE_INTEGER FileOffset
,
167 PCMHIVE CmHive
= (PCMHIVE
)RegistryHive
;
168 HANDLE HiveHandle
= CmHive
->FileHandles
[FileType
];
169 IO_STATUS_BLOCK IoStatusBlock
;
172 /* Just return success if no file is associated with this hive */
173 if (HiveHandle
== NULL
)
176 /* Don't do anything if we're not supposed to */
180 Status
= ZwFlushBuffersFile(HiveHandle
, &IoStatusBlock
);
181 return NT_SUCCESS(Status
) ? TRUE
: FALSE
;