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>
19 #include <internal/debug.h>
21 /* GLOBALS ****************************************************************/
23 POBJECT_TYPE ObDirectoryType
= NULL
;
25 PDIRECTORY_OBJECT NameSpaceRoot
= NULL
;
27 /* FUNCTIONS **************************************************************/
29 NTSTATUS STDCALL
ObReferenceObjectByName(PUNICODE_STRING ObjectPath
,
31 PACCESS_STATE PassedAccessState
,
32 ACCESS_MASK DesiredAccess
,
33 POBJECT_TYPE ObjectType
,
34 KPROCESSOR_MODE AccessMode
,
39 UNICODE_STRING RemainingPath
;
40 OBJECT_ATTRIBUTES ObjectAttributes
;
43 InitializeObjectAttributes(&ObjectAttributes
,
48 Status
= ObFindObject(&ObjectAttributes
,
52 if (!NT_SUCCESS(Status
))
54 return(STATUS_UNSUCCESSFUL
);
57 if (RemainingPath
.Buffer
!= NULL
||
61 RtlFreeUnicodeString (&RemainingPath
);
62 return(STATUS_UNSUCCESSFUL
);
65 RtlFreeUnicodeString (&RemainingPath
);
66 return(STATUS_SUCCESS
);
69 VOID STDCALL
ObAddEntryDirectory(PDIRECTORY_OBJECT Parent
,
73 * FUNCTION: Add an entry to a namespace directory
75 * parent = directory to add in
76 * name = Name to give the entry
77 * Object = Header of the object to add the entry for
81 POBJECT_HEADER Header
= BODY_TO_HEADER(Object
);
83 RtlCreateUnicodeString(&Header
->Name
, Name
);
84 Header
->Parent
= Parent
;
86 KeAcquireSpinLock(&Parent
->Lock
, &oldlvl
);
87 InsertTailList(&Parent
->head
, &Header
->Entry
);
88 KeReleaseSpinLock(&Parent
->Lock
, oldlvl
);
91 PVOID
ObpFindEntryDirectory(PDIRECTORY_OBJECT DirectoryObject
,
95 PLIST_ENTRY current
= DirectoryObject
->head
.Flink
;
96 POBJECT_HEADER current_obj
;
98 DPRINT("ObDirLookup(dir %x, name %S)\n",DirectoryObject
, Name
);
102 return(DirectoryObject
);
104 if (Name
[0]=='.' && Name
[1]==0)
106 return(DirectoryObject
);
108 if (Name
[0]=='.' && Name
[1]=='.' && Name
[2]==0)
110 return(BODY_TO_HEADER(DirectoryObject
)->Parent
);
112 while (current
!=(&(DirectoryObject
->head
)))
114 current_obj
= CONTAINING_RECORD(current
,OBJECT_HEADER
,Entry
);
115 DPRINT("Scanning %S %S\n",current_obj
->Name
.Buffer
, Name
);
116 if (Attributes
& OBJ_CASE_INSENSITIVE
)
118 if (_wcsicmp(current_obj
->Name
.Buffer
, Name
)==0)
120 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
121 return(HEADER_TO_BODY(current_obj
));
126 if ( wcscmp(current_obj
->Name
.Buffer
, Name
)==0)
128 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
129 return(HEADER_TO_BODY(current_obj
));
132 current
= current
->Flink
;
134 DPRINT("%s() = NULL\n",__FUNCTION__
);
143 PUNICODE_STRING FullPath
,
145 POBJECT_TYPE ObjectType
151 DPRINT("ObpParseDirectory(Object %x, Path %x, *Path %S)\n",
158 return STATUS_UNSUCCESSFUL
;
161 end
= wcschr((*Path
)+1, '\\');
167 FoundObject
= ObpFindEntryDirectory(Object
, (*Path
)+1, 0);
169 if (FoundObject
== NULL
)
175 return STATUS_UNSUCCESSFUL
;
178 ObReferenceObjectByPointer(FoundObject
,
179 STANDARD_RIGHTS_REQUIRED
,
193 *NextObject
= FoundObject
;
195 return STATUS_SUCCESS
;
198 NTSTATUS
ObpCreateDirectory(PVOID ObjectBody
,
201 POBJECT_ATTRIBUTES ObjectAttributes
)
203 PDIRECTORY_OBJECT DirectoryObject
= (PDIRECTORY_OBJECT
)ObjectBody
;
205 DPRINT("ObpCreateDirectory(ObjectBody %x, Parent %x, RemainingPath %S)\n",
206 ObjectBody
, Parent
, RemainingPath
);
208 if (RemainingPath
!= NULL
&& wcschr(RemainingPath
+1, '\\') != NULL
)
210 return(STATUS_UNSUCCESSFUL
);
213 if (Parent
!= NULL
&& RemainingPath
!= NULL
)
215 ObAddEntryDirectory(Parent
, ObjectBody
, RemainingPath
+1);
217 InitializeListHead(&DirectoryObject
->head
);
218 KeInitializeSpinLock(&DirectoryObject
->Lock
);
219 return(STATUS_SUCCESS
);
224 * FUNCTION: Initialize the object manager namespace
227 ANSI_STRING AnsiString
;
229 ObDirectoryType
= ExAllocatePool(NonPagedPool
,sizeof(OBJECT_TYPE
));
231 ObDirectoryType
->TotalObjects
= 0;
232 ObDirectoryType
->TotalHandles
= 0;
233 ObDirectoryType
->MaxObjects
= ULONG_MAX
;
234 ObDirectoryType
->MaxHandles
= ULONG_MAX
;
235 ObDirectoryType
->PagedPoolCharge
= 0;
236 ObDirectoryType
->NonpagedPoolCharge
= sizeof(DIRECTORY_OBJECT
);
237 ObDirectoryType
->Dump
= NULL
;
238 ObDirectoryType
->Open
= NULL
;
239 ObDirectoryType
->Close
= NULL
;
240 ObDirectoryType
->Delete
= NULL
;
241 ObDirectoryType
->Parse
= ObpParseDirectory
;
242 ObDirectoryType
->Security
= NULL
;
243 ObDirectoryType
->QueryName
= NULL
;
244 ObDirectoryType
->OkayToClose
= NULL
;
245 ObDirectoryType
->Create
= ObpCreateDirectory
;
247 RtlInitAnsiString(&AnsiString
,"Directory");
248 RtlAnsiStringToUnicodeString(&ObDirectoryType
->TypeName
,
251 NameSpaceRoot
= ObCreateObject(NULL
,
252 STANDARD_RIGHTS_REQUIRED
,
257 VOID
ObRemoveEntry(POBJECT_HEADER Header
)
261 DPRINT("ObRemoveEntry(Header %x)\n",Header
);
263 KeAcquireSpinLock(&(Header
->Parent
->Lock
),&oldlvl
);
264 RemoveEntryList(&(Header
->Entry
));
265 KeReleaseSpinLock(&(Header
->Parent
->Lock
),oldlvl
);