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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/ntfs.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Eric Kohl
27 /* INCLUDES *****************************************************************/
34 #if defined(ALLOC_PRAGMA)
35 #pragma alloc_text(INIT, DriverEntry)
36 #pragma alloc_text(INIT, NtfsInitializeFunctionPointers)
39 /* GLOBALS *****************************************************************/
41 PNTFS_GLOBAL_DATA NtfsGlobalData
= NULL
;
43 /* FUNCTIONS ****************************************************************/
46 * FUNCTION: Called by the system to initialize the driver
48 * DriverObject = object describing this driver
49 * RegistryPath = path to our configuration entries
50 * RETURNS: Success or failure
55 DriverEntry(PDRIVER_OBJECT DriverObject
,
56 PUNICODE_STRING RegistryPath
)
58 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(DEVICE_NAME
);
60 PDEVICE_OBJECT DeviceObject
;
61 OBJECT_ATTRIBUTES Attributes
;
62 HANDLE DriverKey
= NULL
;
64 TRACE_(NTFS
, "DriverEntry(%p, '%wZ')\n", DriverObject
, RegistryPath
);
66 Status
= IoCreateDevice(DriverObject
,
67 sizeof(NTFS_GLOBAL_DATA
),
69 FILE_DEVICE_DISK_FILE_SYSTEM
,
73 if (!NT_SUCCESS(Status
))
75 WARN_(NTFS
, "IoCreateDevice failed with status: %lx\n", Status
);
79 /* Initialize global data */
80 NtfsGlobalData
= DeviceObject
->DeviceExtension
;
81 RtlZeroMemory(NtfsGlobalData
, sizeof(NTFS_GLOBAL_DATA
));
83 NtfsGlobalData
->DeviceObject
= DeviceObject
;
84 NtfsGlobalData
->Identifier
.Type
= NTFS_TYPE_GLOBAL_DATA
;
85 NtfsGlobalData
->Identifier
.Size
= sizeof(NTFS_GLOBAL_DATA
);
87 ExInitializeResourceLite(&NtfsGlobalData
->Resource
);
89 NtfsGlobalData
->EnableWriteSupport
= FALSE
;
91 // Read registry to determine if write support should be enabled
92 InitializeObjectAttributes(&Attributes
,
94 OBJ_CASE_INSENSITIVE
| OBJ_KERNEL_HANDLE
,
98 Status
= ZwOpenKey(&DriverKey
, KEY_READ
, &Attributes
);
99 if (NT_SUCCESS(Status
))
101 UNICODE_STRING ValueName
;
102 UCHAR Buffer
[sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + sizeof(ULONG
)];
103 PKEY_VALUE_PARTIAL_INFORMATION Value
= (PKEY_VALUE_PARTIAL_INFORMATION
)Buffer
;
104 ULONG ValueLength
= sizeof(Buffer
);
107 RtlInitUnicodeString(&ValueName
, L
"MyDataDoesNotMatterSoEnableExperimentalWriteSupportForEveryNTFSVolume");
109 Status
= ZwQueryValueKey(DriverKey
,
111 KeyValuePartialInformation
,
116 if (NT_SUCCESS(Status
) && Value
->Data
[0] == TRUE
)
118 DPRINT1("\tEnabling write support on ALL NTFS volumes!\n");
119 NtfsGlobalData
->EnableWriteSupport
= TRUE
;
125 /* Keep trace of Driver Object */
126 NtfsGlobalData
->DriverObject
= DriverObject
;
128 /* Initialize IRP functions array */
129 NtfsInitializeFunctionPointers(DriverObject
);
131 /* Initialize CC functions array */
132 NtfsGlobalData
->CacheMgrCallbacks
.AcquireForLazyWrite
= NtfsAcqLazyWrite
;
133 NtfsGlobalData
->CacheMgrCallbacks
.ReleaseFromLazyWrite
= NtfsRelLazyWrite
;
134 NtfsGlobalData
->CacheMgrCallbacks
.AcquireForReadAhead
= NtfsAcqReadAhead
;
135 NtfsGlobalData
->CacheMgrCallbacks
.ReleaseFromReadAhead
= NtfsRelReadAhead
;
137 NtfsGlobalData
->FastIoDispatch
.SizeOfFastIoDispatch
= sizeof(FAST_IO_DISPATCH
);
138 NtfsGlobalData
->FastIoDispatch
.FastIoCheckIfPossible
= NtfsFastIoCheckIfPossible
;
139 NtfsGlobalData
->FastIoDispatch
.FastIoRead
= NtfsFastIoRead
;
140 NtfsGlobalData
->FastIoDispatch
.FastIoWrite
= NtfsFastIoWrite
;
141 DriverObject
->FastIoDispatch
= &NtfsGlobalData
->FastIoDispatch
;
143 /* Initialize lookaside list for IRP contexts */
144 ExInitializeNPagedLookasideList(&NtfsGlobalData
->IrpContextLookasideList
,
145 NULL
, NULL
, 0, sizeof(NTFS_IRP_CONTEXT
), 'PRIN', 0);
146 /* Initialize lookaside list for FCBs */
147 ExInitializeNPagedLookasideList(&NtfsGlobalData
->FcbLookasideList
,
148 NULL
, NULL
, 0, sizeof(NTFS_FCB
), TAG_FCB
, 0);
150 /* Driver can't be unloaded */
151 DriverObject
->DriverUnload
= NULL
;
153 NtfsGlobalData
->DeviceObject
->Flags
|= DO_DIRECT_IO
;
155 /* Register file system */
156 IoRegisterFileSystem(NtfsGlobalData
->DeviceObject
);
157 ObReferenceObject(NtfsGlobalData
->DeviceObject
);
159 return STATUS_SUCCESS
;
164 * FUNCTION: Called within the driver entry to initialize the IRP functions array
166 * DriverObject = object describing this driver
172 NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject
)
174 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = NtfsFsdDispatch
;
175 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = NtfsFsdDispatch
;
176 DriverObject
->MajorFunction
[IRP_MJ_CLEANUP
] = NtfsFsdDispatch
;
177 DriverObject
->MajorFunction
[IRP_MJ_READ
] = NtfsFsdDispatch
;
178 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = NtfsFsdDispatch
;
179 DriverObject
->MajorFunction
[IRP_MJ_QUERY_INFORMATION
] = NtfsFsdDispatch
;
180 DriverObject
->MajorFunction
[IRP_MJ_SET_INFORMATION
] = NtfsFsdDispatch
;
181 DriverObject
->MajorFunction
[IRP_MJ_QUERY_VOLUME_INFORMATION
] = NtfsFsdDispatch
;
182 DriverObject
->MajorFunction
[IRP_MJ_SET_VOLUME_INFORMATION
] = NtfsFsdDispatch
;
183 DriverObject
->MajorFunction
[IRP_MJ_DIRECTORY_CONTROL
] = NtfsFsdDispatch
;
184 DriverObject
->MajorFunction
[IRP_MJ_FILE_SYSTEM_CONTROL
] = NtfsFsdDispatch
;
185 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = NtfsFsdDispatch
;