ReactOS 0.4.15-dev-5664-g3bf4ef6
filesystem.c
Go to the documentation of this file.
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
34typedef struct
35{
36 PDEVICE_OBJECT StorageDevice;
38
39/* GLOBALS ******************************************************************/
40
42
43/* FUNCTIONS ****************************************************************/
44
48/*
49 * FUNCTION: Closes a file
50 */
51{
52 return(STATUS_SUCCESS);
53}
54
55
60/*
61 * FUNCTION: Opens a file
62 */
63{
64 return(STATUS_SUCCESS);
65}
66
67
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
81 PDEVICE_OBJECT DeviceToMount)
82/*
83 * FUNCTION: Mounts the device
84 */
85{
86 return(STATUS_SUCCESS);
87}
88
89
96/*
97 * FUNCTION: Reads data from a file
98 */
99{
100 return(STATUS_SUCCESS);
101}
102
103
106 PIRP Irp)
107{
109 PFILE_OBJECT FileObject = Stack->FileObject;
110 PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
112
113 Status = FsdCloseFile(DeviceExtension,FileObject);
114
115 Irp->IoStatus.Status = Status;
116 Irp->IoStatus.Information = 0;
117
119 return(Status);
120}
121
122
125 PIRP Irp)
126{
128 PFILE_OBJECT FileObject = Stack->FileObject;
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
139 return(Status);
140}
141
142
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
156 PIRP Irp)
157{
162 PFILE_OBJECT FileObject = Stack->FileObject;
163 PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
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
173
174 Irp->IoStatus.Status = Status;
175 Irp->IoStatus.Information = Length;
177 return(Status);
178}
179
180
183{
185 PDEVICE_EXTENSION DeviceExt;
186
188 sizeof(DEVICE_EXTENSION),
189 NULL,
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
213 PIRP Irp)
214{
216 PVPB vpb = Stack->Parameters.Mount.Vpb;
217 PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
219
220 if (FsdHasFileSystem(DeviceToMount))
221 {
222 Status = FsdMount(DeviceToMount);
223 }
224 else
225 {
227 }
228
229 Irp->IoStatus.Status = Status;
230 Irp->IoStatus.Information = 0;
231
233 return(Status);
234}
235
236
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{
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
257 0,
258 &DeviceName,
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;
275 DriverObject->DriverUnload = NULL;
276
278
279 return(STATUS_SUCCESS);
280}
281
282/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
Status
Definition: gdiplustypes.h:25
#define DbgPrint
Definition: hal.h:12
void * PVOID
Definition: retypes.h:9
unsigned int ULONG
Definition: retypes.h:1
struct DEVICE_EXTENSION * PDEVICE_EXTENSION
NTSTATUS NTAPI FsdWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filesystem.c:144
NTSTATUS NTAPI FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PVOID Buffer, ULONG Length, ULONG Offset)
Definition: filesystem.c:91
NTSTATUS NTAPI FsdMountDevice(PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
Definition: filesystem.c:80
NTSTATUS NTAPI FsdClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filesystem.c:105
static PDRIVER_OBJECT DriverObject
Definition: filesystem.c:41
NTSTATUS NTAPI FsdCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: filesystem.c:46
NTSTATUS NTAPI FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filesystem.c:124
NTSTATUS NTAPI FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filesystem.c:155
NTSTATUS NTAPI FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: filesystem.c:212
BOOLEAN NTAPI FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
Definition: filesystem.c:69
NTSTATUS NTAPI FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PWSTR FileName)
Definition: filesystem.c:57
NTSTATUS FsdMount(PDEVICE_OBJECT DeviceToMount)
Definition: filesystem.c:182
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define IoCompleteRequest
Definition: irp.c:1240
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_FILE_SYSTEM
Definition: winioctl.h:115
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
Definition: iotypes.h:189
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint16_t * PWSTR
Definition: typedefs.h:56
#define NTAPI
Definition: typedefs.h:36
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
#define VPB_MOUNTED
Definition: iotypes.h:1807
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MJ_FILE_SYSTEM_CONTROL
* PFILE_OBJECT
Definition: iotypes.h:1998
#define MmGetSystemAddressForMdl(Mdl)