Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / drivers / filesystems / npfs / finfo.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/filesystems/npfs/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
28 UNREFERENCED_PARAMETER(DeviceObject);
29
30 DPRINT("NpfsSetPipeInformation()\n");
31
32 if (*BufferLength < sizeof(FILE_PIPE_INFORMATION))
33 {
34 /* Buffer too small */
35 return STATUS_INFO_LENGTH_MISMATCH;
36 }
37
38
39 /* Get the Pipe and data */
40 Fcb = Ccb->Fcb;
41 Request = (PFILE_PIPE_INFORMATION)Info;
42
43 if ((Fcb->PipeType == FILE_PIPE_BYTE_STREAM_TYPE) && (Request->ReadMode == FILE_PIPE_MESSAGE_MODE))
44 {
45 DPRINT("Cannot change readmode to message type on a byte type pipe!\n");
46 return STATUS_ACCESS_DENIED;
47 }
48
49 /* Set Pipe Data */
50 if (Ccb->PipeEnd == FILE_PIPE_CLIENT_END)
51 {
52 Fcb->ClientReadMode = Request->ReadMode;
53 }
54 else
55 {
56 Fcb->ServerReadMode = Request->ReadMode;
57 }
58
59 Fcb->CompletionMode = Request->CompletionMode;
60
61 /* Return Success */
62 return STATUS_SUCCESS;
63 }
64
65 static
66 NTSTATUS
67 NpfsSetPipeRemoteInformation(PDEVICE_OBJECT DeviceObject,
68 PNPFS_CCB Ccb,
69 PFILE_PIPE_INFORMATION Info,
70 PULONG BufferLength)
71 {
72 PNPFS_FCB Fcb;
73 PFILE_PIPE_REMOTE_INFORMATION Request;
74
75 UNREFERENCED_PARAMETER(DeviceObject);
76
77 DPRINT("NpfsSetPipeRemoteInformation()\n");
78
79 if (*BufferLength < sizeof(FILE_PIPE_REMOTE_INFORMATION))
80 {
81 /* Buffer too small */
82 return STATUS_INFO_LENGTH_MISMATCH;
83 }
84
85 /* Get the Pipe and data */
86 Fcb = Ccb->Fcb;
87 Request = (PFILE_PIPE_REMOTE_INFORMATION)Info;
88
89 /* Set the Settings */
90 Fcb->TimeOut = Request->CollectDataTime;
91 Fcb->InboundQuota = Request->MaximumCollectionCount;
92
93 /* Return Success */
94 return STATUS_SUCCESS;
95 }
96
97 static
98 NTSTATUS
99 NpfsQueryPipeInformation(PDEVICE_OBJECT DeviceObject,
100 PNPFS_CCB Ccb,
101 PFILE_PIPE_INFORMATION Info,
102 PULONG BufferLength)
103 {
104 PNPFS_FCB Fcb;
105 ULONG ConnectionSideReadMode;
106
107 UNREFERENCED_PARAMETER(DeviceObject);
108
109 DPRINT("NpfsQueryPipeInformation()\n");
110
111 if (*BufferLength < sizeof(FILE_PIPE_INFORMATION))
112 {
113 /* Buffer too small */
114 *BufferLength = sizeof(FILE_PIPE_INFORMATION);
115 return STATUS_BUFFER_OVERFLOW;
116 }
117
118 /* Get the Pipe */
119 Fcb = Ccb->Fcb;
120
121 /* Clear Info */
122 RtlZeroMemory(Info, sizeof(FILE_PIPE_INFORMATION));
123
124 if (Ccb->PipeEnd == FILE_PIPE_CLIENT_END) ConnectionSideReadMode=Ccb->Fcb->ClientReadMode;
125 else ConnectionSideReadMode = Ccb->Fcb->ServerReadMode;
126
127 /* Return Info */
128 Info->CompletionMode = Fcb->CompletionMode;
129 Info->ReadMode = ConnectionSideReadMode;
130
131 /* Return success */
132 *BufferLength = sizeof(FILE_PIPE_INFORMATION);
133 return STATUS_SUCCESS;
134 }
135
136 static
137 NTSTATUS
138 NpfsQueryPipeRemoteInformation(PDEVICE_OBJECT DeviceObject,
139 PNPFS_CCB Ccb,
140 PFILE_PIPE_REMOTE_INFORMATION Info,
141 PULONG BufferLength)
142 {
143 PNPFS_FCB Fcb;
144
145 UNREFERENCED_PARAMETER(DeviceObject);
146
147 DPRINT("NpfsQueryPipeRemoteInformation()\n");
148
149 if (*BufferLength < sizeof(FILE_PIPE_REMOTE_INFORMATION))
150 {
151 /* Buffer too small */
152 *BufferLength = sizeof(FILE_PIPE_REMOTE_INFORMATION);
153 return STATUS_BUFFER_OVERFLOW;
154 }
155
156 /* Get the Pipe */
157 Fcb = Ccb->Fcb;
158
159 /* Clear Info */
160 RtlZeroMemory(Info, sizeof(FILE_PIPE_REMOTE_INFORMATION));
161
162 /* Return Info */
163 Info->MaximumCollectionCount = Fcb->InboundQuota;
164 Info->CollectDataTime = Fcb->TimeOut;
165
166 /* Return success */
167 *BufferLength = sizeof(FILE_PIPE_REMOTE_INFORMATION);
168 return STATUS_SUCCESS;
169 }
170
171
172 static NTSTATUS
173 NpfsQueryLocalPipeInformation(PDEVICE_OBJECT DeviceObject,
174 PNPFS_CCB Ccb,
175 PFILE_PIPE_LOCAL_INFORMATION Info,
176 PULONG BufferLength)
177 {
178 PNPFS_FCB Fcb;
179
180 UNREFERENCED_PARAMETER(DeviceObject);
181
182 DPRINT("NpfsQueryLocalPipeInformation()\n");
183
184 if (*BufferLength < sizeof(FILE_PIPE_REMOTE_INFORMATION))
185 {
186 /* Buffer too small */
187 *BufferLength = sizeof(FILE_PIPE_REMOTE_INFORMATION);
188 return STATUS_BUFFER_OVERFLOW;
189 }
190
191 /* Get the Pipe */
192 Fcb = Ccb->Fcb;
193
194 /* Clear Info */
195 RtlZeroMemory(Info,
196 sizeof(FILE_PIPE_LOCAL_INFORMATION));
197
198 /* Return Info */
199 Info->NamedPipeType = Fcb->PipeType;
200 Info->NamedPipeConfiguration = Fcb->PipeConfiguration;
201 Info->MaximumInstances = Fcb->MaximumInstances;
202 Info->CurrentInstances = Fcb->CurrentInstances;
203 Info->InboundQuota = Fcb->InboundQuota;
204 Info->OutboundQuota = Fcb->OutboundQuota;
205 Info->NamedPipeState = Ccb->PipeState;
206 Info->NamedPipeEnd = Ccb->PipeEnd;
207
208 if (Ccb->PipeEnd == FILE_PIPE_SERVER_END)
209 {
210 Info->ReadDataAvailable = Ccb->ReadDataAvailable;
211 Info->WriteQuotaAvailable = Ccb->WriteQuotaAvailable;
212 }
213 else if (Ccb->OtherSide != NULL)
214 {
215 Info->ReadDataAvailable = Ccb->OtherSide->ReadDataAvailable;
216 Info->WriteQuotaAvailable = Ccb->OtherSide->WriteQuotaAvailable;
217 }
218
219 *BufferLength = sizeof(FILE_PIPE_LOCAL_INFORMATION);
220 return STATUS_SUCCESS;
221 }
222
223
224 NTSTATUS NTAPI
225 NpfsQueryInformation(PDEVICE_OBJECT DeviceObject,
226 PIRP Irp)
227 {
228 PIO_STACK_LOCATION IoStack;
229 FILE_INFORMATION_CLASS FileInformationClass;
230 PFILE_OBJECT FileObject;
231 //PNPFS_VCB Vcb;
232 PNPFS_FCB Fcb;
233 PNPFS_CCB Ccb;
234 PVOID SystemBuffer;
235 ULONG BufferLength;
236 NTSTATUS Status;
237
238 DPRINT("NpfsQueryInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
239
240 IoStack = IoGetCurrentIrpStackLocation (Irp);
241 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
242 //Vcb = (PNPFS_VCB)DeviceObject->DeviceExtension;
243 FileObject = IoStack->FileObject;
244 Ccb = (PNPFS_CCB)FileObject->FsContext2;
245 Fcb = Ccb->Fcb;
246
247 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
248 BufferLength = IoStack->Parameters.QueryFile.Length;
249
250 DPRINT("Pipe name: %wZ\n", &Fcb->PipeName);
251 DPRINT("FileInformationClass %d\n", FileInformationClass);
252 DPRINT("SystemBuffer %p\n", SystemBuffer);
253 DPRINT("BufferLength %lu\n", BufferLength);
254
255 switch (FileInformationClass)
256 {
257 case FilePipeInformation:
258 Status = NpfsQueryPipeInformation(DeviceObject,
259 Ccb,
260 SystemBuffer,
261 &BufferLength);
262 break;
263
264 case FilePipeLocalInformation:
265 Status = NpfsQueryLocalPipeInformation(DeviceObject,
266 Ccb,
267 SystemBuffer,
268 &BufferLength);
269 break;
270
271 case FilePipeRemoteInformation:
272 Status = NpfsQueryPipeRemoteInformation(DeviceObject,
273 Ccb,
274 SystemBuffer,
275 &BufferLength);
276 break;
277
278 default:
279 Status = STATUS_NOT_SUPPORTED;
280 BufferLength = 0;
281 }
282
283 Irp->IoStatus.Status = Status;
284 Irp->IoStatus.Information = BufferLength;
285
286 IoCompleteRequest (Irp, IO_NO_INCREMENT);
287
288 return Status;
289 }
290
291
292 NTSTATUS NTAPI
293 NpfsSetInformation(PDEVICE_OBJECT DeviceObject,
294 PIRP Irp)
295 {
296 PIO_STACK_LOCATION IoStack;
297 FILE_INFORMATION_CLASS FileInformationClass;
298 PFILE_OBJECT FileObject;
299 PNPFS_FCB Fcb;
300 PNPFS_CCB Ccb;
301 PVOID SystemBuffer;
302 ULONG BufferLength;
303 NTSTATUS Status;
304
305 DPRINT("NpfsSetInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
306
307 IoStack = IoGetCurrentIrpStackLocation (Irp);
308 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
309 FileObject = IoStack->FileObject;
310 Ccb = (PNPFS_CCB)FileObject->FsContext2;
311 Fcb = Ccb->Fcb;
312
313 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
314 BufferLength = IoStack->Parameters.QueryFile.Length;
315
316 DPRINT("Pipe name: %wZ\n", &Fcb->PipeName);
317 DPRINT("FileInformationClass %d\n", FileInformationClass);
318 DPRINT("SystemBuffer %p\n", SystemBuffer);
319 DPRINT("BufferLength %lu\n", BufferLength);
320
321 switch (FileInformationClass)
322 {
323 case FilePipeInformation:
324 /* Call the handler */
325 Status = NpfsSetPipeInformation(DeviceObject,
326 Ccb,
327 SystemBuffer,
328 &BufferLength);
329 break;
330
331 case FilePipeLocalInformation:
332 Status = STATUS_NOT_IMPLEMENTED;
333 break;
334
335 case FilePipeRemoteInformation:
336 /* Call the handler */
337 Status = NpfsSetPipeRemoteInformation(DeviceObject,
338 Ccb,
339 SystemBuffer,
340 &BufferLength);
341 break;
342 default:
343 Status = STATUS_NOT_SUPPORTED;
344 }
345
346 Irp->IoStatus.Status = Status;
347 Irp->IoStatus.Information = 0;
348 IoCompleteRequest(Irp, IO_NO_INCREMENT);
349 return Status;
350 }
351
352 /* EOF */