ReactOS  0.4.12-dev-934-g9a4676f
cminit.c File Reference
#include "ntoskrnl.h"
#include "debug.h"
Include dependency graph for cminit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI CmpInitializeHive (OUT PCMHIVE *CmHive, IN ULONG OperationType, IN ULONG HiveFlags, IN ULONG FileType, IN PVOID HiveData OPTIONAL, IN HANDLE Primary, IN HANDLE Log, IN HANDLE External, IN PCUNICODE_STRING FileName OPTIONAL, IN ULONG CheckFlags)
 
NTSTATUS NTAPI CmpDestroyHive (IN PCMHIVE CmHive)
 
NTSTATUS NTAPI CmpOpenHiveFiles (IN PCUNICODE_STRING BaseName, IN PCWSTR Extension OPTIONAL, OUT PHANDLE Primary, OUT PHANDLE Log, OUT PULONG PrimaryDisposition, OUT PULONG LogDisposition, IN BOOLEAN CreateAllowed, IN BOOLEAN MarkAsSystemHive, IN BOOLEAN NoBuffering, OUT PULONG ClusterSize OPTIONAL)
 
VOID NTAPI CmpCloseHiveFiles (IN PCMHIVE Hive)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cminit.c.

Function Documentation

◆ CmpCloseHiveFiles()

VOID NTAPI CmpCloseHiveFiles ( IN PCMHIVE  Hive)

Definition at line 631 of file cminit.c.

632 {
633  ULONG i;
634 
635  for (i = 0; i < HFILE_TYPE_MAX; i++)
636  {
637  if (Hive->FileHandles[i] != NULL)
638  {
639  ZwClose(Hive->FileHandles[i]);
640  Hive->FileHandles[i] = NULL;
641  }
642  }
643 }
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
#define HFILE_TYPE_MAX
Definition: hivedata.h:36
unsigned int ULONG
Definition: retypes.h:1

Referenced by CmShutdownSystem(), and CmUnloadKey().

◆ CmpDestroyHive()

NTSTATUS NTAPI CmpDestroyHive ( IN PCMHIVE  CmHive)

Definition at line 235 of file cminit.c.

