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.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: services/fs/template/template.c
23 * PURPOSE: Bare filesystem template
24 * PROGRAMMER: David Welch (welch@mcmail.com)
28 /* INCLUDES *****************************************************************/
37 PDEVICE_OBJECT StorageDevice
;
38 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
;
40 /* GLOBALS ******************************************************************/
42 static PDRIVER_OBJECT DriverObject
;
44 /* FUNCTIONS ****************************************************************/
47 FsdCloseFile(PDEVICE_EXTENSION DeviceExt
,
48 PFILE_OBJECT FileObject
)
50 * FUNCTION: Closes a file
53 return(STATUS_SUCCESS
);
58 FsdOpenFile(PDEVICE_EXTENSION DeviceExt
,
59 PFILE_OBJECT FileObject
,
62 * FUNCTION: Opens a file
65 return(STATUS_SUCCESS
);
70 FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount
)
72 * FUNCTION: Tests if the device contains a filesystem that can be mounted
81 FsdMountDevice(PDEVICE_EXTENSION DeviceExt
,
82 PDEVICE_OBJECT DeviceToMount
)
84 * FUNCTION: Mounts the device
87 return(STATUS_SUCCESS
);
92 FsdReadFile(PDEVICE_EXTENSION DeviceExt
,
93 PFILE_OBJECT FileObject
,
98 * FUNCTION: Reads data from a file
101 return(STATUS_SUCCESS
);
106 FsdClose(PDEVICE_OBJECT DeviceObject
,
109 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
110 PFILE_OBJECT FileObject
= Stack
->FileObject
;
111 PDEVICE_EXTENSION DeviceExtension
= DeviceObject
->DeviceExtension
;
114 Status
= FsdCloseFile(DeviceExtension
,FileObject
);
116 Irp
->IoStatus
.Status
= Status
;
117 Irp
->IoStatus
.Information
= 0;
119 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
125 FsdCreate(PDEVICE_OBJECT DeviceObject
,
128 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
129 PFILE_OBJECT FileObject
= Stack
->FileObject
;
131 PDEVICE_EXTENSION DeviceExt
;
133 DeviceExt
= DeviceObject
->DeviceExtension
;
134 Status
= FsdOpenFile(DeviceExt
,FileObject
,FileObject
->FileName
.Buffer
);
136 Irp
->IoStatus
.Status
= Status
;
137 Irp
->IoStatus
.Information
= 0;
139 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
145 FsdWrite(PDEVICE_OBJECT DeviceObject
,
148 DPRINT("FsdWrite(DeviceObject %x Irp %x)\n",DeviceObject
,Irp
);
150 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
151 Irp
->IoStatus
.Information
= 0;
152 return(STATUS_UNSUCCESSFUL
);
156 FsdRead(PDEVICE_OBJECT DeviceObject
,
162 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
163 PFILE_OBJECT FileObject
= Stack
->FileObject
;
164 PDEVICE_EXTENSION DeviceExt
= DeviceObject
->DeviceExtension
;
167 DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject
,Irp
);
169 Length
= Stack
->Parameters
.Read
.Length
;
170 Buffer
= MmGetSystemAddressForMdl(Irp
->MdlAddress
);
171 Offset
= Stack
->Parameters
.Read
.ByteOffset
.LowPart
;
173 Status
= FsdReadFile(DeviceExt
,FileObject
,Buffer
,Length
,Offset
);
175 Irp
->IoStatus
.Status
= Status
;
176 Irp
->IoStatus
.Information
= Length
;
177 IoCompleteRequest(Irp
,IO_NO_INCREMENT
);
183 FsdMount(PDEVICE_OBJECT DeviceToMount
)
185 PDEVICE_OBJECT DeviceObject
;
186 PDEVICE_EXTENSION DeviceExt
;
188 IoCreateDevice(DriverObject
,
189 sizeof(DEVICE_EXTENSION
),
191 FILE_DEVICE_FILE_SYSTEM
,
195 DeviceObject
->Flags
= DeviceObject
->Flags
| DO_DIRECT_IO
;
196 DeviceExt
= (PVOID
)DeviceObject
->DeviceExtension
;
198 FsdMountDevice(DeviceExt
,
201 DeviceExt
->StorageDevice
= DeviceToMount
;
202 DeviceExt
->StorageDevice
->Vpb
->DeviceObject
= DeviceObject
;
203 DeviceExt
->StorageDevice
->Vpb
->RealDevice
= DeviceExt
->StorageDevice
;
204 DeviceExt
->StorageDevice
->Vpb
->Flags
|= VPB_MOUNTED
;
205 DeviceObject
->StackSize
= DeviceExt
->StorageDevice
->StackSize
+ 1;
206 DeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
208 return(STATUS_SUCCESS
);
213 FsdFileSystemControl(PDEVICE_OBJECT DeviceObject
,
216 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
217 PVPB vpb
= Stack
->Parameters
.Mount
.Vpb
;
218 PDEVICE_OBJECT DeviceToMount
= Stack
->Parameters
.Mount
.DeviceObject
;
221 if (FsdHasFileSystem(DeviceToMount
))
223 Status
= FsdMount(DeviceToMount
);
227 Status
= STATUS_UNRECOGNIZED_VOLUME
;
230 Irp
->IoStatus
.Status
= Status
;
231 Irp
->IoStatus
.Information
= 0;
233 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
239 DriverEntry(PDRIVER_OBJECT _DriverObject
,
240 PUNICODE_STRING RegistryPath
)
242 * FUNCTION: Called by the system to initialize the driver
244 * DriverObject = object describing this driver
245 * RegistryPath = path to our configuration entries
246 * RETURNS: Success or failure
249 PDEVICE_OBJECT DeviceObject
;
251 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Device\\BareFsd");
253 DbgPrint("Bare FSD Template 0.0.1\n");
255 DriverObject
= _DriverObject
;
257 Status
= IoCreateDevice(DriverObject
,
260 FILE_DEVICE_FILE_SYSTEM
,
264 if (!NT_SUCCESS(Status
))
269 DeviceObject
->Flags
=0;
270 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = FsdClose
;
271 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = FsdCreate
;
272 DriverObject
->MajorFunction
[IRP_MJ_READ
] = FsdRead
;
273 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = FsdWrite
;
274 DriverObject
->MajorFunction
[IRP_MJ_FILE_SYSTEM_CONTROL
] =
275 FsdFileSystemControl
;
276 DriverObject
->DriverUnload
= NULL
;
278 IoRegisterFileSystem(DeviceObject
);
280 return(STATUS_SUCCESS
);