- ObpCreateDosDevicesDirectory: Check that allocation succeeded before dereference
[reactos.git] / reactos / ntoskrnl / ob / obname.c
index 2ffd720..c97d4ce 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * PROJECT:         ReactOS Kernel
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            ntoskrnl/ob/namespce.c
+ * FILE:            ntoskrnl/ob/obname.c
  * PURPOSE:         Manages all functions related to the Object Manager name-
  *                  space, such as finding objects or querying their names.
  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
@@ -16,7 +16,7 @@
 #include <debug.h>
 
 BOOLEAN ObpCaseInsensitive = TRUE;
-POBJECT_DIRECTORY NameSpaceRoot;
+POBJECT_DIRECTORY ObpRootDirectoryObject;
 POBJECT_DIRECTORY ObpTypeDirectoryObject;
 
 /* DOS Device Prefix \??\ and \?? */
@@ -100,7 +100,8 @@ ObpCreateDosDevicesDirectory(VOID)
     /* FIXME: Hack Hack! */
     ObSystemDeviceMap = ExAllocatePoolWithTag(NonPagedPool,
                                               sizeof(*ObSystemDeviceMap),
-                                              TAG('O', 'b', 'D', 'm'));
+                                              'mDbO');
+    if (!ObSystemDeviceMap) return STATUS_INSUFFICIENT_RESOURCES;
     RtlZeroMemory(ObSystemDeviceMap, sizeof(*ObSystemDeviceMap));
 
     /* Return status */
@@ -179,7 +180,7 @@ ObpDeleteNameCheck(IN PVOID Object)
 
     /* Get object structures */
     ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
-    ObjectNameInfo = ObpAcquireNameInformation(ObjectHeader);
+    ObjectNameInfo = ObpReferenceNameInfo(ObjectHeader);
     ObjectType = ObjectHeader->Type;
 
     /*
@@ -193,7 +194,7 @@ ObpDeleteNameCheck(IN PVOID Object)
          !(ObjectHeader->Flags & OB_FLAG_PERMANENT))
     {
         /* Setup a lookup context */
-        ObpInitializeDirectoryLookup(&Context);
+        ObpInitializeLookupContext(&Context);
 
         /* Lock the directory */
         ObpAcquireDirectoryLockExclusive(ObjectNameInfo->Directory, &Context);
@@ -206,8 +207,8 @@ ObpDeleteNameCheck(IN PVOID Object)
                                          &Context);
         if (Object)
         {
-            /* Lock the object type */
-            ObpEnterObjectTypeMutex(ObjectType);
+            /* Lock the object */
+            ObpAcquireObjectLock(ObjectHeader);
 
             /* Make sure we can still delete the object */
             if (!(ObjectHeader->HandleCount) &&
@@ -238,20 +239,20 @@ ObpDeleteNameCheck(IN PVOID Object)
             }
 
             /* Release the lock */
-            ObpLeaveObjectTypeMutex(ObjectType);
+            ObpReleaseObjectLock(ObjectHeader);
         }
 
         /* Cleanup after lookup */
-        ObpCleanupDirectoryLookup(&Context);
+        ObpReleaseLookupContext(&Context);
 
         /* Remove another query reference since we added one on top */
-        ObpReleaseNameInformation(ObjectNameInfo);
+        ObpDereferenceNameInfo(ObjectNameInfo);
 
         /* Check if we were inserted in a directory */
         if (Directory)
         {
             /* We were, so first remove the extra reference we had added */
-            ObpReleaseNameInformation(ObjectNameInfo);
+            ObpDereferenceNameInfo(ObjectNameInfo);
 
             /* Now dereference the object as well */
             ObDereferenceObject(Object);
@@ -260,7 +261,7 @@ ObpDeleteNameCheck(IN PVOID Object)
     else
     {
         /* Remove the reference we added */
-        ObpReleaseNameInformation(ObjectNameInfo);
+        ObpDereferenceNameInfo(ObjectNameInfo);
     }
 }
 
@@ -282,7 +283,6 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
     POBJECT_HEADER ObjectHeader;
     UNICODE_STRING ComponentName, RemainingName;
     BOOLEAN Reparse = FALSE, SymLink = FALSE;
-    PDEVICE_MAP DeviceMap = NULL;
     POBJECT_DIRECTORY Directory = NULL, ParentDirectory = NULL, RootDirectory;
     POBJECT_DIRECTORY ReferencedDirectory = NULL, ReferencedParentDirectory = NULL;
     KIRQL CalloutIrql;
@@ -300,7 +300,7 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
             InsertObject);
 
     /* Initialize starting state */
-    ObpInitializeDirectoryLookup(LookupContext);
+    ObpInitializeLookupContext(LookupContext);
     *FoundObject = NULL;
     Status = STATUS_SUCCESS;
     Object = NULL;
