1 /* $Id: dirobj.c,v 1.5 1999/08/29 06:59:10 ea Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/ob/dirobj.c
6 * PURPOSE: Interface functions to directory object
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* 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>
24 /* FUNCTIONS **************************************************************/
27 /**********************************************************************
29 * NtOpenDirectoryObject
32 * Opens a namespace directory object.
35 * DirectoryHandle (OUT)
36 * Variable which receives the directory handle.
39 * Desired access to the directory.
42 * Structure describing the directory.
52 NtOpenDirectoryObject (
53 PHANDLE DirectoryHandle
,
54 ACCESS_MASK DesiredAccess
,
55 POBJECT_ATTRIBUTES ObjectAttributes
63 Status
= ObReferenceObjectByName(
64 ObjectAttributes
->ObjectName
,
65 ObjectAttributes
->Attributes
,
73 if (!NT_SUCCESS(Status
))
78 Status
= ObCreateHandle(
79 PsGetCurrentProcess(),
85 return STATUS_SUCCESS
;
89 /**********************************************************************
91 * NtQueryDirectoryObject
94 * Reads information from a namespace directory.
97 * DirObjInformation (OUT)
98 * Buffer to hold the data read.
101 * Size of the buffer in bytes.
104 * If TRUE then set ObjectIndex to the index of the
106 * If FALSE then set ObjectIndex to the number of
107 * objects in the directory.
110 * If TRUE start reading at index 0.
111 * If FALSE start reading at the index specified
115 * Zero based index into the directory, interpretation
116 * depends on IgnoreInputIndex and GetNextIndex.
119 * Caller supplied storage for the number of bytes
127 NtQueryDirectoryObject (
128 IN HANDLE DirObjHandle
,
129 OUT POBJDIR_INFORMATION DirObjInformation
,
130 IN ULONG BufferLength
,
131 IN BOOLEAN GetNextIndex
,
132 IN BOOLEAN IgnoreInputIndex
,
133 IN OUT PULONG ObjectIndex
,
134 OUT PULONG DataWritten OPTIONAL
137 PDIRECTORY_OBJECT dir
= NULL
;
139 PLIST_ENTRY current_entry
;
140 POBJECT_HEADER current
;
147 "NtQueryDirectoryObject(DirObjHandle %x)\n",
151 "dir %x namespc_root %x\n",
153 HEADER_TO_BODY(&(namespc_root
.hdr
))
156 // assert_irql(PASSIVE_LEVEL);
158 Status
= ObReferenceObjectByHandle(
166 if (Status
!= STATUS_SUCCESS
)
171 EntriesToRead
= BufferLength
/ sizeof (OBJDIR_INFORMATION
);
174 DPRINT("EntriesToRead %d\n",EntriesToRead
);
176 current_entry
= dir
->head
.Flink
;
179 * Optionally, skip over some entries at the start of the directory
181 if (!IgnoreInputIndex
)
185 EntriesToSkip
= *ObjectIndex
;
186 while ( (i
< EntriesToSkip
) && (current_entry
!= NULL
))
188 current_entry
= current_entry
->Flink
;
192 DPRINT("DirObjInformation %x\n",DirObjInformation
);
195 * Read the maximum entries possible into the buffer
197 while ( (i
< EntriesToRead
) && (current_entry
!= (&(dir
->head
))))
199 current
= CONTAINING_RECORD(
209 DirObjInformation
[i
].ObjectName
.Buffer
=
212 (current
->Name
.Length
+ 1) * 2
214 DirObjInformation
[i
].ObjectName
.Length
=
215 current
->Name
.Length
;
216 DirObjInformation
[i
].ObjectName
.MaximumLength
=
217 current
->Name
.Length
;
220 "DirObjInformation[i].ObjectName.Buffer %x\n",
221 DirObjInformation
[i
].ObjectName
.Buffer
224 RtlCopyUnicodeString(
225 & DirObjInformation
[i
].ObjectName
,
229 current_entry
= current_entry
->Flink
;
230 (*DataWritten
) = (*DataWritten
) + sizeof (OBJDIR_INFORMATION
);
237 * Optionally, count the number of entries in the directory
245 while ( current_entry
!= (&(dir
->head
)) )
247 current_entry
= current_entry
->Flink
;
252 return STATUS_SUCCESS
;
256 /**********************************************************************
257 * NAME (EXPORTED as Zw)
258 * NtCreateDirectoryObject
261 * Creates or opens a directory object (a container for other
265 * DirectoryHandle (OUT)
266 * Caller supplied storage for the handle of the
270 * Access desired to the directory.
273 * Object attributes initialized with
274 * InitializeObjectAttributes.
281 NtCreateDirectoryObject (
282 PHANDLE DirectoryHandle
,
283 ACCESS_MASK DesiredAccess
,
284 POBJECT_ATTRIBUTES ObjectAttributes
287 PDIRECTORY_OBJECT dir
;
289 dir
= ObCreateObject(
295 return STATUS_SUCCESS
;
299 /**********************************************************************
300 * NAME (MACRO in DDK)
301 * InitializeObjectAttributes
304 * Sets up a parameter of type OBJECT_ATTRIBUTES for a
305 * subsequent call to ZwCreateXXX or ZwOpenXXX.
308 * InitializedAttributes (OUT)
309 * Caller supplied storage for the object attributes.
312 * Full path name for object.
315 * Attributes for the object.
318 * Where the object should be placed or NULL.
324 * Either ObjectName is a fully qualified pathname or a path
325 * relative to RootDirectory.
328 InitializeObjectAttributes (
329 POBJECT_ATTRIBUTES InitializedAttributes
,
330 PUNICODE_STRING ObjectName
,
332 HANDLE RootDirectory
,
333 PSECURITY_DESCRIPTOR SecurityDescriptor
337 "InitializeObjectAttributes(InitializedAttributes %x "
338 "ObjectName %x Attributes %x RootDirectory %x)\n",
339 InitializedAttributes
,
344 InitializedAttributes
->Length
=
345 sizeof (OBJECT_ATTRIBUTES
);
346 InitializedAttributes
->RootDirectory
=
348 InitializedAttributes
->ObjectName
=
350 InitializedAttributes
->Attributes
=
352 InitializedAttributes
->SecurityDescriptor
=
354 InitializedAttributes
->SecurityQualityOfService
=