[ros-diffs] [ion] 26714: - Change CmiInitNonVolatileRegistry hive to use CmpOpenHiveFiles and CmpInitializeHive. Required a lot of hacking to get to work right, but at least it does, and uses our new code paths. - Update CmpInitializeHive with the HINIT_FILE hack required for current cmlib functionality.

ion at svn.reactos.org ion at svn.reactos.org
Sat May 12 08:47:40 CEST 2007


Author: ion
Date: Sat May 12 10:47:39 2007
New Revision: 26714

URL: http://svn.reactos.org/svn/reactos?rev=26714&view=rev
Log:
- Change CmiInitNonVolatileRegistry hive to use CmpOpenHiveFiles and CmpInitializeHive. Required a lot of hacking to get to work right, but at least it does, and uses our new code paths.
- Update CmpInitializeHive with the HINIT_FILE hack required for current cmlib functionality.

Modified:
    trunk/reactos/ntoskrnl/cm/regfile.c
    trunk/reactos/ntoskrnl/config/cminit.c

Modified: trunk/reactos/ntoskrnl/cm/regfile.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/cm/regfile.c?rev=26714&r1=26713&r2=26714&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/cm/regfile.c (original)
+++ trunk/reactos/ntoskrnl/cm/regfile.c Sat May 12 10:47:39 2007
@@ -23,6 +23,19 @@
 
 /* FUNCTIONS ****************************************************************/
 
+NTSTATUS
+NTAPI
+CmpInitializeHive(OUT PEREGISTRY_HIVE *RegistryHive,
+                  IN ULONG OperationType,
+                  IN ULONG HiveFlags,
+                  IN ULONG FileType,
+                  IN PVOID HiveData OPTIONAL,
+                  IN HANDLE Primary,
+                  IN HANDLE Log,
+                  IN HANDLE External,
+                  IN PUNICODE_STRING FileName OPTIONAL,
+                  IN ULONG CheckFlags);
+
 static NTSTATUS
 CmiCreateNewRegFile(HANDLE FileHandle)
 {
@@ -57,95 +70,66 @@
 }
 
 static NTSTATUS
-CmiInitNonVolatileRegistryHive (PEREGISTRY_HIVE RegistryHive,
-				PWSTR Filename)
-{
-  OBJECT_ATTRIBUTES ObjectAttributes;
-  ULONG CreateDisposition;
-  IO_STATUS_BLOCK IoSB;
-  HANDLE FileHandle;
-  NTSTATUS Status;
-  FILE_STANDARD_INFORMATION FileInformation;
-
-  DPRINT("CmiInitNonVolatileRegistryHive(%p, %S) called\n",
-	 RegistryHive, Filename);
-
-  /* Duplicate Filename */
-  Status = RtlCreateUnicodeString(&RegistryHive->HiveFileName,
-                                  Filename);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT("RtlCreateUnicodeString() failed (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  InitializeObjectAttributes(&ObjectAttributes,
-			     &RegistryHive->HiveFileName,
-			     OBJ_CASE_INSENSITIVE,
-			     NULL,
-			     NULL);
-
-  CreateDisposition = FILE_OPEN_IF;
-  Status = ZwCreateFile(&FileHandle,
-			FILE_ALL_ACCESS,
-			&ObjectAttributes,
-			&IoSB,
-			NULL,
-			FILE_ATTRIBUTE_NORMAL,
-			0,
-			CreateDisposition,
-			FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT,
-			NULL,
-			0);
-  if (!NT_SUCCESS(Status))
-    {
-      RtlFreeUnicodeString(&RegistryHive->HiveFileName);
-      DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
-      return(Status);
-    }
-
-  if (IoSB.Information != FILE_OPENED)
-    {
-      Status = CmiCreateNewRegFile(FileHandle);
-      if (!NT_SUCCESS(Status))
-	{
-	  DPRINT("CmiCreateNewRegFile() failed (Status %lx)\n", Status);
-	  ZwClose(FileHandle);
-	  RtlFreeUnicodeString(&RegistryHive->HiveFileName);
-	  return(Status);
-	}
-    }
-
-    RegistryHive->HiveHandle = FileHandle;
-
-    /* Check how large the file is */
-    ZwQueryInformationFile(FileHandle,
-                           &IoSB,
-                           &FileInformation,
-                           sizeof(FileInformation),
-                           FileStandardInformation);
-  Status = HvInitialize(&RegistryHive->Hive, HINIT_FILE, 0, 0,
-                        0, FileInformation.EndOfFile.LowPart,
-                        CmpAllocate, CmpFree,
-                        CmpFileRead, CmpFileWrite, CmpFileSetSize,
-                        CmpFileFlush, NULL);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT1("Failed to open hive\n");
-      RtlFreeUnicodeString(&RegistryHive->HiveFileName);
-      ZwClose(FileHandle);
-      return Status;
-    }
-
-  CmPrepareHive(&RegistryHive->Hive);
-
-  /* Close the hive file */
-  ZwClose(FileHandle);
-
-  DPRINT("CmiInitNonVolatileRegistryHive(%p, %S) - Finished.\n",
-	 RegistryHive, Filename);
-
-  return STATUS_SUCCESS;
+CmiInitNonVolatileRegistryHive (IN ULONG HiveFlags,
+                                IN PUNICODE_STRING HiveName,
+                                OUT PEREGISTRY_HIVE *Hive)
+{
+    ULONG CreateDisposition, LogDisposition;
+    HANDLE FileHandle, LogHandle;
+    NTSTATUS Status;
+    //ULONG Operation;
+    PEREGISTRY_HIVE NewHive;
+
+    *Hive = NULL;
+
+    Status = CmpOpenHiveFiles(HiveName,
+                              NULL, //L".LOG",
+                              &FileHandle,
+                              &LogHandle,
+                              &CreateDisposition,
+                              &LogDisposition,
+                              TRUE,
+                              FALSE,
+                              TRUE,
+                              NULL);
+    if (CreateDisposition == FILE_CREATED)
+    {
+        Status = CmiCreateNewRegFile(FileHandle);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT("CmiCreateNewRegFile() failed (Status %lx)\n", Status);
+            ZwClose(FileHandle);
+            return(Status);
+        }
+    }
+
+    Status = CmpInitializeHive(&NewHive,
+                               HINIT_FILE,
+                               HiveFlags,
+                               HFILE_TYPE_PRIMARY,
+                               NULL,
+                               FileHandle,
+                               NULL,
+                               NULL,
+                               HiveName,
+                               0);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to open hive\n");
+        ZwClose(FileHandle);
+        return Status;
+    }
+
+    CmPrepareHive(&NewHive->Hive);
+    NewHive->Flags = HiveFlags;
+
+    RtlCreateUnicodeString(&NewHive->HiveFileName, HiveName->Buffer);
+
+    /* Close the hive file */
+    ZwClose(FileHandle);
+
+    *Hive = NewHive;
+    return Status;
 }
 
 NTSTATUS
