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 ***************************************************************/
15 #include <ddk/ntddk.h>
16 #include <internal/ob.h>
17 #include <internal/io.h>
18 #include <internal/string.h>
21 #include <internal/debug.h>
23 /* GLOBALS ****************************************************************/
25 POBJECT_TYPE ObDirectoryType
= NULL
;
27 PDIRECTORY_OBJECT NameSpaceRoot
= NULL
;
29 /* FUNCTIONS **************************************************************/
31 NTSTATUS STDCALL
ObReferenceObjectByName(PUNICODE_STRING ObjectPath
,
33 PACCESS_STATE PassedAccessState
,
34 ACCESS_MASK DesiredAccess
,
35 POBJECT_TYPE ObjectType
,
36 KPROCESSOR_MODE AccessMode
,
41 UNICODE_STRING RemainingPath
;
42 // PWSTR RemainingPath;
43 OBJECT_ATTRIBUTES ObjectAttributes
;
45 InitializeObjectAttributes(&ObjectAttributes
,
50 ObFindObject(&ObjectAttributes
,
54 if (RemainingPath
.Buffer
!= NULL
||
58 RtlFreeUnicodeString (&RemainingPath
);
59 return(STATUS_UNSUCCESSFUL
);
62 RtlFreeUnicodeString (&RemainingPath
);
63 return(STATUS_SUCCESS
);
66 VOID
ObAddEntryDirectory(PDIRECTORY_OBJECT Parent
,
70 * FUNCTION: Add an entry to a namespace directory
72 * parent = directory to add in
73 * name = Name to give the entry
74 * Object = Header of the object to add the entry for
78 POBJECT_HEADER Header
= BODY_TO_HEADER(Object
);
80 RtlInitUnicodeString(&Header
->Name
, wcsdup(Name
));
81 Header
->Parent
= Parent
;
83 KeAcquireSpinLock(&Parent
->Lock
, &oldlvl
);
84 InsertTailList(&Parent
->head
, &Header
->Entry
);
85 KeReleaseSpinLock(&Parent
->Lock
, oldlvl
);
88 PVOID
ObpFindEntryDirectory(PDIRECTORY_OBJECT DirectoryObject
,
92 PLIST_ENTRY current
= DirectoryObject
->head
.Flink
;
93 POBJECT_HEADER current_obj
;
95 DPRINT("ObDirLookup(dir %x, name %S)\n",DirectoryObject
, Name
);
99 return(DirectoryObject
);
101 if (Name
[0]=='.' && Name
[1]==0)
103 return(DirectoryObject
);
105 if (Name
[0]=='.' && Name
[1]=='.' && Name
[2]==0)
107 return(BODY_TO_HEADER(DirectoryObject
)->Parent
);
109 while (current
!=(&(DirectoryObject
->head
)))
111 current_obj
= CONTAINING_RECORD(current
,OBJECT_HEADER
,Entry
);
112 DPRINT("Scanning %S %S\n",current_obj
->Name
.Buffer
, Name
);
113 if (Attributes
& OBJ_CASE_INSENSITIVE
)
115 if (_wcsicmp(current_obj
->Name
.Buffer
, Name
)==0)
117 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
118 return(HEADER_TO_BODY(current_obj
));
123 if ( wcscmp(current_obj
->Name
.Buffer
, Name
)==0)
125 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
126 return(HEADER_TO_BODY(current_obj
));
129 current
= current
->Flink
;
131 DPRINT("%s() = NULL\n",__FUNCTION__
);
140 PUNICODE_STRING FullPath
,
147 DPRINT("ObpParseDirectory(Object %x, Path %x, *Path %S)\n",
154 return STATUS_UNSUCCESSFUL
;
157 end
= wcschr((*Path
)+1, '\\');
163 FoundObject
= ObpFindEntryDirectory(Object
, (*Path
)+1, 0);
165 if (FoundObject
== NULL
)
171 return STATUS_UNSUCCESSFUL
;
174 ObReferenceObjectByPointer(FoundObject
,
175 STANDARD_RIGHTS_REQUIRED
,
189 *NextObject
= FoundObject
;
191 return STATUS_SUCCESS
;
194 NTSTATUS
ObpCreateDirectory(PVOID ObjectBody
,
197 POBJECT_ATTRIBUTES ObjectAttributes
)
199 PDIRECTORY_OBJECT DirectoryObject
= (PDIRECTORY_OBJECT
)ObjectBody
;
201 DPRINT("ObpCreateDirectory(ObjectBody %x, Parent %x, RemainingPath %S)\n",
202 ObjectBody
, Parent
, RemainingPath
);
204 if (RemainingPath
!= NULL
&& wcschr(RemainingPath
+1, '\\') != NULL
)
206 return(STATUS_UNSUCCESSFUL
);
209 if (Parent
!= NULL
&& RemainingPath
!= NULL
)
211 ObAddEntryDirectory(Parent
, ObjectBody
, RemainingPath
+1);
213 InitializeListHead(&DirectoryObject
->head
);
214 KeInitializeSpinLock(&DirectoryObject
->Lock
);
215 return(STATUS_SUCCESS
);
220 * FUNCTION: Initialize the object manager namespace
223 ANSI_STRING AnsiString
;
225 ObDirectoryType
= ExAllocatePool(NonPagedPool
,sizeof(OBJECT_TYPE
));
227 ObDirectoryType
->TotalObjects
= 0;
228 ObDirectoryType
->TotalHandles
= 0;
229 ObDirectoryType
->MaxObjects
= ULONG_MAX
;
230 ObDirectoryType
->MaxHandles
= ULONG_MAX
;
231 ObDirectoryType
->PagedPoolCharge
= 0;
232 ObDirectoryType
->NonpagedPoolCharge
= sizeof(DIRECTORY_OBJECT
);
233 ObDirectoryType
->Dump
= NULL
;
234 ObDirectoryType
->Open
= NULL
;
235 ObDirectoryType
->Close
= NULL
;
236 ObDirectoryType
->Delete
= NULL
;
237 ObDirectoryType
->Parse
= ObpParseDirectory
;
238 ObDirectoryType
->Security
= NULL
;
239 ObDirectoryType
->QueryName
= NULL
;
240 ObDirectoryType
->OkayToClose
= NULL
;
241 ObDirectoryType
->Create
= ObpCreateDirectory
;
243 RtlInitAnsiString(&AnsiString
,"Directory");
244 RtlAnsiStringToUnicodeString(&ObDirectoryType
->TypeName
,
247 NameSpaceRoot
= ObCreateObject(NULL
,
248 STANDARD_RIGHTS_REQUIRED
,
253 VOID
ObRemoveEntry(POBJECT_HEADER Header
)
257 DPRINT("ObRemoveEntry(Header %x)\n",Header
);
259 KeAcquireSpinLock(&(Header
->Parent
->Lock
),&oldlvl
);
260 RemoveEntryList(&(Header
->Entry
));
261 KeReleaseSpinLock(&(Header
->Parent
->Lock
),oldlvl
);