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
ObReferenceObjectByName(PUNICODE_STRING ObjectPath
,
32 PACCESS_STATE PassedAccessState
,
33 ACCESS_MASK DesiredAccess
,
34 POBJECT_TYPE ObjectType
,
35 KPROCESSOR_MODE AccessMode
,
41 OBJECT_ATTRIBUTES ObjectAttributes
;
43 InitializeObjectAttributes(&ObjectAttributes
,
48 ObFindObject(&ObjectAttributes
,
52 if (RemainingPath
!= NULL
||
56 return(STATUS_UNSUCCESSFUL
);
59 return(STATUS_SUCCESS
);
62 VOID
ObAddEntryDirectory(PDIRECTORY_OBJECT Parent
,
66 * FUNCTION: Add an entry to a namespace directory
68 * parent = directory to add in
69 * name = Name to give the entry
70 * Object = Header of the object to add the entry for
74 POBJECT_HEADER Header
= BODY_TO_HEADER(Object
);
76 RtlInitUnicodeString(&Header
->Name
, wcsdup(Name
));
77 Header
->Parent
= Parent
;
79 KeAcquireSpinLock(&Parent
->Lock
, &oldlvl
);
80 InsertTailList(&Parent
->head
, &Header
->Entry
);
81 KeReleaseSpinLock(&Parent
->Lock
, oldlvl
);
84 PVOID
ObpFindEntryDirectory(PDIRECTORY_OBJECT DirectoryObject
,
88 PLIST_ENTRY current
= DirectoryObject
->head
.Flink
;
89 POBJECT_HEADER current_obj
;
91 DPRINT("ObDirLookup(dir %x, name %w)\n",DirectoryObject
, Name
);
95 return(DirectoryObject
);
97 if (Name
[0]=='.' && Name
[1]==0)
99 return(DirectoryObject
);
101 if (Name
[0]=='.' && Name
[1]=='.' && Name
[2]==0)
103 return(BODY_TO_HEADER(DirectoryObject
)->Parent
);
105 while (current
!=(&(DirectoryObject
->head
)))
107 current_obj
= CONTAINING_RECORD(current
,OBJECT_HEADER
,Entry
);
108 DPRINT("Scanning %w %w\n",current_obj
->Name
.Buffer
, Name
);
109 if (Attributes
& OBJ_CASE_INSENSITIVE
)
111 if (wcsicmp(current_obj
->Name
.Buffer
, Name
)==0)
113 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
114 return(HEADER_TO_BODY(current_obj
));
119 if ( wcscmp(current_obj
->Name
.Buffer
, Name
)==0)
121 DPRINT("Found it %x\n",HEADER_TO_BODY(current_obj
));
122 return(HEADER_TO_BODY(current_obj
));
125 current
= current
->Flink
;
127 DPRINT("%s() = NULL\n",__FUNCTION__
);
132 PVOID
ObpParseDirectory(PVOID Object
, PWSTR
* Path
)
138 DPRINT("ObpParseDirectory(Object %x, Path %x, *Path %w)\n",
146 end
= wcschr((*Path
)+1, '\\');
152 FoundObject
= ObpFindEntryDirectory(Object
, (*Path
)+1, 0);
154 if (FoundObject
== NULL
)
163 ObReferenceObjectByPointer(FoundObject
,
164 STANDARD_RIGHTS_REQUIRED
,
181 NTSTATUS
ObpCreateDirectory(PVOID ObjectBody
,
184 POBJECT_ATTRIBUTES ObjectAttributes
)
186 PDIRECTORY_OBJECT DirectoryObject
= (PDIRECTORY_OBJECT
)ObjectBody
;
188 DPRINT("ObpCreateDirectory(ObjectBody %x, Parent %x, RemainingPath %w)\n",
189 ObjectBody
, Parent
, RemainingPath
);
191 if (RemainingPath
!= NULL
&& wcschr(RemainingPath
+1, '\\') != NULL
)
193 return(STATUS_UNSUCCESSFUL
);
196 if (Parent
!= NULL
&& RemainingPath
!= NULL
)
198 ObAddEntryDirectory(Parent
, ObjectBody
, RemainingPath
+1);
200 InitializeListHead(&DirectoryObject
->head
);
201 KeInitializeSpinLock(&DirectoryObject
->Lock
);
202 return(STATUS_SUCCESS
);
207 * FUNCTION: Initialize the object manager namespace
210 ANSI_STRING AnsiString
;
212 ObDirectoryType
= ExAllocatePool(NonPagedPool
,sizeof(OBJECT_TYPE
));
214 ObDirectoryType
->TotalObjects
= 0;
215 ObDirectoryType
->TotalHandles
= 0;
216 ObDirectoryType
->MaxObjects
= ULONG_MAX
;
217 ObDirectoryType
->MaxHandles
= ULONG_MAX
;
218 ObDirectoryType
->PagedPoolCharge
= 0;
219 ObDirectoryType
->NonpagedPoolCharge
= sizeof(DIRECTORY_OBJECT
);
220 ObDirectoryType
->Dump
= NULL
;
221 ObDirectoryType
->Open
= NULL
;
222 ObDirectoryType
->Close
= NULL
;
223 ObDirectoryType
->Delete
= NULL
;
224 ObDirectoryType
->Parse
= ObpParseDirectory
;
225 ObDirectoryType
->Security
= NULL
;
226 ObDirectoryType
->QueryName
= NULL
;
227 ObDirectoryType
->OkayToClose
= NULL
;
228 ObDirectoryType
->Create
= ObpCreateDirectory
;
230 RtlInitAnsiString(&AnsiString
,"Directory");
231 RtlAnsiStringToUnicodeString(&ObDirectoryType
->TypeName
,
234 NameSpaceRoot
= ObCreateObject(NULL
,
235 STANDARD_RIGHTS_REQUIRED
,
240 VOID
ObRemoveEntry(POBJECT_HEADER Header
)
244 DPRINT("ObRemoveEntry(Header %x)\n",Header
);
246 KeAcquireSpinLock(&(Header
->Parent
->Lock
),&oldlvl
);
247 RemoveEntryList(&(Header
->Entry
));
248 KeReleaseSpinLock(&(Header
->Parent
->Lock
),oldlvl
);