Added some modifications for asyncronous i/o requests (for vfatfs).
[reactos.git] / reactos / ntoskrnl / io / dir.c
1 /* $Id: dir.c,v 1.11 2001/11/02 22:22:33 hbirr Exp $
2 *
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)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/io.h>
16
17 #define NDEBUG
18 #include <internal/debug.h>
19
20 /* FUNCTIONS *****************************************************************/
21
22
23
24 NTSTATUS
25 STDCALL
26 NtNotifyChangeDirectoryFile (
27 IN HANDLE FileHandle,
28 IN HANDLE Event OPTIONAL,
29 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
30 IN PVOID ApcContext OPTIONAL,
31 OUT PIO_STATUS_BLOCK IoStatusBlock,
32 OUT PVOID Buffer,
33 IN ULONG BufferSize,
34 IN ULONG CompletionFilter,
35 IN BOOLEAN WatchTree
36 )
37 {
38 UNIMPLEMENTED;
39 }
40
41
42 NTSTATUS
43 STDCALL
44 NtQueryDirectoryFile(
45 IN HANDLE FileHandle,
46 IN HANDLE PEvent OPTIONAL,
47 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
48 IN PVOID ApcContext OPTIONAL,
49 OUT PIO_STATUS_BLOCK IoStatusBlock,
50 OUT PVOID FileInformation,
51 IN ULONG Length,
52 IN FILE_INFORMATION_CLASS FileInformationClass,
53 IN BOOLEAN ReturnSingleEntry,
54 IN PUNICODE_STRING FileName OPTIONAL,
55 IN BOOLEAN RestartScan
56 )
57 /*
58 * FUNCTION: Queries a directory file.
59 * ARGUMENTS:
60 * FileHandle = Handle to a directory file
61 * EventHandle = Handle to the event signaled on completion
62 * ApcRoutine = Asynchroneous procedure callback, called on completion
63 * ApcContext = Argument to the apc.
64 * IoStatusBlock = Caller supplies storage for extended status information.
65 * FileInformation = Caller supplies storage for the resulting information.
66 *
67 * FileNameInformation FILE_NAMES_INFORMATION
68 * FileDirectoryInformation FILE_DIRECTORY_INFORMATION
69 * FileFullDirectoryInformation FILE_FULL_DIRECTORY_INFORMATION
70 * FileBothDirectoryInformation FILE_BOTH_DIR_INFORMATION
71 *
72 * Length = Size of the storage supplied
73 * FileInformationClass = Indicates the type of information requested.
74 * ReturnSingleEntry = Specify true if caller only requests the first
75 * directory found.
76 * FileName = Initial directory name to query, that may contain wild
77 * cards.
78 * RestartScan = Number of times the action should be repeated
79 * RETURNS: Status [ STATUS_SUCCESS, STATUS_ACCESS_DENIED, STATUS_INSUFFICIENT_RESOURCES,
80 * STATUS_INVALID_PARAMETER, STATUS_INVALID_DEVICE_REQUEST, STATUS_BUFFER_OVERFLOW,
81 * STATUS_INVALID_INFO_CLASS, STATUS_NO_SUCH_FILE, STATUS_NO_MORE_FILES ]
82 */
83 {
84 PIRP Irp;
85 PDEVICE_OBJECT DeviceObject;
86 PFILE_OBJECT FileObject;
87 NTSTATUS Status;
88 KEVENT Event;
89 PIO_STACK_LOCATION IoStack;
90 IO_STATUS_BLOCK IoSB;
91
92 DPRINT("NtQueryDirectoryFile()\n");
93
94 Status = ObReferenceObjectByHandle(FileHandle,
95 FILE_LIST_DIRECTORY,
96 IoFileObjectType,
97 UserMode,
98 (PVOID *)&FileObject,
99 NULL);
100
101 if (Status != STATUS_SUCCESS)
102 {
103 ObDereferenceObject(FileObject);
104 return(Status);
105 }
106 KeInitializeEvent(&Event,NotificationEvent,FALSE);
107 DeviceObject = FileObject->DeviceObject;
108
109 Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
110 if (Irp==NULL)
111 {
112 ObDereferenceObject(FileObject);
113 return STATUS_UNSUCCESSFUL;
114 }
115
116
117 Irp->UserIosb = &IoSB;
118 Irp->UserEvent = &Event;
119 Irp->UserBuffer=FileInformation;
120
121 IoStack = IoGetNextIrpStackLocation(Irp);
122
123 IoStack->MajorFunction = IRP_MJ_DIRECTORY_CONTROL;
124 IoStack->MinorFunction = IRP_MN_QUERY_DIRECTORY;
125 IoStack->Flags = 0;
126 IoStack->Control = 0;
127 IoStack->DeviceObject = DeviceObject;
128 IoStack->FileObject = FileObject;
129
130 if (RestartScan)
131 {
132 IoStack->Flags = IoStack->Flags | SL_RESTART_SCAN;
133 }
134 if (ReturnSingleEntry)
135 {
136 IoStack->Flags = IoStack->Flags | SL_RETURN_SINGLE_ENTRY;
137 }
138 if (((PFILE_DIRECTORY_INFORMATION)FileInformation)->FileIndex != 0)
139 {
140 IoStack->Flags = IoStack->Flags | SL_INDEX_SPECIFIED;
141 }
142
143 IoStack->Parameters.QueryDirectory.FileInformationClass =
144 FileInformationClass;
145 IoStack->Parameters.QueryDirectory.FileName = FileName;
146 IoStack->Parameters.QueryDirectory.Length = Length;
147
148 Status = IoCallDriver(FileObject->DeviceObject,Irp);
149 if (Status==STATUS_PENDING && (FileObject->Flags & FO_SYNCHRONOUS_IO))
150 {
151 if (FileObject->Flags & FO_ALERTABLE_IO)
152 {
153 KeWaitForSingleObject(&Event,Executive,KernelMode,TRUE,NULL);
154 }
155 else
156 {
157 KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
158 }
159 Status = IoSB.Status;
160 }
161 if (IoStatusBlock)
162 {
163 *IoStatusBlock = IoSB;
164 }
165 return(Status);
166 }
167
168 NTSTATUS STDCALL NtQueryOleDirectoryFile(VOID)
169 {
170 UNIMPLEMENTED;
171 }
172
173
174 /* EOF */