3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/dir.c
6 * PURPOSE: Directory functions
7 * PROGRAMMER: David Welch (welch@mcmail.com)
12 /* INCLUDES *****************************************************************/
14 #include <ddk/ntddk.h>
15 #include <internal/io.h>
18 #include <internal/debug.h>
20 /* FUNCTIONS *****************************************************************/
27 NtNotifyChangeDirectoryFile (
29 IN HANDLE Event OPTIONAL,
30 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
31 IN PVOID ApcContext OPTIONAL,
32 OUT PIO_STATUS_BLOCK IoStatusBlock,
35 IN ULONG CompletionFilter,
42 #endif /* LIBCAPTIVE */
48 IN HANDLE PEvent OPTIONAL,
49 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
50 IN PVOID ApcContext OPTIONAL,
51 OUT PIO_STATUS_BLOCK IoStatusBlock,
52 OUT PVOID FileInformation,
54 IN FILE_INFORMATION_CLASS FileInformationClass,
55 IN BOOLEAN ReturnSingleEntry,
56 IN PUNICODE_STRING FileName OPTIONAL,
57 IN BOOLEAN RestartScan
60 * FUNCTION: Queries a directory file.
62 * FileHandle = Handle to a directory file
63 * EventHandle = Handle to the event signaled on completion
64 * ApcRoutine = Asynchroneous procedure callback, called on completion
65 * ApcContext = Argument to the apc.
66 * IoStatusBlock = Caller supplies storage for extended status information.
67 * FileInformation = Caller supplies storage for the resulting information.
69 * FileNameInformation FILE_NAMES_INFORMATION
70 * FileDirectoryInformation FILE_DIRECTORY_INFORMATION
71 * FileFullDirectoryInformation FILE_FULL_DIRECTORY_INFORMATION
72 * FileBothDirectoryInformation FILE_BOTH_DIR_INFORMATION
74 * Length = Size of the storage supplied
75 * FileInformationClass = Indicates the type of information requested.
76 * ReturnSingleEntry = Specify true if caller only requests the first
78 * FileName = Initial directory name to query, that may contain wild
80 * RestartScan = Number of times the action should be repeated
81 * RETURNS: Status [ STATUS_SUCCESS, STATUS_ACCESS_DENIED, STATUS_INSUFFICIENT_RESOURCES,
82 * STATUS_INVALID_PARAMETER, STATUS_INVALID_DEVICE_REQUEST, STATUS_BUFFER_OVERFLOW,
83 * STATUS_INVALID_INFO_CLASS, STATUS_NO_SUCH_FILE, STATUS_NO_MORE_FILES ]
87 PDEVICE_OBJECT DeviceObject;
88 PFILE_OBJECT FileObject;
90 PIO_STACK_LOCATION IoStack;
93 DPRINT("NtQueryDirectoryFile()\n");
95 Status = ObReferenceObjectByHandle(FileHandle,
102 if (Status != STATUS_SUCCESS)
104 ObDereferenceObject(FileObject);
107 DeviceObject = FileObject->DeviceObject;
109 Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
112 ObDereferenceObject(FileObject);
113 return STATUS_UNSUCCESSFUL;
117 Irp->UserIosb = &IoSB;
118 Irp->UserEvent = &FileObject->Event;
119 KeResetEvent( &FileObject->Event );
120 Irp->UserBuffer=FileInformation;
122 IoStack = IoGetNextIrpStackLocation(Irp);
124 IoStack->MajorFunction = IRP_MJ_DIRECTORY_CONTROL;
125 IoStack->MinorFunction = IRP_MN_QUERY_DIRECTORY;
127 IoStack->Control = 0;
128 IoStack->DeviceObject = DeviceObject;
129 IoStack->FileObject = FileObject;
133 IoStack->Flags = IoStack->Flags | SL_RESTART_SCAN;
135 if (ReturnSingleEntry)
137 IoStack->Flags = IoStack->Flags | SL_RETURN_SINGLE_ENTRY;
139 /* SL_INDEX_SPECIFIED may take precedense over SL_RESTART_SCAN
140 * and 'FileInformation' may not be valid if !RestartScan.
141 * ext2fsd.sys-V0.10A requires unspecified SL_INDEX_SPECIFIED
142 * as it would otherwise expect direct pointer to EXT2 directory data block
143 * which we have no information about. FIXME: Why W32 filesystems required
144 * SL_INDEX_SPECIFIED? Is it still valid?
148 switch (FileInformationClass) {
149 case FileIdBothDirectoryInformation:
150 IoStack->Parameters.QueryDirectory.FileIndex = ((FILE_ID_BOTH_DIR_INFORMATION *)FileInformation)->FileIndex;
152 case FileBothDirectoryInformation:
153 IoStack->Parameters.QueryDirectory.FileIndex = ((FILE_BOTH_DIR_INFORMATION *)FileInformation)->FileIndex;
155 default: KeBugCheck(0); /* FIXME: such 'FileInformationClass' NOT IMPLEMENTED YET */
157 if (IoStack->Parameters.QueryDirectory.FileIndex)
158 IoStack->Flags = IoStack->Flags | SL_INDEX_SPECIFIED;
161 IoStack->Parameters.QueryDirectory.FileInformationClass =
162 FileInformationClass;
163 IoStack->Parameters.QueryDirectory.FileName = FileName;
164 IoStack->Parameters.QueryDirectory.Length = Length;
166 Status = IoCallDriver(FileObject->DeviceObject,Irp);
167 if (Status==STATUS_PENDING && !(FileObject->Flags & FO_SYNCHRONOUS_IO))
169 if (FileObject->Flags & FO_ALERTABLE_IO)
171 KeWaitForSingleObject(&FileObject->Event,Executive,KernelMode,TRUE,NULL);
175 KeWaitForSingleObject(&FileObject->Event,Executive,KernelMode,FALSE,NULL);
177 Status = IoSB.Status;
181 *IoStatusBlock = IoSB;
188 NTSTATUS STDCALL NtQueryOleDirectoryFile(VOID)
193 #endif /* LIBCAPTIVE */