2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ob/dirobj.c
5 * PURPOSE: Interface functions to directory object
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>
23 /* FUNCTIONS **************************************************************/
25 NTSTATUS
NtOpenDirectoryObject(PHANDLE DirectoryHandle
,
26 ACCESS_MASK DesiredAccess
,
27 POBJECT_ATTRIBUTES ObjectAttributes
)
29 return(ZwOpenDirectoryObject(DirectoryHandle
,
34 NTSTATUS
ZwOpenDirectoryObject(PHANDLE DirectoryHandle
,
35 ACCESS_MASK DesiredAccess
,
36 POBJECT_ATTRIBUTES ObjectAttributes
)
38 * FUNCTION: Opens a namespace directory object
40 * DirectoryHandle (OUT) = Variable which receives the directory handle
41 * DesiredAccess = Desired access to the directory
42 * ObjectAttributes = Structure describing the directory
52 Status
= ObReferenceObjectByName(ObjectAttributes
->ObjectName
,
53 ObjectAttributes
->Attributes
,
60 if (!NT_SUCCESS(Status
))
65 Status
= ObCreateHandle(PsGetCurrentProcess(),
70 return(STATUS_SUCCESS
);
73 NTSTATUS
NtQueryDirectoryObject(IN HANDLE DirObjHandle
,
74 OUT POBJDIR_INFORMATION DirObjInformation
,
75 IN ULONG BufferLength
,
76 IN BOOLEAN GetNextIndex
,
77 IN BOOLEAN IgnoreInputIndex
,
78 IN OUT PULONG ObjectIndex
,
79 OUT PULONG DataWritten OPTIONAL
)
81 return(ZwQueryDirectoryObject(DirObjHandle
,
90 NTSTATUS
ZwQueryDirectoryObject(IN HANDLE DirObjHandle
,
91 OUT POBJDIR_INFORMATION DirObjInformation
,
92 IN ULONG BufferLength
,
93 IN BOOLEAN GetNextIndex
,
94 IN BOOLEAN IgnoreInputIndex
,
95 IN OUT PULONG ObjectIndex
,
96 OUT PULONG DataWritten OPTIONAL
)
98 * FUNCTION: Reads information from a namespace directory
100 * DirObjInformation (OUT) = Buffer to hold the data read
101 * BufferLength = Size of the buffer in bytes
102 * GetNextIndex = If TRUE then set ObjectIndex to the index of the
104 * If FALSE then set ObjectIndex to the number of
105 * objects in the directory
106 * IgnoreInputIndex = If TRUE start reading at index 0
107 * If FALSE start reading at the index specified
109 * ObjectIndex = Zero based index into the directory, interpretation
110 * depends on IgnoreInputIndex and GetNextIndex
111 * DataWritten (OUT) = Caller supplied storage for the number of bytes
116 PDIRECTORY_OBJECT dir
= NULL
;
118 PLIST_ENTRY current_entry
;
119 POBJECT_HEADER current
;
124 DPRINT("ZwQueryDirectoryObject(DirObjHandle %x)\n",DirObjHandle
);
125 DPRINT("dir %x namespc_root %x\n",dir
,HEADER_TO_BODY(&(namespc_root
.hdr
)));
127 // assert_irql(PASSIVE_LEVEL);
129 Status
= ObReferenceObjectByHandle(DirObjHandle
,
135 if (Status
!= STATUS_SUCCESS
)
140 EntriesToRead
= BufferLength
/ sizeof(OBJDIR_INFORMATION
);
143 DPRINT("EntriesToRead %d\n",EntriesToRead
);
145 current_entry
= dir
->head
.Flink
;
148 * Optionally, skip over some entries at the start of the directory
150 if (!IgnoreInputIndex
)
154 EntriesToSkip
= *ObjectIndex
;
155 while ( i
<EntriesToSkip
&& current_entry
!=NULL
)
157 current_entry
= current_entry
->Flink
;
161 DPRINT("DirObjInformation %x\n",DirObjInformation
);
164 * Read the maximum entries possible into the buffer
166 while ( i
<EntriesToRead
&& current_entry
!=(&(dir
->head
)))
168 current
= CONTAINING_RECORD(current_entry
,OBJECT_HEADER
,Entry
);
169 DPRINT("Scanning %w\n",current
->Name
.Buffer
);
170 DirObjInformation
[i
].ObjectName
.Buffer
=
171 ExAllocatePool(NonPagedPool
,(current
->Name
.Length
+1)*2);
172 DirObjInformation
[i
].ObjectName
.Length
= current
->Name
.Length
;
173 DirObjInformation
[i
].ObjectName
.MaximumLength
= current
->Name
.Length
;
174 DPRINT("DirObjInformation[i].ObjectName.Buffer %x\n",
175 DirObjInformation
[i
].ObjectName
.Buffer
);
176 RtlCopyUnicodeString(&DirObjInformation
[i
].ObjectName
,
179 current_entry
= current_entry
->Flink
;
180 (*DataWritten
) = (*DataWritten
) + sizeof(OBJDIR_INFORMATION
);
186 * Optionally, count the number of entries in the directory
194 while ( current_entry
!=(&(dir
->head
)) )
196 current_entry
=current_entry
->Flink
;
201 return(STATUS_SUCCESS
);
205 NTSTATUS STDCALL
NtCreateDirectoryObject(PHANDLE DirectoryHandle
,
206 ACCESS_MASK DesiredAccess
,
207 POBJECT_ATTRIBUTES ObjectAttributes
)
209 return(ZwCreateDirectoryObject(DirectoryHandle
,
214 NTSTATUS STDCALL
ZwCreateDirectoryObject(PHANDLE DirectoryHandle
,
215 ACCESS_MASK DesiredAccess
,
216 POBJECT_ATTRIBUTES ObjectAttributes
)
218 * FUNCTION: Creates or opens a directory object (a container for other
221 * DirectoryHandle (OUT) = Caller supplied storage for the handle
223 * DesiredAccess = Access desired to the directory
224 * ObjectAttributes = Object attributes initialized with
225 * InitializeObjectAttributes
229 PDIRECTORY_OBJECT dir
;
231 dir
= ObCreateObject(DirectoryHandle
,
235 return(STATUS_SUCCESS
);
238 VOID
InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes
,
239 PUNICODE_STRING ObjectName
,
241 HANDLE RootDirectory
,
242 PSECURITY_DESCRIPTOR SecurityDescriptor
)
244 * FUNCTION: Sets up a parameter of type OBJECT_ATTRIBUTES for a
245 * subsequent call to ZwCreateXXX or ZwOpenXXX
247 * InitializedAttributes (OUT) = Caller supplied storage for the
249 * ObjectName = Full path name for object
250 * Attributes = Attributes for the object
251 * RootDirectory = Where the object should be placed or NULL
252 * SecurityDescriptor = Ignored
255 * Either ObjectName is a fully qualified pathname or a path relative
259 DPRINT("InitializeObjectAttributes(InitializedAttributes %x "
260 "ObjectName %x Attributes %x RootDirectory %x)\n",
261 InitializedAttributes
,ObjectName
,Attributes
,RootDirectory
);
262 InitializedAttributes
->Length
=sizeof(OBJECT_ATTRIBUTES
);
263 InitializedAttributes
->RootDirectory
=RootDirectory
;
264 InitializedAttributes
->ObjectName
=ObjectName
;
265 InitializedAttributes
->Attributes
=Attributes
;
266 InitializedAttributes
->SecurityDescriptor
=SecurityDescriptor
;
267 InitializedAttributes
->SecurityQualityOfService
=NULL
;