ReactOS  0.4.14-dev-55-g2da92ac
template.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  * FILE: services/fs/template/template.c
23  * PURPOSE: Bare filesystem template
24  * PROGRAMMER: David Welch (welch@mcmail.com)
25  * UPDATE HISTORY:
26  */
27 
28 /* INCLUDES *****************************************************************/
29 
30 #include <ntddk.h>
31 
32 #define NDEBUG
33 #include <debug.h>
34 
35 typedef struct
36 {
37  PDEVICE_OBJECT StorageDevice;
39 
40 /* GLOBALS ******************************************************************/
41 
43 
44 /* FUNCTIONS ****************************************************************/
45 
49 /*
50  * FUNCTION: Closes a file
51  */
52 {
53  return(STATUS_SUCCESS);
54 }
55 
56 
61 /*
62  * FUNCTION: Opens a file
63  */
64 {
65  return(STATUS_SUCCESS);
66 }
67 
68 
71 /*
72  * FUNCTION: Tests if the device contains a filesystem that can be mounted
73  * by this fsd
74  */
75 {
76  return(TRUE);
77 }
78 
79 
82  PDEVICE_OBJECT DeviceToMount)
83 /*
84  * FUNCTION: Mounts the device
85  */
86 {
87  return(STATUS_SUCCESS);
88 }
89 
90 
94  PVOID Buffer,
95  ULONG Length,
96  ULONG Offset)
97 /*
98  * FUNCTION: Reads data from a file
99  */
100 {
101  return(STATUS_SUCCESS);
102 }
103 
104 
107  PIRP Irp)
108 {
113 
114  Status = FsdCloseFile(DeviceExtension,FileObject);
115 
116  Irp->IoStatus.Status = Status;
117  Irp->IoStatus.Information = 0;
118 
120  return(Status);
121 }
122 
123 
126  PIRP Irp)
127 {
131  PDEVICE_EXTENSION DeviceExt;
132 
133  DeviceExt = DeviceObject->DeviceExtension;
134  Status = FsdOpenFile(DeviceExt,FileObject,FileObject->FileName.Buffer);
135 
136  Irp->IoStatus.Status = Status;
137  Irp->IoStatus.Information = 0;
138 
140  return(Status);
141 }
142 
143 
146  PIRP Irp)
147 {
148  DPRINT("FsdWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
149 
150  Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
151  Irp->IoStatus.Information = 0;
152  return(STATUS_UNSUCCESSFUL);
153 }
154 
157  PIRP Irp)
158 {
159  ULONG Length;
160  PVOID Buffer;
161  ULONG Offset;
166 
167  DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
168 
169  Length = Stack->Parameters.Read.Length;
170  Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
171  Offset = Stack->Parameters.Read.ByteOffset.LowPart;
172 
174 
175  Irp->IoStatus.Status = Status;
176  Irp->IoStatus.Information = Length;
178  return(Status);
179 }
180 
181 
182 NTSTATUS
183 FsdMount(PDEVICE_OBJECT DeviceToMount)
184 {
186  PDEVICE_EXTENSION DeviceExt;
187 
189  sizeof(DEVICE_EXTENSION),
190  NULL,
192  0,
193  FALSE,
194  &DeviceObject);
196  DeviceExt = (PVOID)DeviceObject->DeviceExtension;
197 
198  FsdMountDevice(DeviceExt,
199  DeviceToMount);
200 
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;
207 
208  return(STATUS_SUCCESS);
209 }
210 
211 
214  PIRP Irp)
215 {
217  PVPB vpb = Stack->Parameters.Mount.Vpb;
218  PDEVICE_OBJECT DeviceToMount = Stack->Parameters.Mount.DeviceObject;
220 
221  if (FsdHasFileSystem(DeviceToMount))
222  {
223  Status = FsdMount(DeviceToMount);
224  }
225  else
226  {
228  }
229 
230  Irp->IoStatus.Status = Status;
231  Irp->IoStatus.Information = 0;
232 
234  return(Status);
235 }
236 
237 
241 /*
242  * FUNCTION: Called by the system to initialize the driver
243  * ARGUMENTS:
244  * DriverObject = object describing this driver
245  * RegistryPath = path to our configuration entries
246  * RETURNS: Success or failure
247  */
248 {
251  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\BareFsd");
252 
253  DbgPrint("Bare FSD Template 0.0.1\n");
254 
255  DriverObject = _DriverObject;
256 
258  0,
259  &DeviceName,
261  0,
262  FALSE,
263  &DeviceObject);
264  if (!NT_SUCCESS(Status))
265  {
266  return(Status);
267  }
268 
269  DeviceObject->Flags=0;
277 
279 
280  return(STATUS_SUCCESS);
281 }
282 
283 /* EOF */
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
NTSTATUS NTAPI FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: template.c:156
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define DbgPrint
Definition: loader.c:25
_In_ PIRP Irp
Definition: csq.h:116
uint16_t * PWSTR
Definition: typedefs.h:54
#define FILE_DEVICE_FILE_SYSTEM
Definition: winioctl.h:114
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT _DriverObject, PUNICODE_STRING RegistryPath)
Definition: template.c:239
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
NTSTATUS NTAPI FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PVOID Buffer, ULONG Length, ULONG Offset)
Definition: template.c:92
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS FsdMount(PDEVICE_OBJECT DeviceToMount)
Definition: template.c:183
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
struct DEVICE_EXTENSION * PDEVICE_EXTENSION
NTSTATUS NTAPI FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: template.c:213
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI FsdWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: template.c:145
* PFILE_OBJECT
Definition: iotypes.h:1955
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI FsdClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: template.c:106
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS NTAPI FsdCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: template.c:47
NTSTATUS NTAPI FsdMountDevice(PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
Definition: template.c:81
#define IRP_MJ_READ
Definition: rdpdr.c:46
struct _BEEP_DEVICE_EXTENSION DEVICE_EXTENSION
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:992
Definition: iotypes.h:166
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 MmGetSystemAddressForMdl(Mdl)
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
NTSTATUS NTAPI FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: template.c:125
NTSTATUS NTAPI FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, PWSTR FileName)
Definition: template.c:58
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define VPB_MOUNTED
Definition: iotypes.h:1764
BOOLEAN NTAPI FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
Definition: template.c:70
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14