mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
Rewritten NTFS driver entry :
- Use Hervé debug method (better), thanks to Hervé - Use NTAPI instead of STDCALL to have MSVC compatibility, thanks to Hervé - Moved IRP functions array to a new function, NtfsInitializeFunctionPointers - Added more checks - Initialize global and local data before acting with kernel - Removeed the use of one var That should be all.... svn path=/trunk/; revision=31747
This commit is contained in:
parent
6072b41a71
commit
8d54c16b65
2 changed files with 86 additions and 44 deletions
|
@ -23,6 +23,7 @@
|
|||
* FILE: services/fs/ntfs/ntfs.c
|
||||
* PURPOSE: NTFS filesystem driver
|
||||
* PROGRAMMER: Eric Kohl
|
||||
* Pierre Schweitzer
|
||||
*/
|
||||
|
||||
/* INCLUDES *****************************************************************/
|
||||
|
@ -34,12 +35,12 @@
|
|||
|
||||
/* GLOBALS *****************************************************************/
|
||||
|
||||
PNTFS_GLOBAL_DATA NtfsGlobalData;
|
||||
PNTFS_GLOBAL_DATA NtfsGlobalData = NULL;
|
||||
|
||||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
NTSTATUS STDCALL
|
||||
NTSTATUS NTAPI
|
||||
DriverEntry(PDRIVER_OBJECT DriverObject,
|
||||
PUNICODE_STRING RegistryPath)
|
||||
/*
|
||||
|
@ -50,52 +51,83 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
|
|||
* RETURNS: Success or failure
|
||||
*/
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
NTSTATUS Status;
|
||||
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Ntfs");
|
||||
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(DEVICE_NAME);
|
||||
|
||||
DPRINT("NTFS 0.0.1\n");
|
||||
|
||||
Status = IoCreateDevice(DriverObject,
|
||||
sizeof(NTFS_GLOBAL_DATA),
|
||||
&DeviceName,
|
||||
FILE_DEVICE_DISK_FILE_SYSTEM,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);
|
||||
|
||||
/* Initialize global data */
|
||||
NtfsGlobalData = DeviceObject->DeviceExtension;
|
||||
RtlZeroMemory(NtfsGlobalData,
|
||||
sizeof(NTFS_GLOBAL_DATA));
|
||||
NtfsGlobalData = ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_GLOBAL_DATA), TAG('N', 'D', 'R', 'G'));
|
||||
if (!NtfsGlobalData)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto ErrorEnd;
|
||||
}
|
||||
RtlZeroMemory(NtfsGlobalData, sizeof(NTFS_GLOBAL_DATA));
|
||||
NtfsGlobalData->Identifier.Type = NTFS_TYPE_GLOBAL_DATA;
|
||||
NtfsGlobalData->Identifier.Size = sizeof(NTFS_GLOBAL_DATA);
|
||||
|
||||
ExInitializeResourceLite(&NtfsGlobalData->Resource);
|
||||
|
||||
/* Keep trace of Driver Object */
|
||||
NtfsGlobalData->DriverObject = DriverObject;
|
||||
NtfsGlobalData->DeviceObject = DeviceObject;
|
||||
|
||||
/* Initialize driver data */
|
||||
DeviceObject->Flags |= DO_DIRECT_IO;
|
||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = NtfsClose;
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = NtfsCreate;
|
||||
DriverObject->MajorFunction[IRP_MJ_READ] = NtfsRead;
|
||||
DriverObject->MajorFunction[IRP_MJ_WRITE] = NtfsWrite;
|
||||
DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
|
||||
NtfsFileSystemControl;
|
||||
DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
|
||||
NtfsDirectoryControl;
|
||||
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
|
||||
NtfsQueryInformation;
|
||||
DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
|
||||
NtfsQueryVolumeInformation;
|
||||
DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] =
|
||||
NtfsSetVolumeInformation;
|
||||
|
||||
/* Initialize IRP functions array */
|
||||
NtfsInitializeFunctionPointers(DriverObject);
|
||||
/* Driver can't be unloaded */
|
||||
DriverObject->DriverUnload = NULL;
|
||||
|
||||
IoRegisterFileSystem(DeviceObject);
|
||||
Status = IoCreateDevice(DriverObject,
|
||||
sizeof(NTFS_GLOBAL_DATA),
|
||||
&DeviceName,
|
||||
FILE_DEVICE_DISK_FILE_SYSTEM,
|
||||
0,
|
||||
FALSE,
|
||||
&NtfsGlobalData->DeviceObject);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
|
||||
goto ErrorEnd;
|
||||
}
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
/* Register file system */
|
||||
IoRegisterFileSystem(NtfsGlobalData->DeviceObject);
|
||||
ObReferenceObject(NtfsGlobalData->DeviceObject);
|
||||
|
||||
ErrorEnd:
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
if (NtfsGlobalData)
|
||||
{
|
||||
ExDeleteResourceLite(&NtfsGlobalData->Resource);
|
||||
ExFreePoolWithTag(NtfsGlobalData, TAG('N', 'D', 'R', 'G'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
VOID NTAPI
|
||||
NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject)
|
||||
/*
|
||||
* FUNCTION: Called within the driver entry to initialize the IRP functions array
|
||||
* ARGUMENTS:
|
||||
* DriverObject = object describing this driver
|
||||
* RETURNS: Nothing
|
||||
*/
|
||||
{
|
||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = NtfsClose;
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = NtfsCreate;
|
||||
DriverObject->MajorFunction[IRP_MJ_READ] = NtfsRead;
|
||||
DriverObject->MajorFunction[IRP_MJ_WRITE] = NtfsWrite;
|
||||
DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = NtfsFileSystemControl;
|
||||
DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = NtfsDirectoryControl;
|
||||
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NtfsQueryInformation;
|
||||
DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = NtfsQueryVolumeInformation;
|
||||
DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = NtfsSetVolumeInformation;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#define USE_ROS_CC_AND_FS
|
||||
|
||||
|
||||
#define CACHEPAGESIZE(pDeviceExt) \
|
||||
((pDeviceExt)->NtfsInfo.UCHARsPerCluster > PAGE_SIZE ? \
|
||||
(pDeviceExt)->NtfsInfo.UCHARsPerCluster : PAGE_SIZE)
|
||||
|
@ -19,6 +18,8 @@
|
|||
|
||||
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
|
||||
|
||||
#define DEVICE_NAME L"\\Ntfs"
|
||||
|
||||
#include <pshpack1.h>
|
||||
typedef struct _BIOS_PARAMETERS_BLOCK
|
||||
{
|
||||
|
@ -150,8 +151,18 @@ typedef struct _CCB
|
|||
|
||||
#define TAG_CCB TAG('I', 'C', 'C', 'B')
|
||||
|
||||
#define NTFS_TYPE_GLOBAL_DATA TAG('F','S',0,7)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ULONG Type;
|
||||
ULONG Size;
|
||||
} NTFSIDENTIFIER, *PNTFSIDENTIFIER;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
NTFSIDENTIFIER Identifier;
|
||||
ERESOURCE Resource;
|
||||
PDRIVER_OBJECT DriverObject;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
ULONG Flags;
|
||||
|
@ -544,8 +555,7 @@ NtfsSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
|
|||
|
||||
/* ntfs.c */
|
||||
|
||||
NTSTATUS STDCALL
|
||||
DriverEntry(PDRIVER_OBJECT DriverObject,
|
||||
PUNICODE_STRING RegistryPath);
|
||||
DRIVER_INITIALIZE DriverEntry;
|
||||
|
||||
VOID NTAPI NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject);
|
||||
#endif /* NTFS_H */
|
||||
|
|
Loading…
Reference in a new issue