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 _FileOffset
.QuadPart
= *FileOffset
;
86 Status
= ZwReadFile(HiveHandle
, 0, 0, 0, &IoStatusBlock
,
87 Buffer
, (ULONG
)BufferLength
, &_FileOffset
, 0);
88 return NT_SUCCESS(Status
) ? TRUE
: FALSE
;
93 CmpFileWrite(IN PHHIVE RegistryHive
,
97 IN SIZE_T BufferLength
)
99 PCMHIVE CmHive
= (PCMHIVE
)RegistryHive
;
100 HANDLE HiveHandle
= CmHive
->FileHandles
[FileType
];
101 LARGE_INTEGER _FileOffset
;
102 IO_STATUS_BLOCK IoStatusBlock
;
105 _FileOffset
.QuadPart
= *FileOffset
;
106 Status
= ZwWriteFile(HiveHandle
, 0, 0, 0, &IoStatusBlock
,
107 Buffer
, (ULONG
)BufferLength
, &_FileOffset
, 0);
108 return NT_SUCCESS(Status
) ? TRUE
: FALSE
;
113 CmpFileSetSize(IN PHHIVE RegistryHive
,
116 IN ULONG OldFileSize
)
118 PCMHIVE CmHive
= (PCMHIVE
)RegistryHive
;
119 HANDLE HiveHandle
= CmHive
->FileHandles
[FileType
];
120 FILE_END_OF_FILE_INFORMATION EndOfFileInfo
;
121 FILE_ALLOCATION_INFORMATION FileAllocationInfo
;
122 IO_STATUS_BLOCK IoStatusBlock
;
125 EndOfFileInfo
.EndOfFile
.QuadPart
= FileSize
;
126 Status
= ZwSetInformationFile(HiveHandle
,
129 sizeof(FILE_END_OF_FILE_INFORMATION
),
130 FileEndOfFileInformation
);
131 if (!NT_SUCCESS(Status
)) return FALSE
;
133 FileAllocationInfo
.AllocationSize
.QuadPart
= FileSize
;
134 Status
= ZwSetInformationFile(HiveHandle
,
137 sizeof(FILE_ALLOCATION_INFORMATION
),
138 FileAllocationInformation
);
139 if (!NT_SUCCESS(Status
)) return FALSE
;
146 CmpFileFlush(IN PHHIVE RegistryHive
,
148 IN OUT PLARGE_INTEGER FileOffset
,
151 PCMHIVE CmHive
= (PCMHIVE
)RegistryHive
;
152 HANDLE HiveHandle
= CmHive
->FileHandles
[FileType
];
153 IO_STATUS_BLOCK IoStatusBlock
;
156 Status
= ZwFlushBuffersFile(HiveHandle
, &IoStatusBlock
);
157 return NT_SUCCESS(Status
) ? TRUE
: FALSE
;