- Sync up Mm interface with WinLdr branch (introduce the concept of a memory type...
[reactos.git] / reactos / drivers / filesystems / npfs / finfo.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/fs/np/finfo.c
5 * PURPOSE: Named pipe filesystem
6 * PROGRAMMER: Eric Kohl
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "npfs.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS *****************************************************************/
17
18 static
19 NTSTATUS
20 NpfsSetPipeInformation(PDEVICE_OBJECT DeviceObject,
21 PNPFS_CCB Ccb,
22 PFILE_PIPE_INFORMATION Info,
23 PULONG BufferLength)
24 {
25 PNPFS_FCB Fcb;
26 PFILE_PIPE_INFORMATION Request;
27 DPRINT("NpfsSetPipeInformation()\n");
28
29 /* Get the Pipe and data */
30 Fcb = Ccb->Fcb;
31 Request = (PFILE_PIPE_INFORMATION)Info;
32
33 /* Set Pipe Data */
34 Fcb->ReadMode = Request->ReadMode;
35 Fcb->CompletionMode = Request->CompletionMode;
36
37 /* Return Success */
38 return STATUS_SUCCESS;
39 }
40
41 static
42 NTSTATUS
43 NpfsSetPipeRemoteInformation(PDEVICE_OBJECT DeviceObject,
44 PNPFS_CCB Ccb,
45 PFILE_PIPE_INFORMATION Info,
46 PULONG BufferLength)
47 {
48 PNPFS_FCB Fcb;
49 PFILE_PIPE_REMOTE_INFORMATION Request;
50 DPRINT("NpfsSetPipeRemoteInformation()\n");
51
52 /* Get the Pipe and data */
53 Fcb = Ccb->Fcb;
54 Request = (PFILE_PIPE_REMOTE_INFORMATION)Info;
55
56 /* Set the Settings */
57 Fcb->TimeOut = Request->CollectDataTime;
58 Fcb->InboundQuota = Request->MaximumCollectionCount;
59
60 /* Return Success */
61 return STATUS_SUCCESS;
62 }
63
64 static
65 NTSTATUS
66 NpfsQueryPipeInformation(PDEVICE_OBJECT DeviceObject,
67 PNPFS_CCB Ccb,
68 PFILE_PIPE_INFORMATION Info,
69 PULONG BufferLength)
70 {
71 PNPFS_FCB Fcb;
72 DPRINT("NpfsQueryPipeInformation()\n");
73
74 /* Get the Pipe */
75 Fcb = Ccb->Fcb;
76
77 /* Clear Info */
78 RtlZeroMemory(Info, sizeof(FILE_PIPE_INFORMATION));
79
80 /* Return Info */
81 Info->CompletionMode = Fcb->CompletionMode;
82 Info->ReadMode = Fcb->ReadMode;
83
84 /* Return success */
85 *BufferLength -= sizeof(FILE_PIPE_INFORMATION);
86 return STATUS_SUCCESS;
87 }
88
89 static
90 NTSTATUS
91 NpfsQueryPipeRemoteInformation(PDEVICE_OBJECT DeviceObject,
92 PNPFS_CCB Ccb,
93 PFILE_PIPE_REMOTE_INFORMATION Info,
94 PULONG BufferLength)
95 {
96 PNPFS_FCB Fcb;
97 DPRINT("NpfsQueryPipeRemoteInformation()\n");
98
99 /* Get the Pipe */
100 Fcb = Ccb->Fcb;
101
102 /* Clear Info */
103 RtlZeroMemory(Info, sizeof(FILE_PIPE_REMOTE_INFORMATION));
104
105 /* Return Info */
106 Info->MaximumCollectionCount = Fcb->InboundQuota;
107 Info->CollectDataTime = Fcb->TimeOut;
108
109 /* Return success */
110 *BufferLength -= sizeof(FILE_PIPE_REMOTE_INFORMATION);
111 return STATUS_SUCCESS;
112 }
113
114
115 static NTSTATUS
116 NpfsQueryLocalPipeInformation(PDEVICE_OBJECT DeviceObject,
117 PNPFS_CCB Ccb,
118 PFILE_PIPE_LOCAL_INFORMATION Info,
119 PULONG BufferLength)
120 {
121 PNPFS_FCB Fcb;
122
123 DPRINT("NpfsQueryLocalPipeInformation()\n");
124
125 Fcb = Ccb->Fcb;
126
127 RtlZeroMemory(Info,
128 sizeof(FILE_PIPE_LOCAL_INFORMATION));
129
130 Info->NamedPipeType = Fcb->PipeType;
131 Info->NamedPipeConfiguration = Fcb->PipeConfiguration;
132 Info->MaximumInstances = Fcb->MaximumInstances;
133 Info->CurrentInstances = Fcb->CurrentInstances;
134 Info->InboundQuota = Fcb->InboundQuota;
135 Info->OutboundQuota = Fcb->OutboundQuota;
136 Info->NamedPipeState = Ccb->PipeState;
137 Info->NamedPipeEnd = Ccb->PipeEnd;
138
139 if (Ccb->PipeEnd == FILE_PIPE_SERVER_END)
140 {
141 Info->ReadDataAvailable = Ccb->ReadDataAvailable;
142 Info->WriteQuotaAvailable = Ccb->WriteQuotaAvailable;
143 }
144 else if (Ccb->OtherSide != NULL)
145 {
146 Info->ReadDataAvailable = Ccb->OtherSide->ReadDataAvailable;
147 Info->WriteQuotaAvailable = Ccb->OtherSide->WriteQuotaAvailable;
148 }
149
150 *BufferLength -= sizeof(FILE_PIPE_LOCAL_INFORMATION);
151 return STATUS_SUCCESS;
152 }
153
154
155 NTSTATUS STDCALL
156 NpfsQueryInformation(PDEVICE_OBJECT DeviceObject,
157 PIRP Irp)
158 {
159 PIO_STACK_LOCATION IoStack;
160 FILE_INFORMATION_CLASS FileInformationClass;
161 PFILE_OBJECT FileObject;
162 PNPFS_DEVICE_EXTENSION DeviceExtension;
163 PNPFS_FCB Fcb;
164 PNPFS_CCB Ccb;
165 PVOID SystemBuffer;
166 ULONG BufferLength;
167 NTSTATUS Status;
168
169 DPRINT("NpfsQueryInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
170
171 IoStack = IoGetCurrentIrpStackLocation (Irp);
172 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
173 DeviceExtension = DeviceObject->DeviceExtension;
174 FileObject = IoStack->FileObject;
175 Ccb = (PNPFS_CCB)FileObject->FsContext2;
176 Fcb = Ccb->Fcb;
177
178 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
179 BufferLength = IoStack->Parameters.QueryFile.Length;
180
181 DPRINT("Pipe name: %wZ\n", &Fcb->PipeName);
182 DPRINT("FileInformationClass %d\n", FileInformationClass);
183 DPRINT("SystemBuffer %p\n", SystemBuffer);
184 DPRINT("BufferLength %lu\n", BufferLength);
185
186 switch (FileInformationClass)
187 {
188 case FilePipeInformation:
189 Status = NpfsQueryPipeInformation(DeviceObject,
190 Ccb,
191 SystemBuffer,
192 &BufferLength);
193 break;
194
195 case FilePipeLocalInformation:
196 Status = NpfsQueryLocalPipeInformation(DeviceObject,
197 Ccb,
198 SystemBuffer,
199 &BufferLength);
200 break;
201
202 case FilePipeRemoteInformation:
203 Status = NpfsQueryPipeRemoteInformation(DeviceObject,
204 Ccb,
205 SystemBuffer,
206 &BufferLength);
207 break;
208
209 default:
210 Status = STATUS_NOT_SUPPORTED;
211 }
212
213 Irp->IoStatus.Status = Status;
214 if (NT_SUCCESS(Status))
215 Irp->IoStatus.Information =
216 IoStack->Parameters.QueryFile.Length - BufferLength;
217 else
218 Irp->IoStatus.Information = 0;
219 IoCompleteRequest (Irp, IO_NO_INCREMENT);
220
221 return Status;
222 }
223
224
225 NTSTATUS STDCALL
226 NpfsSetInformation(PDEVICE_OBJECT DeviceObject,
227 PIRP Irp)
228 {
229 PIO_STACK_LOCATION IoStack;
230 FILE_INFORMATION_CLASS FileInformationClass;
231 PFILE_OBJECT FileObject;
232 PNPFS_FCB Fcb;
233 PNPFS_CCB Ccb;
234 PVOID SystemBuffer;
235 ULONG BufferLength;
236 NTSTATUS Status;
237
238 DPRINT("NpfsSetInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
239
240 IoStack = IoGetCurrentIrpStackLocation (Irp);
241 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
242 FileObject = IoStack->FileObject;
243 Ccb = (PNPFS_CCB)FileObject->FsContext2;
244 Fcb = Ccb->Fcb;
245
246 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
247 BufferLength = IoStack->Parameters.QueryFile.Length;
248
249 DPRINT("Pipe name: %wZ\n", &Fcb->PipeName);
250 DPRINT("FileInformationClass %d\n", FileInformationClass);
251 DPRINT("SystemBuffer %p\n", SystemBuffer);
252 DPRINT("BufferLength %lu\n", BufferLength);
253
254 switch (FileInformationClass)
255 {
256 case FilePipeInformation:
257 /* Call the handler */
258 Status = NpfsSetPipeInformation(DeviceObject,
259 Ccb,
260 SystemBuffer,
261 &BufferLength);
262 break;
263
264 case FilePipeLocalInformation:
265 Status = STATUS_NOT_IMPLEMENTED;
266 break;
267
268 case FilePipeRemoteInformation:
269 /* Call the handler */
270 Status = NpfsSetPipeRemoteInformation(DeviceObject,
271 Ccb,
272 SystemBuffer,
273 &BufferLength);
274 break;
275 default:
276 Status = STATUS_NOT_SUPPORTED;
277 }
278
279 Irp->IoStatus.Status = Status;
280 Irp->IoStatus.Information = 0;
281 IoCompleteRequest(Irp, IO_NO_INCREMENT);
282 return Status;
283 }
284
285 /* EOF */