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