Sync to trunk (r46918)
[reactos.git] / 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 if (Ccb->PipeEnd == FILE_PIPE_CLIENT_END) ConnectionSideReadMode=Ccb->Fcb->ClientReadMode;
96 else ConnectionSideReadMode = Ccb->Fcb->ServerReadMode;
97
98 /* Return Info */
99 Info->CompletionMode = Fcb->CompletionMode;
100 Info->ReadMode = ConnectionSideReadMode;
101
102 /* Return success */
103 *BufferLength -= sizeof(FILE_PIPE_INFORMATION);
104 return STATUS_SUCCESS;
105 }
106
107 static
108 NTSTATUS
109 NpfsQueryPipeRemoteInformation(PDEVICE_OBJECT DeviceObject,
110 PNPFS_CCB Ccb,
111 PFILE_PIPE_REMOTE_INFORMATION Info,
112 PULONG BufferLength)
113 {
114 PNPFS_FCB Fcb;
115 DPRINT("NpfsQueryPipeRemoteInformation()\n");
116
117 /* Get the Pipe */
118 Fcb = Ccb->Fcb;
119
120 /* Clear Info */
121 RtlZeroMemory(Info, sizeof(FILE_PIPE_REMOTE_INFORMATION));
122
123 /* Return Info */
124 Info->MaximumCollectionCount = Fcb->InboundQuota;
125 Info->CollectDataTime = Fcb->TimeOut;
126
127 /* Return success */
128 *BufferLength -= sizeof(FILE_PIPE_REMOTE_INFORMATION);
129 return STATUS_SUCCESS;
130 }
131
132
133 static NTSTATUS
134 NpfsQueryLocalPipeInformation(PDEVICE_OBJECT DeviceObject,
135 PNPFS_CCB Ccb,
136 PFILE_PIPE_LOCAL_INFORMATION Info,
137 PULONG BufferLength)
138 {
139 PNPFS_FCB Fcb;
140
141 DPRINT("NpfsQueryLocalPipeInformation()\n");
142
143 Fcb = Ccb->Fcb;
144
145 RtlZeroMemory(Info,
146 sizeof(FILE_PIPE_LOCAL_INFORMATION));
147
148 Info->NamedPipeType = Fcb->PipeType;
149 Info->NamedPipeConfiguration = Fcb->PipeConfiguration;
150 Info->MaximumInstances = Fcb->MaximumInstances;
151 Info->CurrentInstances = Fcb->CurrentInstances;
152 Info->InboundQuota = Fcb->InboundQuota;
153 Info->OutboundQuota = Fcb->OutboundQuota;
154 Info->NamedPipeState = Ccb->PipeState;
155 Info->NamedPipeEnd = Ccb->PipeEnd;
156
157 if (Ccb->PipeEnd == FILE_PIPE_SERVER_END)
158 {
159 Info->ReadDataAvailable = Ccb->ReadDataAvailable;
160 Info->WriteQuotaAvailable = Ccb->WriteQuotaAvailable;
161 }
162 else if (Ccb->OtherSide != NULL)
163 {
164 Info->ReadDataAvailable = Ccb->OtherSide->ReadDataAvailable;
165 Info->WriteQuotaAvailable = Ccb->OtherSide->WriteQuotaAvailable;
166 }
167
168 *BufferLength -= sizeof(FILE_PIPE_LOCAL_INFORMATION);
169 return STATUS_SUCCESS;
170 }
171
172
173 NTSTATUS NTAPI
174 NpfsQueryInformation(PDEVICE_OBJECT DeviceObject,
175 PIRP Irp)
176 {
177 PIO_STACK_LOCATION IoStack;
178 FILE_INFORMATION_CLASS FileInformationClass;
179 PFILE_OBJECT FileObject;
180 PNPFS_DEVICE_EXTENSION DeviceExtension;
181 PNPFS_FCB Fcb;
182 PNPFS_CCB Ccb;
183 PVOID SystemBuffer;
184 ULONG BufferLength;
185 NTSTATUS Status;
186
187 DPRINT("NpfsQueryInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
188
189 IoStack = IoGetCurrentIrpStackLocation (Irp);
190 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
191 DeviceExtension = DeviceObject->DeviceExtension;
192 FileObject = IoStack->FileObject;
193 Ccb = (PNPFS_CCB)FileObject->FsContext2;
194 Fcb = Ccb->Fcb;
195
196 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
197 BufferLength = IoStack->Parameters.QueryFile.Length;
198
199 DPRINT("Pipe name: %wZ\n", &Fcb->PipeName);
200 DPRINT("FileInformationClass %d\n", FileInformationClass);
201 DPRINT("SystemBuffer %p\n", SystemBuffer);
202 DPRINT("BufferLength %lu\n", BufferLength);
203
204 switch (FileInformationClass)
205 {
206 case FilePipeInformation:
207 Status = NpfsQueryPipeInformation(DeviceObject,
208 Ccb,
209 SystemBuffer,
210 &BufferLength);
211 break;
212
213 case FilePipeLocalInformation:
214 Status = NpfsQueryLocalPipeInformation(DeviceObject,
215 Ccb,
216 SystemBuffer,
217 &BufferLength);
218 break;
219
220 case FilePipeRemoteInformation:
221 Status = NpfsQueryPipeRemoteInformation(DeviceObject,
222 Ccb,
223 SystemBuffer,
224 &BufferLength);
225 break;
226
227 default:
228 Status = STATUS_NOT_SUPPORTED;
229 }
230
231 Irp->IoStatus.Status = Status;
232 if (NT_SUCCESS(Status))
233 Irp->IoStatus.Information =
234 IoStack->Parameters.QueryFile.Length - BufferLength;
235 else
236 Irp->IoStatus.Information = 0;
237 IoCompleteRequest (Irp, IO_NO_INCREMENT);
238
239 return Status;
240 }
241
242
243 NTSTATUS NTAPI
244 NpfsSetInformation(PDEVICE_OBJECT DeviceObject,
245 PIRP Irp)
246 {
247 PIO_STACK_LOCATION IoStack;
248 FILE_INFORMATION_CLASS FileInformationClass;
249 PFILE_OBJECT FileObject;
250 PNPFS_FCB Fcb;
251 PNPFS_CCB Ccb;
252 PVOID SystemBuffer;
253 ULONG BufferLength;
254 NTSTATUS Status;
255
256 DPRINT("NpfsSetInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
257
258 IoStack = IoGetCurrentIrpStackLocation (Irp);
259 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
260 FileObject = IoStack->FileObject;
261 Ccb = (PNPFS_CCB)FileObject->FsContext2;
262 Fcb = Ccb->Fcb;
263
264 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
265 BufferLength = IoStack->Parameters.QueryFile.Length;
266
267 DPRINT("Pipe name: %wZ\n", &Fcb->PipeName);
268 DPRINT("FileInformationClass %d\n", FileInformationClass);
269 DPRINT("SystemBuffer %p\n", SystemBuffer);
270 DPRINT("BufferLength %lu\n", BufferLength);
271
272 switch (FileInformationClass)
273 {
274 case FilePipeInformation:
275 /* Call the handler */
276 Status = NpfsSetPipeInformation(DeviceObject,
277 Ccb,
278 SystemBuffer,
279 &BufferLength);
280 break;
281
282 case FilePipeLocalInformation:
283 Status = STATUS_NOT_IMPLEMENTED;
284 break;
285
286 case FilePipeRemoteInformation:
287 /* Call the handler */
288 Status = NpfsSetPipeRemoteInformation(DeviceObject,
289 Ccb,
290 SystemBuffer,
291 &BufferLength);
292 break;
293 default:
294 Status = STATUS_NOT_SUPPORTED;
295 }
296
297 Irp->IoStatus.Status = Status;
298 Irp->IoStatus.Information = 0;
299 IoCompleteRequest(Irp, IO_NO_INCREMENT);
300 return Status;
301 }
302
303 /* EOF */