324b5b914392aa3ef8eb1aedee74be604230d27c
[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 NTSTATUS
48 NTAPI
49 DriverEntry(PDRIVER_OBJECT DriverObject,
50 PUNICODE_STRING RegistryPath)
51 {
52 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(DEVICE_NAME);
53 NTSTATUS Status;
54
55 TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);
56
57 /* Initialize global data */
58 NtfsGlobalData = ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_GLOBAL_DATA), 'GRDN');
59 if (!NtfsGlobalData)
60 {
61 Status = STATUS_INSUFFICIENT_RESOURCES;
62 goto ErrorEnd;
63 }
64
65 RtlZeroMemory(NtfsGlobalData, sizeof(NTFS_GLOBAL_DATA));
66 NtfsGlobalData->Identifier.Type = NTFS_TYPE_GLOBAL_DATA;
67 NtfsGlobalData->Identifier.Size = sizeof(NTFS_GLOBAL_DATA);
68
69 ExInitializeResourceLite(&NtfsGlobalData->Resource);
70
71 /* Keep trace of Driver Object */
72 NtfsGlobalData->DriverObject = DriverObject;
73
74 /* Initialize IRP functions array */
75 NtfsInitializeFunctionPointers(DriverObject);
76
77 /* Initialize CC functions array */
78 NtfsGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = NtfsAcqLazyWrite;
79 NtfsGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = NtfsRelLazyWrite;
80 NtfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = NtfsAcqReadAhead;
81 NtfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = NtfsRelReadAhead;
82
83 NtfsGlobalData->FastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
84 NtfsGlobalData->FastIoDispatch.FastIoCheckIfPossible = NtfsFastIoCheckIfPossible;
85 NtfsGlobalData->FastIoDispatch.FastIoRead = NtfsFastIoRead;
86 NtfsGlobalData->FastIoDispatch.FastIoWrite = NtfsFastIoWrite;
87 DriverObject->FastIoDispatch = &NtfsGlobalData->FastIoDispatch;
88
89 /* Driver can't be unloaded */
90 DriverObject->DriverUnload = NULL;
91
92 Status = IoCreateDevice(DriverObject,
93 sizeof(NTFS_GLOBAL_DATA),
94 &DeviceName,
95 FILE_DEVICE_DISK_FILE_SYSTEM,
96 0,
97 FALSE,
98 &NtfsGlobalData->DeviceObject);
99 if (!NT_SUCCESS(Status))
100 {
101 WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
102 goto ErrorEnd;
103 }
104
105 NtfsGlobalData->DeviceObject->Flags |= DO_DIRECT_IO;
106
107 /* Register file system */
108 IoRegisterFileSystem(NtfsGlobalData->DeviceObject);
109 ObReferenceObject(NtfsGlobalData->DeviceObject);
110
111 ErrorEnd:
112 if (!NT_SUCCESS(Status))
113 {
114 if (NtfsGlobalData)
115 {
116 ExDeleteResourceLite(&NtfsGlobalData->Resource);
117 ExFreePoolWithTag(NtfsGlobalData, 'GRDN');
118 }
119 }
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 VOID
132 NTAPI
133 NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject)
134 {
135 DriverObject->MajorFunction[IRP_MJ_CREATE] = NtfsFsdCreate;
136 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NtfsFsdClose;
137 DriverObject->MajorFunction[IRP_MJ_READ] = NtfsFsdRead;
138 DriverObject->MajorFunction[IRP_MJ_WRITE] = NtfsFsdWrite;
139 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NtfsFsdQueryInformation;
140 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = NtfsFsdDispatch;
141 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = NtfsFsdDispatch;
142 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = NtfsFsdDirectoryControl;
143 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = NtfsFsdFileSystemControl;
144 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = NtfsFsdDeviceControl;
145
146 return;
147 }
148
149 /* EOF */