- Check first for an existing directory object in NtCreateDirectoryObject.
authorHartmut Birr <osexpert@googlemail.com>
Sun, 5 Sep 2004 22:26:17 +0000 (22:26 +0000)
committerHartmut Birr <osexpert@googlemail.com>
Sun, 5 Sep 2004 22:26:17 +0000 (22:26 +0000)
svn path=/trunk/; revision=10789

reactos/ntoskrnl/ob/dirobj.c

index 7b2512f..2fe336e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: dirobj.c,v 1.25 2004/08/24 17:07:27 navaraf Exp $
+/* $Id: dirobj.c,v 1.26 2004/09/05 22:26:17 hbirr Exp $
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
@@ -405,28 +405,35 @@ NtCreateDirectoryObject (OUT PHANDLE DirectoryHandle,
         DirectoryHandle, DesiredAccess, ObjectAttributes,
         ObjectAttributes->ObjectName);
 
-  Status = ObCreateObject (ExGetPreviousMode(),
-                          ObDirectoryType,
-                          ObjectAttributes,
-                          ExGetPreviousMode(),
-                          NULL,
-                          sizeof(DIRECTORY_OBJECT),
-                          0,
-                          0,
-                          (PVOID*)&DirectoryObject);
-  if (!NT_SUCCESS(Status))
-    {
-      return Status;
-    }
+  Status = NtOpenDirectoryObject (DirectoryHandle,
+                                 DesiredAccess,
+                                 ObjectAttributes);
+
+  if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
+  {
+     Status = ObCreateObject (ExGetPreviousMode(),
+                             ObDirectoryType,
+                             ObjectAttributes,
+                             ExGetPreviousMode(),
+                             NULL,
+                             sizeof(DIRECTORY_OBJECT),
+                             0,
+                             0,
+                             (PVOID*)&DirectoryObject);
+     if (!NT_SUCCESS(Status))
+     {
+        return Status;
+     }
 
-  Status = ObInsertObject ((PVOID)DirectoryObject,
-                          NULL,
-                          DesiredAccess,
-                          0,
-                          NULL,
-                          DirectoryHandle);
+     Status = ObInsertObject ((PVOID)DirectoryObject,
+                             NULL,
+                             DesiredAccess,
+                             0,
+                             NULL,
+                             DirectoryHandle);
 
-  ObDereferenceObject(DirectoryObject);
+     ObDereferenceObject(DirectoryObject);
+  }
 
   return Status;
 }