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