2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ob/namespc.c
5 * PURPOSE: Manages the system namespace
6 * PROGRAMMER: David Welch (welch@mcmail.com)
11 /* INCLUDES ***************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/ob.h>
16 #include <internal/io.h>
17 #include <internal/string.h>
20 #include <internal/debug.h>
22 /* GLOBALS ****************************************************************/
24 POBJECT_TYPE ObDirectoryType
= NULL
;
26 PDIRECTORY_OBJECT NameSpaceRoot
= NULL
;
28 /* FUNCTIONS **************************************************************/
30 NTSTATUS STDCALL
ObReferenceObjectByName(PUNICODE_STRING ObjectPath
,
32 PACCESS_STATE PassedAccessState
,
33 ACCESS_MASK DesiredAccess
,
34 POBJECT_TYPE ObjectType
,
35 KPROCESSOR_MODE AccessMode
,
40 UNICODE_STRING RemainingPath
;
41 // PWSTR RemainingPath;
42 OBJECT_ATTRIBUTES ObjectAttributes
;
44 InitializeObjectAttributes(&ObjectAttributes
,
49 ObFindObject(&ObjectAttributes
,
53 if (RemainingPath
.Buffer
!= NULL
||
57 RtlFreeUnicodeString (&RemainingPath
);
58 return(STATUS_UNSUCCESSFUL
);
61 RtlFreeUnicodeString (&RemainingPath
);
62 return(STATUS_SUCCESS
);
65 VOID
ObAddEntryDirectory(PDIRECTORY_OBJECT Parent
,
69 * FUNCTION: Add an entry to a namespace directory
71 * parent = directory to add in
72 * name = Name to give the entry
73 * Object = Header of the object to add the entry for
77 POBJECT_HEADER Header
= BODY_TO_HEADER(Object
);
79 RtlInitUnicodeString(&Header
->Name
, wcsdup(Name
));
80 Header
->Parent
= Parent
;
82 KeAcquireSpinLock(&Parent
->Lock
, &oldlvl
);
83 InsertTailList(&Parent
->head
, &Header
->Entry
);
84 KeReleaseSpinLock(&Parent
->Lock
, oldlvl
);
87 PVOID
ObpFindEntryDirectory(PDIRECTORY_OBJECT DirectoryObject
,
91 PLIST_ENTRY current
= DirectoryObject
->head
.Flink
;
92 POBJECT_HEADER current_obj
;
94 DPRINT("ObDirLookup(dir %x, name %S)\n",DirectoryObject
, Name
);
98 return(DirectoryObject
);
100 if (Name
[0]=='.' && Name
[1]==0)
102 return(DirectoryObject
);
104 if (Name
[0]=='.' && Name
[1]=='.' && Name
[2]==0)
106 return(BODY_TO_HEADER(DirectoryObject
)->Parent
);
108 while (current
!=(&(DirectoryObject
->head
)))
110 current_obj
= CONTAINING_RECORD(current
,OBJECT_HEADER
,Entry
);
111 DPRINT("Scanning %S %S\n",current_obj
->Name
.Buffer
, Name
);
112 if (Attributes
& OBJ_CASE_INSENSITIVE
)
114 if (_wcsicmp(current_obj
->Name
.Buffer
, Name
)==0)
116 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
117 return(HEADER_TO_BODY(current_obj
));
122 if ( wcscmp(current_obj
->Name
.Buffer
, Name
)==0)
124 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
125 return(HEADER_TO_BODY(current_obj
));
128 current
= current
->Flink
;
130 DPRINT("%s() = NULL\n",__FUNCTION__
);
139 PUNICODE_STRING FullPath
,
146 DPRINT("ObpParseDirectory(Object %x, Path %x, *Path %S)\n",
153 return STATUS_UNSUCCESSFUL
;
156 end
= wcschr((*Path
)+1, '\\');
162 FoundObject
= ObpFindEntryDirectory(Object
, (*Path
)+1, 0);
164 if (FoundObject
== NULL
)
170 return STATUS_UNSUCCESSFUL
;
173 ObReferenceObjectByPointer(FoundObject
,
174 STANDARD_RIGHTS_REQUIRED
,
188 *NextObject
= FoundObject
;
190 return STATUS_SUCCESS
;
193 NTSTATUS
ObpCreateDirectory(PVOID ObjectBody
,
196 POBJECT_ATTRIBUTES ObjectAttributes
)
198 PDIRECTORY_OBJECT DirectoryObject
= (PDIRECTORY_OBJECT
)ObjectBody
;
200 DPRINT("ObpCreateDirectory(ObjectBody %x, Parent %x, RemainingPath %S)\n",
201 ObjectBody
, Parent
, RemainingPath
);
203 if (RemainingPath
!= NULL
&& wcschr(RemainingPath
+1, '\\') != NULL
)
205 return(STATUS_UNSUCCESSFUL
);
208 if (Parent
!= NULL
&& RemainingPath
!= NULL
)
210 ObAddEntryDirectory(Parent
, ObjectBody
, RemainingPath
+1);
212 InitializeListHead(&DirectoryObject
->head
);
213 KeInitializeSpinLock(&DirectoryObject
->Lock
);
214 return(STATUS_SUCCESS
);
219 * FUNCTION: Initialize the object manager namespace
222 ANSI_STRING AnsiString
;
224 ObDirectoryType
= ExAllocatePool(NonPagedPool
,sizeof(OBJECT_TYPE
));
226 ObDirectoryType
->TotalObjects
= 0;
227 ObDirectoryType
->TotalHandles
= 0;
228 ObDirectoryType
->MaxObjects
= ULONG_MAX
;
229 ObDirectoryType
->MaxHandles
= ULONG_MAX
;
230 ObDirectoryType
->PagedPoolCharge
= 0;
231 ObDirectoryType
->NonpagedPoolCharge
= sizeof(DIRECTORY_OBJECT
);
232 ObDirectoryType
->Dump
= NULL
;
233 ObDirectoryType
->Open
= NULL
;
234 ObDirectoryType
->Close
= NULL
;
235 ObDirectoryType
->Delete
= NULL
;
236 ObDirectoryType
->Parse
= ObpParseDirectory
;
237 ObDirectoryType
->Security
= NULL
;
238 ObDirectoryType
->QueryName
= NULL
;
239 ObDirectoryType
->OkayToClose
= NULL
;
240 ObDirectoryType
->Create
= ObpCreateDirectory
;
242 RtlInitAnsiString(&AnsiString
,"Directory");
243 RtlAnsiStringToUnicodeString(&ObDirectoryType
->TypeName
,
246 NameSpaceRoot
= ObCreateObject(NULL
,
247 STANDARD_RIGHTS_REQUIRED
,
252 VOID
ObRemoveEntry(POBJECT_HEADER Header
)
256 DPRINT("ObRemoveEntry(Header %x)\n",Header
);
258 KeAcquireSpinLock(&(Header
->Parent
->Lock
),&oldlvl
);
259 RemoveEntryList(&(Header
->Entry
));
260 KeReleaseSpinLock(&(Header
->Parent
->Lock
),oldlvl
);