[REACTOS] Cleanup INIT and some PAGE section allocations
[reactos.git] / drivers / filesystems / fastfat / iface.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/fs/vfat/iface.c
22 * PURPOSE: VFAT Filesystem
23 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
24 * Pierre Schweitzer (pierre@reactos.org)
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include "vfat.h"
30
31 #define NDEBUG
32 #include <debug.h>
33
34 /* GLOBALS *****************************************************************/
35
36 PVFAT_GLOBAL_DATA VfatGlobalData;
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 CODE_SEG("INIT")
48 NTSTATUS
49 NTAPI
50 DriverEntry(
51 IN PDRIVER_OBJECT DriverObject,
52 IN PUNICODE_STRING RegistryPath)
53 {
54 PDEVICE_OBJECT DeviceObject;
55 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Fat");
56 NTSTATUS Status;
57
58 UNREFERENCED_PARAMETER(RegistryPath);
59
60 Status = IoCreateDevice(DriverObject,
61 sizeof(VFAT_GLOBAL_DATA),
62 &DeviceName,
63 FILE_DEVICE_DISK_FILE_SYSTEM,
64 0,
65 FALSE,
66 &DeviceObject);
67 if (Status == STATUS_OBJECT_NAME_EXISTS ||
68 Status == STATUS_OBJECT_NAME_COLLISION)
69 {
70 /* Try an other name, if 'Fat' is already in use. 'Fat' is also used by fastfat.sys on W2K */
71 RtlInitUnicodeString(&DeviceName, L"\\RosFat");
72 Status = IoCreateDevice(DriverObject,
73 sizeof(VFAT_GLOBAL_DATA),
74 &DeviceName,
75 FILE_DEVICE_DISK_FILE_SYSTEM,
76 0,
77 FALSE,
78 &DeviceObject);
79 }
80
81 if (!NT_SUCCESS(Status))
82 {
83 return Status;
84 }
85
86 VfatGlobalData = DeviceObject->DeviceExtension;
87 RtlZeroMemory (VfatGlobalData, sizeof(VFAT_GLOBAL_DATA));
88 VfatGlobalData->DriverObject = DriverObject;
89 VfatGlobalData->DeviceObject = DeviceObject;
90 VfatGlobalData->NumberProcessors = KeNumberProcessors;
91 /* Enable this to enter the debugger when file system corruption
92 * has been detected:
93 VfatGlobalData->Flags = VFAT_BREAK_ON_CORRUPTION; */
94
95 /* Delayed close support */
96 ExInitializeFastMutex(&VfatGlobalData->CloseMutex);
97 InitializeListHead(&VfatGlobalData->CloseListHead);
98 VfatGlobalData->CloseCount = 0;
99 VfatGlobalData->CloseWorkerRunning = FALSE;
100 VfatGlobalData->ShutdownStarted = FALSE;
101 VfatGlobalData->CloseWorkItem = IoAllocateWorkItem(DeviceObject);
102 if (VfatGlobalData->CloseWorkItem == NULL)
103 {
104 IoDeleteDevice(DeviceObject);
105 return STATUS_INSUFFICIENT_RESOURCES;
106 }
107
108 DeviceObject->Flags |= DO_DIRECT_IO;
109 DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest;
110 DriverObject->MajorFunction[IRP_MJ_CREATE] = VfatBuildRequest;
111 DriverObject->MajorFunction[IRP_MJ_READ] = VfatBuildRequest;
112 DriverObject->MajorFunction[IRP_MJ_WRITE] = VfatBuildRequest;
113 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = VfatBuildRequest;
114 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = VfatBuildRequest;
115 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = VfatBuildRequest;
116 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = VfatBuildRequest;
117 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = VfatBuildRequest;
118 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = VfatBuildRequest;
119 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;
120 DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = VfatBuildRequest;
121 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VfatBuildRequest;
122 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = VfatBuildRequest;
123 DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = VfatBuildRequest;
124 DriverObject->MajorFunction[IRP_MJ_PNP] = VfatBuildRequest;
125
126 DriverObject->DriverUnload = NULL;
127
128 /* Cache manager */
129 VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = VfatAcquireForLazyWrite;
130 VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = VfatReleaseFromLazyWrite;
131 VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead = VfatAcquireForLazyWrite;
132 VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = VfatReleaseFromLazyWrite;
133
134 /* Fast I/O */
135 VfatInitFastIoRoutines(&VfatGlobalData->FastIoDispatch);
136 DriverObject->FastIoDispatch = &VfatGlobalData->FastIoDispatch;
137
138 /* Private lists */
139 ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,
140 NULL, NULL, 0, sizeof(VFATFCB), TAG_FCB, 0);
141 ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,
142 NULL, NULL, 0, sizeof(VFATCCB), TAG_CCB, 0);
143 ExInitializeNPagedLookasideList(&VfatGlobalData->IrpContextLookasideList,
144 NULL, NULL, 0, sizeof(VFAT_IRP_CONTEXT), TAG_IRP, 0);
145 ExInitializePagedLookasideList(&VfatGlobalData->CloseContextLookasideList,
146 NULL, NULL, 0, sizeof(VFAT_CLOSE_CONTEXT), TAG_CLOSE, 0);
147
148 ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);
149 InitializeListHead(&VfatGlobalData->VolumeListHead);
150 IoRegisterFileSystem(DeviceObject);
151
152 #ifdef KDBG
153 {
154 BOOLEAN Registered;
155
156 Registered = KdRosRegisterCliCallback(vfatKdbgHandler);
157 DPRINT1("FastFAT KDBG extension registered: %s\n", (Registered ? "yes" : "no"));
158 }
159 #endif
160
161 return STATUS_SUCCESS;
162 }
163
164 /* EOF */