Update Indentation (tab->4spaces).
[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: drivers/filesystems/ms/finfo.c
6 * PURPOSE: Mailslot filesystem
7 * PROGRAMMER: Eric Kohl
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",
81 DeviceObject, Irp);
82
83 IoStack = IoGetCurrentIrpStackLocation (Irp);
84 FileInformationClass = IoStack->Parameters.QueryFile.FileInformationClass;
85 DeviceExtension = DeviceObject->DeviceExtension;
86 FileObject = IoStack->FileObject;
87 Fcb = (PMSFS_FCB)FileObject->FsContext;
88 Ccb = (PMSFS_CCB)FileObject->FsContext2;
89
90 DPRINT("Mailslot name: %wZ\n", &Fcb->Name);
91
92 /* querying information is not permitted on client side */
93 if (Fcb->ServerCcb != Ccb)
94 {
95 Status = STATUS_ACCESS_DENIED;
96
97 Irp->IoStatus.Status = Status;
98 Irp->IoStatus.Information = 0;
99
100 IoCompleteRequest(Irp, 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
116 default:
117 Status = STATUS_NOT_IMPLEMENTED;
118 }
119
120 Irp->IoStatus.Status = Status;
121 if (NT_SUCCESS(Status))
122 Irp->IoStatus.Information =
123 IoStack->Parameters.QueryFile.Length - BufferLength;
124 else
125 Irp->IoStatus.Information = 0;
126 IoCompleteRequest(Irp, 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, IO_NO_INCREMENT);
164
165 return Status;
166 }
167
168 SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
169 BufferLength = IoStack->Parameters.QueryFile.Length;
170
171 DPRINT("FileInformationClass %d\n", FileInformationClass);
172 DPRINT("SystemBuffer %x\n", SystemBuffer);
173
174 switch (FileInformationClass)
175 {
176 case FileMailslotSetInformation:
177 Status = MsfsSetMailslotInformation(Fcb,
178 SystemBuffer,
179 &BufferLength);
180 break;
181
182 default:
183 Status = STATUS_NOT_IMPLEMENTED;
184 }
185
186 Irp->IoStatus.Status = Status;
187 Irp->IoStatus.Information = 0;
188 IoCompleteRequest(Irp, IO_NO_INCREMENT);
189
190 return Status;
191 }
192
193 /* EOF */