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