236 {
237  /* Remove the hive from the list */
241 
242  /* Destroy the security descriptor cache */
244 
245  /* Destroy the view list */
247 
248  /* Delete the flusher lock */
251 
252  /* Delete the view lock */
254 
255  /* Free the hive storage */
256  HvFree(&CmHive->Hive);
257 
258  /* Free the hive */
260 
261  return STATUS_SUCCESS;
262 }
PKGUARDED_MUTEX ViewLock
Definition: cm.h:399
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
HHIVE Hive
Definition: cm.h:393
VOID CMAPI HvFree(PHHIVE RegistryHive)
Definition: hiveinit.c:623
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
PERESOURCE FlusherLock
Definition: cm.h:403
LIST_ENTRY HiveList
Definition: cm.h:396
#define TAG_CM
Definition: cmlib.h:203
FORCEINLINE VOID ExReleasePushLock(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1282
EX_PUSH_LOCK CmpHiveListHeadLock
Definition: cmdata.c:39
static PCMHIVE CmHive
Definition: registry.c:28
#define TAG_CMHIVE
Definition: cmlib.h:205
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2725
VOID NTAPI CmpDestroySecurityCache(IN PCMHIVE Hive)
Definition: cmsecach.c:41
VOID NTAPI CmpDestroyHiveViewList(IN PCMHIVE Hive)
Definition: cmmapvw.c:35

Referenced by CmSaveKey(), and CmSaveMergedKeys().

◆ CmpInitializeHive()

NTSTATUS NTAPI CmpInitializeHive ( OUT PCMHIVE CmHive,
IN ULONG  OperationType,
IN ULONG  HiveFlags,
IN ULONG  FileType,
IN PVOID HiveData  OPTIONAL,
IN HANDLE  Primary,
IN HANDLE  Log,
IN HANDLE  External,
IN PCUNICODE_STRING FileName  OPTIONAL,
IN ULONG  CheckFlags 
)

Definition at line 19 of file cminit.c.

29 {
30  PCMHIVE Hive;
32  FILE_FS_SIZE_INFORMATION FileSizeInformation;
34  ULONG Cluster;
35 
36  /* Assume failure */
37  *CmHive = NULL;
38 
39  /*
40  * The following are invalid:
41  * - An external hive that is also internal.
42  * - A log hive that is not a primary hive too.
43  * - A volatile hive that is linked to permanent storage,
44  * unless this hive is a shared system hive.
45  * - An in-memory initialization without hive data.
46  * - A log hive that is not linked to a correct file type.
47  */
48  if (((External) && ((Primary) || (Log))) ||
49  ((Log) && !(Primary)) ||
50  (!(CmpShareSystemHives) && (HiveFlags & HIVE_VOLATILE) &&
51  ((Primary) || (External) || (Log))) ||
52  ((OperationType == HINIT_MEMORY) && (!HiveData)) ||
53  ((Log) && (FileType != HFILE_TYPE_LOG)))
54  {
55  /* Fail the request */
57  }
58 
59  /* Check if this is a primary hive */
60  if (Primary)
61  {
62  /* Get the cluster size */
65  &FileSizeInformation,
68  if (!NT_SUCCESS(Status)) return Status;
69 
70  /* Make sure it's not larger then the block size */
71  if (FileSizeInformation.BytesPerSector > HBLOCK_SIZE)
72  {
73  /* Fail */
75  }
76 
77  /* Otherwise, calculate the cluster */
78  Cluster = FileSizeInformation.BytesPerSector / HSECTOR_SIZE;
79  Cluster = max(1, Cluster);
80  }
81  else
82  {
83  /* Otherwise use cluster 1 */
84  Cluster = 1;
85  }
86 
87  /* Allocate the hive */
89  if (!Hive) return STATUS_INSUFFICIENT_RESOURCES;
90 
91  /* Setup null fields */
92  Hive->UnloadEvent = NULL;
93  Hive->RootKcb = NULL;
94  Hive->Frozen = FALSE;
95  Hive->UnloadWorkItem = NULL;
96  Hive->GrowOnlyMode = FALSE;
97  Hive->GrowOffset = 0;
98  Hive->CellRemapArray = NULL;
99  Hive->UseCountLog.Next = 0;
100  Hive->LockHiveLog.Next = 0;
101  Hive->FileObject = NULL;
102  Hive->NotifyList.Flink = NULL;
103  Hive->NotifyList.Blink = NULL;
104 
105  /* Set the loading flag */
106  Hive->HiveIsLoading = TRUE;
107 
108  /* Set the current thread as creator */
110 
111  /* Initialize lists */
115 
116  /* Allocate the view log */
118  sizeof(KGUARDED_MUTEX),
119  TAG_CMHIVE);
120  if (!Hive->ViewLock)
121  {
122  /* Cleanup allocation and fail */
125  }
126 
127  /* Allocate the flush lock */
129  sizeof(ERESOURCE),
130  TAG_CMHIVE);
131  if (!Hive->FlusherLock)
132  {
133  /* Cleanup allocations and fail */
137  }
138 
139  /* Setup the handles */
140  Hive->FileHandles[HFILE_TYPE_PRIMARY] = Primary;
141  Hive->FileHandles[HFILE_TYPE_LOG] = Log;
143 
144  /* Initailize the guarded mutex */
146  Hive->ViewLockOwner = NULL;
147 
148  /* Initialize the flush lock */
150 
151  /* Setup hive locks */
153  Hive->HiveLockOwner = NULL;
155  Hive->WriterLockOwner = NULL;
157  Hive->HiveSecurityLockOwner = NULL;
158 
159  /* Clear file names */
160  RtlInitEmptyUnicodeString(&Hive->FileUserName, NULL, 0);
161  RtlInitEmptyUnicodeString(&Hive->FileFullPath, NULL, 0);
162 
163  /* Initialize the view list */
164  CmpInitHiveViewList(Hive);
165 
166  /* Initailize the security cache */
167  CmpInitSecurityCache(Hive);
168 
169  /* Setup flags */
170  Hive->Flags = 0;
171  Hive->FlushCount = 0;
172 
173  /* Initialize it */
174  Status = HvInitialize(&Hive->Hive,
175  OperationType,
176  HiveFlags,
177  FileType,
178  HiveData,
179  CmpAllocate,
180  CmpFree,
182  CmpFileWrite,
183  CmpFileRead,
184  CmpFileFlush,
185  Cluster,
186  FileName);
187  if (!NT_SUCCESS(Status))
188  {
189  /* Cleanup allocations and fail */
194  return Status;
195  }
196 
197  /* Check if we should verify the registry */
198  if ((OperationType == HINIT_FILE) ||
199  (OperationType == HINIT_MEMORY) ||
200  (OperationType == HINIT_MEMORY_INPLACE) ||
201  (OperationType == HINIT_MAPFILE))
202  {
203  /* Verify integrity */
204  ULONG CheckStatus = CmCheckRegistry(Hive, CheckFlags);
205  if (CheckStatus != 0)
206  {
207  /* Cleanup allocations and fail */
213  }
214  }
215 
216  /* Reset the loading flag */
217  Hive->HiveIsLoading = FALSE;
218 
219  /* Lock the hive list */
221 
222  /* Insert this hive */
224 
225  /* Release the lock */
227 
228  /* Return the hive and success */
229  *CmHive = Hive;
230  return STATUS_SUCCESS;
231 }
PKGUARDED_MUTEX ViewLock
Definition: cm.h:399
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
LIST_ENTRY TrustClassEntry
Definition: cm.h:431
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
PWORK_QUEUE_ITEM UnloadWorkItem
Definition: cm.h:422
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define HFILE_TYPE_EXTERNAL
Definition: hivedata.h:35
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LIST_ENTRY CmpHiveListHead
Definition: cmsysini.c:18
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define HIVE_VOLATILE
Definition: hivedata.h:23
#define STATUS_REGISTRY_IO_FAILED
Definition: ntstatus.h:555
LIST_ENTRY NotifyList
Definition: cm.h:395
NTSTATUS CMAPI HvInitialize(PHHIVE RegistryHive, ULONG OperationType, ULONG HiveFlags, ULONG FileType, PVOID HiveData OPTIONAL, PALLOCATE_ROUTINE Allocate, PFREE_ROUTINE Free, PFILE_SET_SIZE_ROUTINE FileSetSize, PFILE_WRITE_ROUTINE FileWrite, PFILE_READ_ROUTINE FileRead, PFILE_FLUSH_ROUTINE FileFlush, ULONG Cluster OPTIONAL, PCUNICODE_STRING FileName OPTIONAL)
Definition: hiveinit.c:522
PVOID NTAPI CmpAllocate(_In_ SIZE_T Size, _In_ BOOLEAN Paged, _In_ ULONG Tag)
Definition: bootreg.c:90
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
BOOLEAN Frozen
Definition: cm.h:421
CM_USE_COUNT_LOG UseCountLog
Definition: cm.h:428
ULONG Flags
Definition: cm.h:430
ULONG FlushCount
Definition: cm.h:432
#define HINIT_MAPFILE
Definition: hivedata.h:18
#define HINIT_MEMORY_INPLACE
Definition: hivedata.h:16
EX_PUSH_LOCK SecurityLock
Definition: cm.h:404
PKTHREAD HiveLockOwner
Definition: cm.h:398
#define HSECTOR_SIZE
Definition: hivedata.h:42
UNICODE_STRING FileUserName
Definition: cm.h:410
#define HINIT_FILE
Definition: hivedata.h:15
PCM_KEY_CONTROL_BLOCK RootKcb
Definition: cm.h:420
ULONG GrowOffset
Definition: cm.h:424
VOID NTAPI CmpInitHiveViewList(IN PCMHIVE Hive)
Definition: cmmapvw.c:21
HANDLE FileHandles[HFILE_TYPE_MAX]
Definition: cm.h:394
UNICODE_STRING FileFullPath
Definition: cm.h:409
smooth NULL
Definition: ftsmooth.c:416
static IDispatch External
Definition: htmldoc.c:521
HHIVE Hive
Definition: cm.h:393
#define ExInitializePushLock
Definition: ex.h:999
#define STATUS_REGISTRY_CORRUPT
Definition: ntstatus.h:554
BOOLEAN NTAPI CmpFileFlush(IN PHHIVE RegistryHive, IN ULONG FileType, IN OUT PLARGE_INTEGER FileOffset, IN ULONG Length)
Definition: cmwraprs.c:162
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
BOOLEAN HiveIsLoading
Definition: cm.h:433
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HFILE_TYPE_LOG
Definition: hivedata.h:34
VOID NTAPI CmpFree(_In_ PVOID Ptr, _In_ ULONG Quota)
Definition: bootreg.c:105
EX_PUSH_LOCK HiveLock
Definition: cm.h:397
USHORT Next
Definition: cm.h:383
PERESOURCE FlusherLock
Definition: cm.h:403
LIST_ENTRY HiveList
Definition: cm.h:396
NTSYSAPI NTSTATUS NTAPI ZwQueryVolumeInformationFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FsInformation, IN ULONG Length, IN FS_INFORMATION_CLASS FsInformationClass)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
ULONG NTAPI CmCheckRegistry(IN PCMHIVE RegistryHive, IN ULONG Flags)
Definition: cmcheck.c:21
EX_PUSH_LOCK WriterLock
Definition: cm.h:401
#define HINIT_MEMORY
Definition: hivedata.h:14
PKTHREAD ViewLockOwner
Definition: cm.h:400
PKTHREAD WriterLockOwner
Definition: cm.h:402
PFILE_OBJECT FileObject
Definition: cm.h:408
Status
Definition: gdiplustypes.h:24
FORCEINLINE VOID ExReleasePushLock(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1282
LIST_ENTRY KnodeConvertListHead
Definition: cm.h:426
VOID NTAPI CmpInitSecurityCache(IN PCMHIVE Hive)
Definition: cmsecach.c:21
BOOLEAN NTAPI CmpFileRead(IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, OUT PVOID Buffer, IN SIZE_T BufferLength)
Definition: cmwraprs.c:73
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
EX_PUSH_LOCK CmpHiveListHeadLock
Definition: cmdata.c:39
PCM_CELL_REMAP_BLOCK CellRemapArray
Definition: cm.h:427
#define HFILE_TYPE_PRIMARY
Definition: hivedata.h:33
PKTHREAD CreatorOwner
Definition: cm.h:434
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static PCMHIVE CmHive
Definition: registry.c:28
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
PKTHREAD HiveSecurityLockOwner
Definition: cm.h:405
BOOLEAN NTAPI CmpFileWrite(IN PHHIVE RegistryHive, IN ULONG FileType, IN PULONG FileOffset, IN PVOID Buffer, IN SIZE_T BufferLength)
Definition: cmwraprs.c:97
PKEVENT UnloadEvent
Definition: cm.h:419
CM_USE_COUNT_LOG LockHiveLog
Definition: cm.h:429
ULONG ERESOURCE
Definition: env_spec_w32.h:594
unsigned int ULONG
Definition: retypes.h:1
#define TAG_CMHIVE
Definition: cmlib.h:205
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
BOOLEAN NTAPI CmpFileSetSize(IN PHHIVE RegistryHive, IN ULONG FileType, IN ULONG FileSize, IN ULONG OldFileSize)
Definition: cmwraprs.c:125
#define KeGetCurrentThread
Definition: hal.h:44
return STATUS_SUCCESS
Definition: btrfs.c:2725
LIST_ENTRY KcbConvertListHead
Definition: cm.h:425
Definition: cm.h:391
BOOLEAN CmpShareSystemHives
Definition: cmdata.c:57
BOOLEAN GrowOnlyMode
Definition: cm.h:423

Referenced by CmInitSystem1(), CmpInitHiveFromFile(), CmpInitializeSystemHive(), CmSaveKey(), and CmSaveMergedKeys().

◆ CmpOpenHiveFiles()

NTSTATUS NTAPI CmpOpenHiveFiles ( IN PCUNICODE_STRING  BaseName,
IN PCWSTR Extension  OPTIONAL,
OUT PHANDLE  Primary,
OUT PHANDLE  Log,
OUT PULONG  PrimaryDisposition,
OUT PULONG  LogDisposition,
IN BOOLEAN  CreateAllowed,
IN BOOLEAN  MarkAsSystemHive,
IN BOOLEAN  NoBuffering,
OUT PULONG ClusterSize  OPTIONAL 
)

Definition at line 266 of file cminit.c.

276 {
278  PKEVENT Event;
280  UNICODE_STRING FullName, ExtensionName;
281  PWCHAR NameBuffer;
282  USHORT Length;
285  ULONG AttributeFlags, ShareMode, DesiredAccess, CreateDisposition, IoFlags;
286  USHORT CompressionState;
288  FILE_FS_SIZE_INFORMATION FsSizeInformation;
289 
290  /* Create event */
292  if (!NT_SUCCESS(Status)) return Status;
293 
294  /* Initialize the full name */
295  RtlInitEmptyUnicodeString(&FullName, NULL, 0);
296  Length = BaseName->Length;
297 
298  /* Check if we have an extension */
299  if (Extension)
300  {
301  /* Update the name length */
302  Length += (USHORT)wcslen(Extension) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
303 
304  /* Allocate the buffer for the full name */
306  if (!NameBuffer)
307  {
308  /* Fail */
311  return STATUS_NO_MEMORY;
312  }
313 
314  /* Build the full name */
315  FullName.Buffer = NameBuffer;
317  RtlCopyUnicodeString(&FullName, BaseName);
318  }
319  else
320  {
321  /* The base name is the full name */
322  FullName = *BaseName;
323  NameBuffer = NULL;
324  }
325 
326  /* Initialize the attributes */
328  &FullName,
330  NULL,
331  NULL);
332 
333  /* Check if we can create the hive */
334  if ((CreateAllowed) && !(CmpShareSystemHives))
335  {
336  /* Open only or create */
338  }
339  else
340  {
341  /* Open only */
343  }
344 
345  /* Setup the flags */
346  // FIXME : FILE_OPEN_FOR_BACKUP_INTENT is unimplemented and breaks 3rd stage boot
347  IoFlags = //FILE_OPEN_FOR_BACKUP_INTENT |
350  (NoBuffering ? FILE_NO_INTERMEDIATE_BUFFERING : 0);
351 
352  /* Set share and access modes */
354  {
355  /* We're on Live CD or otherwise sharing */
357  ShareMode = FILE_SHARE_READ;
358  }
359  else
360  {
361  /* We want to write exclusively */
362  ShareMode = 0;
364  }
365 
366  /* Default attributes */
367  AttributeFlags = FILE_ATTRIBUTE_NORMAL;
368 
369  /* Now create the file */
370  Status = ZwCreateFile(Primary,
373  &IoStatusBlock,
374  NULL,
375  AttributeFlags,
376  ShareMode,
379  NULL,
380  0);
381  /* Check if anything failed until now */
382  if (!NT_SUCCESS(Status))
383  {
384  DPRINT1("ZwCreateFile(%wZ) failed, Status 0x%08lx.\n", ObjectAttributes.ObjectName, Status);
385 
386  /* Close handles and free buffers */
387  if (NameBuffer) ExFreePoolWithTag(NameBuffer, TAG_CM);
390  *Primary = NULL;
391  return Status;
392  }
393 
394  if (MarkAsSystemHive)
395  {
396  /* We opened it, mark it as a system hive */
397  Status = ZwFsControlFile(*Primary,
398  EventHandle,
399  NULL,
400  NULL,
401  &IoStatusBlock,
403  NULL,
404  0,
405  NULL,
406  0);
407  if (Status == STATUS_PENDING)
408  {
409  /* Wait for completion */
411  Executive,
412  KernelMode,
413  FALSE,
414  NULL);
416  }
417 
418  /* If we don't support it, ignore the failure */
420 
421  if (!NT_SUCCESS(Status))
422  {
423  /* Close handles and free buffers */
424  if (NameBuffer) ExFreePoolWithTag(NameBuffer, TAG_CM);
427  ZwClose(*Primary);
428  *Primary = NULL;
429  return Status;
430  }
431  }
432 
433  /* Disable compression */
434  CompressionState = 0;
435  Status = ZwFsControlFile(*Primary,
436  EventHandle,
437  NULL,
438  NULL,
439  &IoStatusBlock,
441  &CompressionState,
442  sizeof(CompressionState),
443  NULL,
444  0);
445  if (Status == STATUS_PENDING)
446  {
447  /* Wait for completion */
449  Executive,
450  KernelMode,
451  FALSE,
452  NULL);
453  }
454 
455  /* Get the disposition */
456  *PrimaryDisposition = (ULONG)IoStatusBlock.Information;
458  {
459  /* Check how large the file is */
460  Status = ZwQueryInformationFile(*Primary,
461  &IoStatusBlock,
463  sizeof(FileInformation),
465  if (NT_SUCCESS(Status))
466  {
467  /* Check if it's 0 bytes */
468  if (!FileInformation.EndOfFile.QuadPart)
469  {
470  /* Assume it's a new file */
471  *PrimaryDisposition = FILE_CREATED;
472  }
473  }
474  }
475 
476  /* Check if the caller wants cluster size returned */
477  if (ClusterSize)
478  {
479  /* Query it */
481  &IoStatusBlock,
482  &FsSizeInformation,
483  sizeof(FsSizeInformation),
485  if (!NT_SUCCESS(Status))
486  {
487  /* Close handles and free buffers */
488  if (NameBuffer) ExFreePoolWithTag(NameBuffer, TAG_CM);
491  return Status;
492  }
493 
494  /* Check if the sector size is invalid */
495  if (FsSizeInformation.BytesPerSector > HBLOCK_SIZE)
496  {
497  /* Close handles and free buffers */
498  if (NameBuffer) ExFreePoolWithTag(NameBuffer, TAG_CM);
502  }
503 
504  /* Return cluster size */
505  *ClusterSize = max(1, FsSizeInformation.BytesPerSector / HSECTOR_SIZE);
506  }
507 
508  /* Check if we don't need to create a log file */
509  if (!Extension)
510  {
511  /* We're done, close handles */
514  return STATUS_SUCCESS;
515  }
516 
517  /* Check if we can create the hive */
519  if (*PrimaryDisposition == FILE_CREATED)
520  {
521  /* Over-write the existing log file, since this is a new hive */
523  }
524 
525  /* Setup the name */
526  RtlInitUnicodeString(&ExtensionName, Extension);
527  RtlAppendUnicodeStringToString(&FullName, &ExtensionName);
528 
529  /* Initialize the attributes */
531  &FullName,
533  NULL,
534  NULL);
535 
536  /* Setup the flags */
538 
539  /* Check if this is a log file */
540  if (!_wcsnicmp(Extension, L".log", 4))
541  {
542  /* Hide log files */
543  AttributeFlags |= FILE_ATTRIBUTE_HIDDEN;
544  }
545 
546  /* Now create the file */
547  Status = ZwCreateFile(Log,
550  &IoStatusBlock,
551  NULL,
552  AttributeFlags,
553  ShareMode,
555  IoFlags,
556  NULL,
557  0);
558  if ((NT_SUCCESS(Status)) && (MarkAsSystemHive))
559  {
560  /* We opened it, mark it as a system hive */
561  Status = ZwFsControlFile(*Log,
562  EventHandle,
563  NULL,
564  NULL,
565  &IoStatusBlock,
567  NULL,
568  0,
569  NULL,
570  0);
571  if (Status == STATUS_PENDING)
572  {
573  /* Wait for completion */
575  Executive,
576  KernelMode,
577  FALSE,
578  NULL);
580  }
581 
582  /* If we don't support it, ignore the failure */
584 
585  /* If we failed, close the handle */
586  if (!NT_SUCCESS(Status)) ZwClose(*Log);
587  }
588 
589  /* Check if anything failed until now */
590  if (!NT_SUCCESS(Status))
591  {
592  /* Clear the handle */
593  *Log = NULL;
594  }
595  else
596  {
597  /* Disable compression */
598  Status = ZwFsControlFile(*Log,
599  EventHandle,
600  NULL,
601  NULL,
602  &IoStatusBlock,
604  &CompressionState,
605  sizeof(CompressionState),
606  NULL,
607  0);
608  if (Status == STATUS_PENDING)
609  {
610  /* Wait for completion */
612  Executive,
613  KernelMode,
614  FALSE,
615  NULL);
616  }
617 
618  /* Return the disposition */
619  *LogDisposition = (ULONG)IoStatusBlock.Information;
620  }
621 
622  /* We're done, close handles and free buffers */
623  if (NameBuffer) ExFreePoolWithTag(NameBuffer, TAG_CM);
626  return STATUS_SUCCESS;
627 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define max(a, b)
Definition: svc.c:63
#define FILE_NO_COMPRESSION
Definition: from_kernel.h:43
#define HBLOCK_SIZE
Definition: hivedata.h:41
#define FILE_OPEN_IF
Definition: from_kernel.h:56
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define FSCTL_SET_COMPRESSION
Definition: nt_native.h:842
LONG NTSTATUS
Definition: precomp.h:26
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
static OUT PIO_STATUS_BLOCK OUT PVOID FileInformation
Definition: pipe.c:75
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
uint16_t * PWCHAR
Definition: typedefs.h:54
#define HSECTOR_SIZE
Definition: hivedata.h:42
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FILE_SHARE_READ
Definition: compat.h:125
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
void * Buffer
Definition: sprintf.c:453
#define UNICODE_NULL
#define FILE_READ_DATA
Definition: nt_native.h:628
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
NTSYSAPI NTSTATUS NTAPI ZwFsControlFile(IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferSize, OUT PVOID OutputBuffer, IN ULONG OutputBufferSize)
smooth NULL
Definition: ftsmooth.c:416
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FSCTL_MARK_AS_SYSTEM_HIVE
Definition: nt_native.h:845
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
DWORD ClusterSize
Definition: format.c:67
_In_ PSTRING FullName
Definition: rtlfuncs.h:1649
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwQueryVolumeInformationFile(IN HANDLE FileHandle, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID FsInformation, IN ULONG Length, IN FS_INFORMATION_CLASS FsInformationClass)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define STATUS_CANNOT_LOAD_REGISTRY_FILE
Definition: ntstatus.h:654
BOOLEAN CmpMiniNTBoot
Definition: cmdata.c:60
#define TAG_CM
Definition: cmlib.h:203
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define SYNCHRONIZE
Definition: nt_native.h:61
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
NTSTATUS NTAPI CmpCreateEvent(IN EVENT_TYPE EventType, OUT PHANDLE EventHandle, OUT PKEVENT *Event)
Definition: cmwraprs.c:19
unsigned short USHORT
Definition: pedump.c:61
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK DesiredAccess
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define FILE_RANDOM_ACCESS
Definition: from_kernel.h:38
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_CREATED
Definition: nt_native.h:770
#define DPRINT1
Definition: precomp.h:8
#define FileStandardInformation
Definition: propsheet.cpp:61
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2725
unsigned short MaximumLength
Definition: sprintf.c:452
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT _In_ ULONG CreateDisposition
Definition: create.c:4157
_Inout_opt_ PUNICODE_STRING Extension
Definition: fltkernel.h:1092
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOLEAN CmpShareSystemHives
Definition: cmdata.c:57
_Out_ PHANDLE EventHandle
Definition: iofuncs.h:855

Referenced by _Function_class_(), and CmpInitHiveFromFile().