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