@@ -407,7 +407,7 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
                 {
                     /* Reparsed to the root directory, so start over */
                     ObDereferenceObject(RootDirectory);
-                    RootDirectory = NameSpaceRoot;
+                    RootDirectory = ObpRootDirectoryObject;
 
                     /* Don't use this anymore, since we're starting at root */
                     RootHandle = NULL;
@@ -448,7 +448,7 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
     else
     {
         /* We did not get a Root Directory, so use the root */
-        RootDirectory = NameSpaceRoot;
+        RootDirectory = ObpRootDirectoryObject;
 
         /* It must start with a path separator */
         if (!(ObjectName->Length) ||
@@ -497,13 +497,7 @@ ObpLookupObjectName(IN HANDLE RootHandle OPTIONAL,
         else
         {
 ParseFromRoot:
-            /* Check if we have a device map */
-            if (DeviceMap)
-            {
-                /* Dereference it */
-                //ObfDereferenceDeviceMap(DeviceMap);
-                DeviceMap = NULL;
-            }
+            /* FIXME: Check if we have a device map */
 
             /* Check if this is a possible DOS name */
             if (!((ULONG_PTR)(ObjectName->Buffer) & 7))
@@ -720,7 +714,7 @@ ParseFromRoot:
                 if (ObjectNameInfo->Name.Buffer)
                 {
                     /* Free it */
-                    ExFreePool(ObjectNameInfo->Name.Buffer);
+                    ExFreePoolWithTag(ObjectNameInfo->Name.Buffer, OB_NAME_TAG );
                 }
 
                 /* Write new one */
@@ -755,7 +749,7 @@ ReparseObject:
                 InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
 
                 /* Cleanup from the first lookup */
-                ObpCleanupDirectoryLookup(LookupContext);
+                ObpReleaseLookupContext(LookupContext);
 
                 /* Check if we have a referenced directory */
                 if (ReferencedDirectory)
@@ -811,7 +805,7 @@ ReparseObject:
 
                         /* Start at Root */
                         ParentDirectory = NULL;
-                        RootDirectory = NameSpaceRoot;
+                        RootDirectory = ObpRootDirectoryObject;
 
                         /* Check for reparse status */
                         if (Status == STATUS_REPARSE_OBJECT)
@@ -838,7 +832,7 @@ ReparseObject:
                             goto ParseFromRoot;
                         }
                     }
-                    else if (RootDirectory == NameSpaceRoot)
+                    else if (RootDirectory == ObpRootDirectoryObject)
                     {
                         /* We got STATUS_REPARSE but are at the Root Directory */
                         Object = NULL;
@@ -931,7 +925,7 @@ ReparseObject:
     if (!NT_SUCCESS(Status))
     {
         /* Cleanup after lookup */
-        ObpCleanupDirectoryLookup(LookupContext);
+        ObpReleaseLookupContext(LookupContext);
     }
 
     /* Check if we have a device map and dereference it if so */
@@ -1025,7 +1019,7 @@ ObQueryNameString(IN PVOID Object,
      * enough right at the beginning, not work our way through
      * and find out at the end
      */
-    if (Object == NameSpaceRoot)
+    if (Object == ObpRootDirectoryObject)
     {
         /* Size of the '\' string */
         NameSize = sizeof(OBJ_NAME_PATH_SEPARATOR);
@@ -1037,7 +1031,7 @@ ObQueryNameString(IN PVOID Object,
         NameSize = sizeof(OBJ_NAME_PATH_SEPARATOR) + LocalInfo->Name.Length;
 
         /* Loop inside the directory to get the top-most one (meaning root) */
-        while ((ParentDirectory != NameSpaceRoot) && (ParentDirectory))
+        while ((ParentDirectory != ObpRootDirectoryObject) && (ParentDirectory))
         {
             /* Get the Name Information */
             LocalInfo = OBJECT_HEADER_TO_NAME_INFO(
@@ -1080,7 +1074,7 @@ ObQueryNameString(IN PVOID Object,
     *--ObjectName = UNICODE_NULL;
 
     /* Check if the object is actually the Root directory */
-    if (Object == NameSpaceRoot)
+    if (Object == ObpRootDirectoryObject)
     {
         /* This is already the Root Directory, return "\\" */
         *--ObjectName = OBJ_NAME_PATH_SEPARATOR;
@@ -1101,7 +1095,7 @@ ObQueryNameString(IN PVOID Object,
 
         /* Now parse the Parent directories until we reach the top */
         ParentDirectory = LocalInfo->Directory;
-        while ((ParentDirectory != NameSpaceRoot) && (ParentDirectory))
+        while ((ParentDirectory != ObpRootDirectoryObject) && (ParentDirectory))
         {
             /* Get the name information */
             LocalInfo = OBJECT_HEADER_TO_NAME_INFO(