33a5bebd18ff5531ac36c96b0dc72862065a7c87
[reactos.git] / reactos / drivers / fs / ms / finfo.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/fs/ms/finfo.c
6 * PURPOSE: Mailslot filesystem
7 * PROGRAMMER: Eric Kohl <ekohl@rz-online.de>
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <ntifs.h>
13 #include "msfs.h"
14
15 #define NDEBUG
16 #include <debug.h>
17
18
19 /* FUNCTIONS *****************************************************************/
20
21 static NTSTATUS
22 MsfsQueryMailslotInformation(PMSFS_FCB Fcb,
23 PFILE_MAILSLOT_QUERY_INFORMATION Buffer,
24 PULONG BufferLength)
25 {
26 PMSFS_MAILSLOT Mailslot;
27 KIRQL oldIrql;
28
29 if (*BufferLength < sizeof(FILE_MAILSLOT_QUERY_INFORMATION))
30 return(STATUS_BUFFER_OVERFLOW);
31
32 Mailslot = Fcb->Mailslot;
33
34 Buffer->MaximumMessageSize = Mailslot->MaxMessageSize;
35 Buffer->ReadTimeout = Mailslot->TimeOut;
36
37 KeAcquireSpinLock(&Mailslot->MessageListLock, &oldIrql);
38 Buffer->MessagesAvailable = Mailslot->MessageCount;
39 if (Mailslot->MessageCount == 0)
40 {
41 Buffer->NextMessageSize = 0;
42 }
43 else
44 {
45 /* FIXME: read size of first message (head) */
46 Buffer->NextMessageSize = 0;
47 }
48 KeReleaseSpinLock(&Mailslot->MessageListLock, oldIrql);
49
50 *BufferLength -= sizeof(FILE_MAILSLOT_QUERY_INFORMATION);
51
52 return(STATUS_SUCCESS);
53 }
54
55
56 static NTSTATUS
57 MsfsSetMailslotInformation(PMSFS_FCB Fcb,
58 PFILE_MAILSLOT_SET_INFORMATION Buffer,
59 PULONG BufferLength)
60 {
61 if (*BufferLength < sizeof(FILE_MAILSLOT_SET_INFORMATION))
62 return(STATUS_BUFFER_OVERFLOW);
63
64 Fcb->Mailslot->TimeOut = Buffer->ReadTimeout;
65
66 return(STATUS_SUCCESS);
67 }
68
69
70 NTSTATUS STDCALL
71 MsfsQueryInformation(PDEVICE_OBJECT DeviceObject,
72 PIRP Irp)
73 {
74 PIO_STACK_LOCATION IoStack;
75 FILE_INFORMATION_CLASS FileInformationClass;
76 PFILE_OBJECT FileObject;
77 PMSFS_DEVICE_EXTENSION DeviceExtension;
78 PMSFS_FCB Fcb;
79 PMSFS_MAILSLOT Mailslot;
80 PVOID SystemBuffer;
81 ULONG BufferLength;
82 NTSTATUS Status;
83
84 DPRINT("MsfsQueryInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
85
86 IoStack = IoGetCurrentIrpStackLocation (Irp);
87 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
88 DeviceExtension = DeviceObject->DeviceExtension;
89 FileObject = IoStack->FileObject;
90 Fcb = (PMSFS_FCB)FileObject->FsContext;
91 Mailslot = Fcb->Mailslot;
92
93 DPRINT("Mailslot name: %wZ\n", &Mailslot->Name);
94
95 /* querying information is not permitted on client side */
96 if (Fcb->Mailslot->ServerFcb != Fcb)
97 {
98 Status = STATUS_ACCESS_DENIED;
99
100 Irp->IoStatus.Status = Status;
101 Irp->IoStatus.Information = 0;
102
103 IoCompleteRequest(Irp,
104 IO_NO_INCREMENT);
105
106 return(Status);
107 }
108
109 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
110 BufferLength = IoStack->Parameters.QueryFile.Length;
111
112 switch (FileInformationClass)
113 {
114 case FileMailslotQueryInformation:
115 Status = MsfsQueryMailslotInformation(Fcb,
116 SystemBuffer,
117 &BufferLength);
118 break;
119 default:
120 Status = STATUS_NOT_IMPLEMENTED;
121 }
122
123 Irp->IoStatus.Status = Status;
124 if (NT_SUCCESS(Status))
125 Irp->IoStatus.Information =
126 IoStack->Parameters.QueryFile.Length - BufferLength;
127 else
128 Irp->IoStatus.Information = 0;
129 IoCompleteRequest(Irp,
130 IO_NO_INCREMENT);
131
132 return(Status);
133 }
134
135
136 NTSTATUS STDCALL
137 MsfsSetInformation(PDEVICE_OBJECT DeviceObject,
138 PIRP Irp)
139 {
140 PIO_STACK_LOCATION IoStack;
141 FILE_INFORMATION_CLASS FileInformationClass;
142 PFILE_OBJECT FileObject;
143 PMSFS_FCB Fcb;
144 PMSFS_MAILSLOT Mailslot;
145 PVOID SystemBuffer;
146 ULONG BufferLength;
147 NTSTATUS Status;
148
149 DPRINT("MsfsSetInformation(DeviceObject %p Irp %p)\n", DeviceObject, Irp);
150
151 IoStack = IoGetCurrentIrpStackLocation (Irp);
152 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
153 FileObject = IoStack->FileObject;
154 Fcb = (PMSFS_FCB)FileObject->FsContext;
155 Mailslot = Fcb->Mailslot;
156
157 DPRINT("Mailslot name: %wZ\n", &Mailslot->Name);
158
159 /* setting information is not permitted on client side */
160 if (Fcb->Mailslot->ServerFcb != Fcb)
161 {
162 Status = STATUS_ACCESS_DENIED;
163
164 Irp->IoStatus.Status = Status;
165 Irp->IoStatus.Information = 0;
166
167 IoCompleteRequest(Irp,
168 IO_NO_INCREMENT);
169
170 return(Status);
171 }
172
173 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
174 BufferLength = IoStack->Parameters.QueryFile.Length;
175
176 DPRINT("FileInformationClass %d\n", FileInformationClass);
177 DPRINT("SystemBuffer %x\n", SystemBuffer);
178
179 switch (FileInformationClass)
180 {
181 case FileMailslotSetInformation:
182 Status = MsfsSetMailslotInformation(Fcb,
183 SystemBuffer,
184 &BufferLength);
185 break;
186 default:
187 Status = STATUS_NOT_IMPLEMENTED;
188 }
189
190 Irp->IoStatus.Status = Status;
191 Irp->IoStatus.Information = 0;
192 IoCompleteRequest(Irp,
193 IO_NO_INCREMENT);
194
195 return(Status);
196 }
197
198 /* EOF */