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