Fixed some NT compatibility issues in Nt[Query/Set]InformationFile().
[reactos.git] / reactos / drivers / fs / template / template.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/fs/template/template.c
5 * PURPOSE: Bare filesystem template
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ddk/ntddk.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 typedef struct
18 {
19 PDEVICE_OBJECT StorageDevice;
20 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
21
22 /* GLOBALS *****************************************************************/
23
24 static PDRIVER_OBJECT DriverObject;
25
26 /* FUNCTIONS ****************************************************************/
27
28 NTSTATUS
29 FsdCloseFile(PDEVICE_EXTENSION DeviceExt,
30 PFILE_OBJECT FileObject)
31 /*
32 * FUNCTION: Closes a file
33 */
34 {
35 return(STATUS_SUCCESS);
36 }
37
38 NTSTATUS
39 FsdOpenFile(PDEVICE_EXTENSION DeviceExt,
40 PFILE_OBJECT FileObject,
41 PWSTR FileName)
42 /*
43 * FUNCTION: Opens a file
44 */
45 {
46 return(STATUS_SUCCESS);
47 }
48
49 BOOLEAN
50 FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
51 /*
52 * FUNCTION: Tests if the device contains a filesystem that can be mounted
53 * by this fsd
54 */
55 {
56 return(TRUE);
57 }
58
59 NTSTATUS
60 FsdMountDevice(PDEVICE_EXTENSION DeviceExt,
61 PDEVICE_OBJECT DeviceToMount)
62 /*
63 * FUNCTION: Mounts the device
64 */
65 {
66 return(STATUS_SUCCESS);
67 }
68
69
70 NTSTATUS
71 FsdReadFile(PDEVICE_EXTENSION DeviceExt,
72 PFILE_OBJECT FileObject,
73 PVOID Buffer,
74 ULONG Length,
75 ULONG Offset)
76 /*
77 * FUNCTION: Reads data from a file
78 */
79 {
80 return(STATUS_SUCCESS);
81 }
82
83
84 NTSTATUS STDCALL
85 FsdClose(PDEVICE_OBJECT DeviceObject,
86 PIRP Irp)
87 {
88 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
89 PFILE_OBJECT FileObject = Stack->FileObject;
90 PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
91 NTSTATUS Status;
92
93 Status = FsdCloseFile(DeviceExtension,FileObject);
94
95 Irp->IoStatus.Status = Status;
96 Irp->IoStatus.Information = 0;
97
98 IoCompleteRequest(Irp, IO_NO_INCREMENT);
99 return(Status);
100 }
101
102 NTSTATUS STDCALL
103 FsdCreate(PDEVICE_OBJECT DeviceObject,
104 PIRP Irp)
105 {
106 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
107 PFILE_OBJECT FileObject = Stack->FileObject;
108 NTSTATUS Status;
109 PDEVICE_EXTENSION DeviceExt;
110
111 DeviceExt = DeviceObject->DeviceExtension;
112 Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer);
113
114 Irp->IoStatus.Status = Status;
115 Irp->IoStatus.Information = 0;
116
117 IoCompleteRequest(Irp, IO_NO_INCREMENT);
118 return(Status);
119 }
120
121
122 NTSTATUS STDCALL
123 FsdWrite(PDEVICE_OBJECT DeviceObject,
124 PIRP Irp)
125 {
126 DPRINT("FsdWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
127
128 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
129 Irp->IoStatus.Information = 0;
130 return(STATUS_UNSUCCESSFUL);
131 }
132
133 NTSTATUS STDCALL
134 FsdRead(PDEVICE_OBJECT DeviceObject,
135 PIRP Irp)
136 {
137 ULONG Length;
138 PVOID Buffer;
139 ULONG Offset;
140 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
141 PFILE_OBJECT FileObject = Stack->FileObject;
142 PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
143 NTSTATUS Status;
144
145 DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
146
147 Length = Stack->Parameters.Read.Length;
148 Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
149 Offset = Stack->Parameters.Read.ByteOffset.LowPart;
150
151 Status = FsdReadFile(DeviceExt,FileObject,Buffer,Length,Offset);
152
153 Irp->IoStatus.Status = Status;
154 Irp->IoStatus.Information = Length;
155 IoCompleteRequest(Irp,IO_NO_INCREMENT);
156 return(Status);
157 }
158
159
160 NTSTATUS
161 FsdMount(PDEVICE_OBJECT DeviceToMount)
162 {
163 PDEVICE_OBJECT DeviceObject;
164 PDEVICE_EXTENSION DeviceExt;
165
166 IoCreateDevice(DriverObject,
167 sizeof(DEVICE_EXTENSION),
168 NULL,
169 FILE_DEVICE_FILE_SYSTEM,
170 0,
171 FALSE,
172 &DeviceObject);
173 DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
174 DeviceExt = (PVOID)DeviceObject->DeviceExtension;
175
176 FsdMountDevice(DeviceExt,
177 DeviceToMount);
178
179 DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
180 DeviceToMount);
181 return(STATUS_SUCCESS);
182 }
183
184 NTSTATUS STDCALL
185 FsdFileSystemControl(PDEVICE_OBJECT DeviceObject,
186 PIRP Irp)
187 {
188 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
189 PVPB vpb = Stack->Parameters.Mount.Vpb;
190 PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
191 NTSTATUS Status;
192
193 if (FsdHasFileSystem(DeviceToMount))
194 {
195 Status = FsdMount(DeviceToMount);
196 }
197 else
198 {
199 Status = STATUS_UNRECOGNIZED_VOLUME;
200 }
201
202 Irp->IoStatus.Status = Status;
203 Irp->IoStatus.Information = 0;
204
205 IoCompleteRequest(Irp, IO_NO_INCREMENT);
206 return(Status);
207 }
208
209 NTSTATUS STDCALL
210 DriverEntry(PDRIVER_OBJECT _DriverObject,
211 PUNICODE_STRING RegistryPath)
212 /*
213 * FUNCTION: Called by the system to initalize the driver
214 * ARGUMENTS:
215 * DriverObject = object describing this driver
216 * RegistryPath = path to our configuration entries
217 * RETURNS: Success or failure
218 */
219 {
220 PDEVICE_OBJECT DeviceObject;
221 NTSTATUS Status;
222 UNICODE_STRING DeviceName;
223
224 DbgPrint("Bare FSD Template 0.0.1\n");
225
226 DriverObject = _DriverObject;
227
228 RtlInitUnicodeString(&DeviceName,
229 L"\\Device\\BareFsd");
230 Status = IoCreateDevice(DriverObject,
231 0,
232 &DeviceName,
233 FILE_DEVICE_FILE_SYSTEM,
234 0,
235 FALSE,
236 &DeviceObject);
237 if (!NT_SUCCESS(Status))
238 {
239 return(ret);
240 }
241
242 DeviceObject->Flags=0;
243 DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsdClose;
244 DriverObject->MajorFunction[IRP_MJ_CREATE] = FsdCreate;
245 DriverObject->MajorFunction[IRP_MJ_READ] = FsdRead;
246 DriverObject->MajorFunction[IRP_MJ_WRITE] = FsdWrite;
247 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
248 FsdFileSystemControl;
249 DriverObject->DriverUnload = NULL;
250
251 IoRegisterFileSystem(DeviceObject);
252
253 return(STATUS_SUCCESS);
254 }
255