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