51d62a2b7ee42f04b8876a405ad9ddf4449ba3e4
[reactos.git] / reactos / drivers / filesystems / ntfs / ntfs.c
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
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
24 * Pierre Schweitzer
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include "ntfs.h"
30
31 #define NDEBUG
32 #include <debug.h>
33
34 /* GLOBALS *****************************************************************/
35
36 PNTFS_GLOBAL_DATA NtfsGlobalData = NULL;
37
38 /* FUNCTIONS ****************************************************************/
39
40 /*
41 * FUNCTION: Called by the system to initialize the driver
42 * ARGUMENTS:
43 * DriverObject = object describing this driver
44 * RegistryPath = path to our configuration entries
45 * RETURNS: Success or failure
46 */
47 INIT_FUNCTION
48 NTSTATUS
49 NTAPI
50 DriverEntry(PDRIVER_OBJECT DriverObject,
51 PUNICODE_STRING RegistryPath)
52 {
53 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(DEVICE_NAME);
54 NTSTATUS Status;
55 PDEVICE_OBJECT DeviceObject;
56
57 TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);
58
59 Status = IoCreateDevice(DriverObject,
60 sizeof(NTFS_GLOBAL_DATA),
61 &DeviceName,
62 FILE_DEVICE_DISK_FILE_SYSTEM,
63 0,
64 FALSE,
65 &DeviceObject);
66 if (!NT_SUCCESS(Status))
67 {
68 WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
69 return Status;
70 }
71
72 /* Initialize global data */
73 NtfsGlobalData = DeviceObject->DeviceExtension;
74 RtlZeroMemory(NtfsGlobalData, sizeof(NTFS_GLOBAL_DATA));
75
76 NtfsGlobalData->DeviceObject = DeviceObject;
77 NtfsGlobalData->Identifier.Type = NTFS_TYPE_GLOBAL_DATA;
78 NtfsGlobalData->Identifier.Size = sizeof(NTFS_GLOBAL_DATA);
79
80 ExInitializeResourceLite(&NtfsGlobalData->Resource);
81
82 /* Keep trace of Driver Object */
83 NtfsGlobalData->DriverObject = DriverObject;
84
85 /* Initialize IRP functions array */
86 NtfsInitializeFunctionPointers(DriverObject);
87
88 /* Initialize CC functions array */
89 NtfsGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = NtfsAcqLazyWrite;
90 NtfsGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = NtfsRelLazyWrite;
91 NtfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = NtfsAcqReadAhead;
92 NtfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = NtfsRelReadAhead;
93
94 NtfsGlobalData->FastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
95 NtfsGlobalData->FastIoDispatch.FastIoCheckIfPossible = NtfsFastIoCheckIfPossible;
96 NtfsGlobalData->FastIoDispatch.FastIoRead = NtfsFastIoRead;
97 NtfsGlobalData->FastIoDispatch.FastIoWrite = NtfsFastIoWrite;
98 DriverObject->FastIoDispatch = &NtfsGlobalData->FastIoDispatch;
99
100 /* Initialize lookaside list for IRP contexts */
101 ExInitializeNPagedLookasideList(&NtfsGlobalData->IrpContextLookasideList,
102 NULL, NULL, 0, sizeof(NTFS_IRP_CONTEXT), 'PRIN', 0);
103 /* Initialize lookaside list for FCBs */
104 ExInitializeNPagedLookasideList(&NtfsGlobalData->FcbLookasideList,
105 NULL, NULL, 0, sizeof(NTFS_FCB), TAG_FCB, 0);
106
107 /* Driver can't be unloaded */
108 DriverObject->DriverUnload = NULL;
109
110 NtfsGlobalData->DeviceObject->Flags |= DO_DIRECT_IO;
111
112 /* Register file system */
113 IoRegisterFileSystem(NtfsGlobalData->DeviceObject);
114 ObReferenceObject(NtfsGlobalData->DeviceObject);
115
116 return Status;
117 }
118
119
120 /*
121 * FUNCTION: Called within the driver entry to initialize the IRP functions array
122 * ARGUMENTS:
123 * DriverObject = object describing this driver
124 * RETURNS: Nothing
125 */
126 INIT_FUNCTION
127 VOID
128 NTAPI
129 NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject)
130 {
131 DriverObject->MajorFunction[IRP_MJ_CREATE] = NtfsFsdDispatch;
132 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NtfsFsdDispatch;
133 DriverObject->MajorFunction[IRP_MJ_READ] = NtfsFsdDispatch;
134 DriverObject->MajorFunction[IRP_MJ_WRITE] = NtfsFsdDispatch;
135 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NtfsFsdDispatch;
136 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = NtfsFsdDispatch;
137 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = NtfsFsdDispatch;
138 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = NtfsFsdDispatch;
139 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = NtfsFsdDispatch;
140 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NtfsFsdDispatch;
141
142 return;
143 }
144
145 /* EOF */