2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/fs/ext2/super.c
5 * PURPOSE: ext2 filesystem
6 * PROGRAMMER: David Welch (welch@mcmail.com)
10 /* INCLUDES *****************************************************************/
12 #include <ddk/ntddk.h>
14 #include <internal/string.h>
17 #include <internal/debug.h>
21 /* GLOBALS *****************************************************************/
23 static PDRIVER_OBJECT DriverObject
;
25 /* FUNCTIONS ****************************************************************/
27 NTSTATUS
Ext2Close(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
29 PIO_STACK_LOCATION Stack
;
30 PFILE_OBJECT FileObject
;
31 PDEVICE_EXTENSION DeviceExtension
;
34 DPRINT("Ext2Close(DeviceObject %x, Irp %x)\n",DeviceObject
,Irp
);
36 Stack
= IoGetCurrentIrpStackLocation(Irp
);
37 FileObject
= Stack
->FileObject
;
38 DeviceExtension
= DeviceObject
->DeviceExtension
;
40 Irp
->IoStatus
.Status
= Status
;
41 Irp
->IoStatus
.Information
= 0;
43 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
47 NTSTATUS
Ext2Write(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
49 DPRINT("FsdWrite(DeviceObject %x Irp %x)\n",DeviceObject
,Irp
);
51 Irp
->IoStatus
.Status
= STATUS_UNSUCCESSFUL
;
52 Irp
->IoStatus
.Information
= 0;
53 return(STATUS_UNSUCCESSFUL
);
56 NTSTATUS
Ext2Read(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
61 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
62 PFILE_OBJECT FileObject
= Stack
->FileObject
;
63 PDEVICE_EXTENSION DeviceExt
= DeviceObject
->DeviceExtension
;
66 DPRINT("FsdRead(DeviceObject %x, Irp %x)\n",DeviceObject
,Irp
);
68 Length
= Stack
->Parameters
.Read
.Length
;
69 Buffer
= MmGetSystemAddressForMdl(Irp
->MdlAddress
);
70 Offset
= Stack
->Parameters
.Read
.ByteOffset
;
72 Status
= Ext2ReadFile(DeviceExt
,FileObject
,Buffer
,Length
,Offset
);
74 Irp
->IoStatus
.Status
= Status
;
75 Irp
->IoStatus
.Information
= Length
;
76 IoCompleteRequest(Irp
,IO_NO_INCREMENT
);
82 NTSTATUS
Ext2Mount(PDEVICE_OBJECT DeviceToMount
)
84 PDEVICE_OBJECT DeviceObject
;
85 PDEVICE_EXTENSION DeviceExt
;
87 struct ext2_super_block
* superblock
;
89 DPRINT("Ext2Mount(DeviceToMount %x)\n",DeviceToMount
);
91 BlockBuffer
= ExAllocatePool(NonPagedPool
,BLOCKSIZE
);
92 Ext2ReadSectors(DeviceToMount
,
96 superblock
= BlockBuffer
;
98 if (superblock
->s_magic
!= EXT2_SUPER_MAGIC
)
100 ExFreePool(BlockBuffer
);
101 return(STATUS_UNRECOGNIZED_VOLUME
);
103 DPRINT("Volume recognized\n");
104 DPRINT("s_inodes_count %d\n",superblock
->s_inodes_count
);
105 DPRINT("s_blocks_count %d\n",superblock
->s_blocks_count
);
107 IoCreateDevice(DriverObject
,
108 sizeof(DEVICE_EXTENSION
),
110 FILE_DEVICE_FILE_SYSTEM
,
114 DeviceObject
->Flags
= DeviceObject
->Flags
| DO_DIRECT_IO
;
115 DeviceExt
= (PVOID
)DeviceObject
->DeviceExtension
;
117 DeviceExt
->StorageDevice
= IoAttachDeviceToDeviceStack(DeviceObject
,
119 DeviceExt
->superblock
= superblock
;
121 return(STATUS_SUCCESS
);
124 NTSTATUS
Ext2FileSystemControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
126 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
127 PVPB vpb
= Stack
->Parameters
.Mount
.Vpb
;
128 PDEVICE_OBJECT DeviceToMount
= Stack
->Parameters
.Mount
.DeviceObject
;
131 Status
= Ext2Mount(DeviceToMount
);
133 Irp
->IoStatus
.Status
= Status
;
134 Irp
->IoStatus
.Information
= 0;
136 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
140 NTSTATUS
DriverEntry(PDRIVER_OBJECT _DriverObject
,
141 PUNICODE_STRING RegistryPath
)
143 * FUNCTION: Called by the system to initalize the driver
145 * DriverObject = object describing this driver
146 * RegistryPath = path to our configuration entries
147 * RETURNS: Success or failure
150 PDEVICE_OBJECT DeviceObject
;
152 UNICODE_STRING DeviceNameU
;
153 ANSI_STRING DeviceNameA
;
155 DbgPrint("Ext2 FSD 0.0.1\n");
157 DriverObject
= _DriverObject
;
159 RtlInitAnsiString(&DeviceNameA
,"\\Device\\Ext2Fsd");
160 RtlAnsiStringToUnicodeString(&DeviceNameU
,&DeviceNameA
,TRUE
);
161 ret
= IoCreateDevice(DriverObject
,
164 FILE_DEVICE_FILE_SYSTEM
,
168 if (ret
!=STATUS_SUCCESS
)
173 DeviceObject
->Flags
=0;
174 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = Ext2Close
;
175 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = Ext2Create
;
176 DriverObject
->MajorFunction
[IRP_MJ_READ
] = Ext2Read
;
177 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = Ext2Write
;
178 DriverObject
->MajorFunction
[IRP_MJ_FILE_SYSTEM_CONTROL
] =
179 Ext2FileSystemControl
;
180 DriverObject
->MajorFunction
[IRP_MJ_DIRECTORY_CONTROL
]=
181 Ext2DirectoryControl
;
182 DriverObject
->DriverUnload
= NULL
;
184 DPRINT("DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] %x\n",
185 DriverObject
->MajorFunction
[IRP_MJ_DIRECTORY_CONTROL
]);
186 DPRINT("IRP_MJ_DIRECTORY_CONTROL %d\n",IRP_MJ_DIRECTORY_CONTROL
);
188 IoRegisterFileSystem(DeviceObject
);
190 return(STATUS_SUCCESS
);