3 * Copyright (C) 2002 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/template/template.c
24 * PURPOSE: Bare filesystem template
25 * PROGRAMMER: David Welch (welch@mcmail.com)
29 /* INCLUDES *****************************************************************/
31 #include <ddk/ntddk.h>
38 PDEVICE_OBJECT StorageDevice;
39 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
41 /* GLOBALS ******************************************************************/
43 static PDRIVER_OBJECT DriverObject;
45 /* FUNCTIONS ****************************************************************/
48 FsdCloseFile(PDEVICE_EXTENSION DeviceExt,
49 PFILE_OBJECT FileObject)
51 * FUNCTION: Closes a file
54 return(STATUS_SUCCESS);
59 FsdOpenFile(PDEVICE_EXTENSION DeviceExt,
60 PFILE_OBJECT FileObject,
63 * FUNCTION: Opens a file
66 return(STATUS_SUCCESS);
71 FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
73 * FUNCTION: Tests if the device contains a filesystem that can be mounted
82 FsdMountDevice(PDEVICE_EXTENSION DeviceExt,
83 PDEVICE_OBJECT DeviceToMount)
85 * FUNCTION: Mounts the device
88 return(STATUS_SUCCESS);
93 FsdReadFile(PDEVICE_EXTENSION DeviceExt,
94 PFILE_OBJECT FileObject,
99 * FUNCTION: Reads data from a file
102 return(STATUS_SUCCESS);
107 FsdClose(PDEVICE_OBJECT DeviceObject,
110 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
111 PFILE_OBJECT FileObject = Stack->FileObject;
112 PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
115 Status = FsdCloseFile(DeviceExtension,FileObject);
117 Irp->IoStatus.Status = Status;
118 Irp->IoStatus.Information = 0;
120 IoCompleteRequest(Irp, IO_NO_INCREMENT);
126 FsdCreate(PDEVICE_OBJECT DeviceObject,
129 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
130 PFILE_OBJECT FileObject = Stack->FileObject;
132 PDEVICE_EXTENSION DeviceExt;
134 DeviceExt = DeviceObject->DeviceExtension;
135 Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer);
137 Irp->IoStatus.Status = Status;
138 Irp->IoStatus.Information = 0;
140 IoCompleteRequest(Irp, IO_NO_INCREMENT);
146 FsdWrite(PDEVICE_OBJECT DeviceObject,
149 DPRINT("FsdWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
151 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
152 Irp->IoStatus.Information = 0;
153 return(STATUS_UNSUCCESSFUL);
157 FsdRead(PDEVICE_OBJECT DeviceObject,
163 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
164 PFILE_OBJECT FileObject = Stack->FileObject;
165 PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
168 DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
170 Length = Stack->Parameters.Read.Length;
171 Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
172 Offset = Stack->Parameters.Read.ByteOffset.LowPart;
174 Status = FsdReadFile(DeviceExt,FileObject,Buffer,Length,Offset);
176 Irp->IoStatus.Status = Status;
177 Irp->IoStatus.Information = Length;
178 IoCompleteRequest(Irp,IO_NO_INCREMENT);
184 FsdMount(PDEVICE_OBJECT DeviceToMount)
186 PDEVICE_OBJECT DeviceObject;
187 PDEVICE_EXTENSION DeviceExt;
189 IoCreateDevice(DriverObject,
190 sizeof(DEVICE_EXTENSION),
192 FILE_DEVICE_FILE_SYSTEM,
196 DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
197 DeviceExt = (PVOID)DeviceObject->DeviceExtension;
199 FsdMountDevice(DeviceExt,
202 DeviceExt->StorageDevice = DeviceToMount;
203 DeviceExt->StorageDevice->Vpb->DeviceObject = DeviceObject;
204 DeviceExt->StorageDevice->Vpb->RealDevice = DeviceExt->StorageDevice;
205 DeviceExt->StorageDevice->Vpb->Flags |= VPB_MOUNTED;
206 DeviceObject->StackSize = DeviceExt->StorageDevice->StackSize + 1;
207 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
209 return(STATUS_SUCCESS);
214 FsdFileSystemControl(PDEVICE_OBJECT DeviceObject,
217 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
218 PVPB vpb = Stack->Parameters.Mount.Vpb;
219 PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
222 if (FsdHasFileSystem(DeviceToMount))
224 Status = FsdMount(DeviceToMount);
228 Status = STATUS_UNRECOGNIZED_VOLUME;
231 Irp->IoStatus.Status = Status;
232 Irp->IoStatus.Information = 0;
234 IoCompleteRequest(Irp, IO_NO_INCREMENT);
240 DriverEntry(PDRIVER_OBJECT _DriverObject,
241 PUNICODE_STRING RegistryPath)
243 * FUNCTION: Called by the system to initalize the driver
245 * DriverObject = object describing this driver
246 * RegistryPath = path to our configuration entries
247 * RETURNS: Success or failure
250 PDEVICE_OBJECT DeviceObject;
252 UNICODE_STRING DeviceName = UNICODE_STRING_INITIALIZER(L"\\Device\\BareFsd");
254 DbgPrint("Bare FSD Template 0.0.1\n");
256 DriverObject = _DriverObject;
258 Status = IoCreateDevice(DriverObject,
261 FILE_DEVICE_FILE_SYSTEM,
265 if (!NT_SUCCESS(Status))
270 DeviceObject->Flags=0;
271 DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsdClose;
272 DriverObject->MajorFunction[IRP_MJ_CREATE] = FsdCreate;
273 DriverObject->MajorFunction[IRP_MJ_READ] = FsdRead;
274 DriverObject->MajorFunction[IRP_MJ_WRITE] = FsdWrite;
275 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
276 FsdFileSystemControl;
277 DriverObject->DriverUnload = NULL;
279 IoRegisterFileSystem(DeviceObject);
281 return(STATUS_SUCCESS);