@@ -161,33 +145,15 @@
   if (Flags & ~REG_NO_LAZY_FLUSH)
     return STATUS_INVALID_PARAMETER;
 
-  Hive = ExAllocatePool (NonPagedPool,
-			 sizeof(EREGISTRY_HIVE));
-  if (Hive == NULL)
-    {
-      DPRINT1 ("Failed to allocate hive header.\n");
-      return STATUS_INSUFFICIENT_RESOURCES;
-    }
-  RtlZeroMemory (Hive,
-		 sizeof(EREGISTRY_HIVE));
-
-  DPRINT ("Hive 0x%p\n", Hive);
-  Hive->Flags = (Flags & REG_NO_LAZY_FLUSH) ? HIVE_NO_SYNCH : 0;
-
-  Status = CmiInitNonVolatileRegistryHive (Hive,
-					   FileName->Buffer);
+  Status = CmiInitNonVolatileRegistryHive ((Flags & REG_NO_LAZY_FLUSH) ? HIVE_NO_SYNCH : 0,
+					   FileName,
+                       &Hive);
   if (!NT_SUCCESS (Status))
     {
       DPRINT1 ("CmiInitNonVolatileRegistryHive() failed (Status %lx)\n", Status);
       ExFreePool (Hive);
       return Status;
     }
-
-  /* Add the new hive to the hive list */
-  InsertTailList (&CmpHiveListHead,
-		  &Hive->HiveList);
-
-  VERIFY_REGISTRY_HIVE(Hive);
 
   Status = CmiConnectHive (KeyObjectAttributes,
 			   Hive);

Modified: trunk/reactos/ntoskrnl/config/cminit.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cminit.c?rev=26714&r1=26713&r2=26714&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/config/cminit.c (original)
+++ trunk/reactos/ntoskrnl/config/cminit.c Sat May 12 10:47:39 2007
@@ -32,6 +32,7 @@
     PCMHIVE Hive;
 #else
     PEREGISTRY_HIVE Hive;
+    FILE_STANDARD_INFORMATION FileInformation;
 #endif
     IO_STATUS_BLOCK IoStatusBlock;
     FILE_FS_SIZE_INFORMATION FileSizeInformation;
@@ -167,6 +168,15 @@
 
     /* Set flags */
     Hive->Flags = HiveFlags;
+    Hive->HiveHandle = Primary;
+
+    /* Check how large the file is */
+    ZwQueryInformationFile(Primary,
+                           &IoStatusBlock,
+                           &FileInformation,
+                           sizeof(FileInformation),
+                           FileStandardInformation);
+    Cluster = FileInformation.EndOfFile.LowPart;
 #endif
 
     /* Initialize it */




More information about the Ros-diffs mailing list