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 **************************************************************/
26 NtOpenDirectoryObject (
27 PHANDLE DirectoryHandle
,
28 ACCESS_MASK DesiredAccess
,
29 POBJECT_ATTRIBUTES ObjectAttributes
32 * FUNCTION: Opens a namespace directory object
34 * DirectoryHandle (OUT) = Variable which receives the directory handle
35 * DesiredAccess = Desired access to the directory
36 * ObjectAttributes = Structure describing the directory
46 Status
= ObReferenceObjectByName(ObjectAttributes
->ObjectName
,
47 ObjectAttributes
->Attributes
,
54 if (!NT_SUCCESS(Status
))
59 Status
= ObCreateHandle(PsGetCurrentProcess(),
64 return(STATUS_SUCCESS
);
69 NtQueryDirectoryObject (
70 IN HANDLE DirObjHandle
,
71 OUT POBJDIR_INFORMATION DirObjInformation
,
72 IN ULONG BufferLength
,
73 IN BOOLEAN GetNextIndex
,
74 IN BOOLEAN IgnoreInputIndex
,
75 IN OUT PULONG ObjectIndex
,
76 OUT PULONG DataWritten OPTIONAL
79 * FUNCTION: Reads information from a namespace directory
81 * DirObjInformation (OUT) = Buffer to hold the data read
82 * BufferLength = Size of the buffer in bytes
83 * GetNextIndex = If TRUE then set ObjectIndex to the index of the
85 * If FALSE then set ObjectIndex to the number of
86 * objects in the directory
87 * IgnoreInputIndex = If TRUE start reading at index 0
88 * If FALSE start reading at the index specified
90 * ObjectIndex = Zero based index into the directory, interpretation
91 * depends on IgnoreInputIndex and GetNextIndex
92 * DataWritten (OUT) = Caller supplied storage for the number of bytes
97 PDIRECTORY_OBJECT dir
= NULL
;
99 PLIST_ENTRY current_entry
;
100 POBJECT_HEADER current
;
105 DPRINT("NtQueryDirectoryObject(DirObjHandle %x)\n",DirObjHandle
);
106 DPRINT("dir %x namespc_root %x\n",dir
,HEADER_TO_BODY(&(namespc_root
.hdr
)));
108 // assert_irql(PASSIVE_LEVEL);
110 Status
= ObReferenceObjectByHandle(DirObjHandle
,
116 if (Status
!= STATUS_SUCCESS
)
121 EntriesToRead
= BufferLength
/ sizeof(OBJDIR_INFORMATION
);
124 DPRINT("EntriesToRead %d\n",EntriesToRead
);
126 current_entry
= dir
->head
.Flink
;
129 * Optionally, skip over some entries at the start of the directory
131 if (!IgnoreInputIndex
)
135 EntriesToSkip
= *ObjectIndex
;
136 while ( i
<EntriesToSkip
&& current_entry
!=NULL
)
138 current_entry
= current_entry
->Flink
;
142 DPRINT("DirObjInformation %x\n",DirObjInformation
);
145 * Read the maximum entries possible into the buffer
147 while ( i
<EntriesToRead
&& current_entry
!=(&(dir
->head
)))
149 current
= CONTAINING_RECORD(current_entry
,OBJECT_HEADER
,Entry
);
150 DPRINT("Scanning %w\n",current
->Name
.Buffer
);
151 DirObjInformation
[i
].ObjectName
.Buffer
=
152 ExAllocatePool(NonPagedPool
,(current
->Name
.Length
+1)*2);
153 DirObjInformation
[i
].ObjectName
.Length
= current
->Name
.Length
;
154 DirObjInformation
[i
].ObjectName
.MaximumLength
= current
->Name
.Length
;
155 DPRINT("DirObjInformation[i].ObjectName.Buffer %x\n",
156 DirObjInformation
[i
].ObjectName
.Buffer
);
157 RtlCopyUnicodeString(&DirObjInformation
[i
].ObjectName
,
160 current_entry
= current_entry
->Flink
;
161 (*DataWritten
) = (*DataWritten
) + sizeof(OBJDIR_INFORMATION
);
167 * Optionally, count the number of entries in the directory
175 while ( current_entry
!=(&(dir
->head
)) )
177 current_entry
=current_entry
->Flink
;
182 return(STATUS_SUCCESS
);
188 NtCreateDirectoryObject (
189 PHANDLE DirectoryHandle
,
190 ACCESS_MASK DesiredAccess
,
191 POBJECT_ATTRIBUTES ObjectAttributes
194 * FUNCTION: Creates or opens a directory object (a container for other
197 * DirectoryHandle (OUT) = Caller supplied storage for the handle
199 * DesiredAccess = Access desired to the directory
200 * ObjectAttributes = Object attributes initialized with
201 * InitializeObjectAttributes
205 PDIRECTORY_OBJECT dir
;
207 dir
= ObCreateObject(DirectoryHandle
,
211 return(STATUS_SUCCESS
);
214 VOID
InitializeObjectAttributes(POBJECT_ATTRIBUTES InitializedAttributes
,
215 PUNICODE_STRING ObjectName
,
217 HANDLE RootDirectory
,
218 PSECURITY_DESCRIPTOR SecurityDescriptor
)
220 * FUNCTION: Sets up a parameter of type OBJECT_ATTRIBUTES for a
221 * subsequent call to ZwCreateXXX or ZwOpenXXX
223 * InitializedAttributes (OUT) = Caller supplied storage for the
225 * ObjectName = Full path name for object
226 * Attributes = Attributes for the object
227 * RootDirectory = Where the object should be placed or NULL
228 * SecurityDescriptor = Ignored
231 * Either ObjectName is a fully qualified pathname or a path relative
235 DPRINT("InitializeObjectAttributes(InitializedAttributes %x "
236 "ObjectName %x Attributes %x RootDirectory %x)\n",
237 InitializedAttributes
,ObjectName
,Attributes
,RootDirectory
);
238 InitializedAttributes
->Length
=sizeof(OBJECT_ATTRIBUTES
);
239 InitializedAttributes
->RootDirectory
=RootDirectory
;
240 InitializedAttributes
->ObjectName
=ObjectName
;
241 InitializedAttributes
->Attributes
=Attributes
;
242 InitializedAttributes
->SecurityDescriptor
=SecurityDescriptor
;
243 InitializedAttributes
->SecurityQualityOfService
=NULL
;