[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
[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 #if defined(ALLOC_PRAGMA)
35 #pragma alloc_text(INIT, DriverEntry)
36 #endif
37
38 /* GLOBALS *****************************************************************/
39
40 PVFAT_GLOBAL_DATA VfatGlobalData;
41
42 /* FUNCTIONS ****************************************************************/
43
44 /*
45 * FUNCTION: Called by the system to initialize the driver
46 * ARGUMENTS:
47 * DriverObject = object describing this driver
48 * RegistryPath = path to our configuration entries
49 * RETURNS: Success or failure
50 */
51 INIT_FUNCTION
52 NTSTATUS
53 NTAPI
54 DriverEntry(
55 IN PDRIVER_OBJECT DriverObject,
56 IN PUNICODE_STRING RegistryPath)
57 {
58 PDEVICE_OBJECT DeviceObject;
59 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Fat");
60 NTSTATUS Status;
61
62 UNREFERENCED_PARAMETER(RegistryPath);
63
64 Status = IoCreateDevice(DriverObject,
65 sizeof(VFAT_GLOBAL_DATA),
66 &DeviceName,
67 FILE_DEVICE_DISK_FILE_SYSTEM,
68 0,
69 FALSE,
70 &DeviceObject);
71 if (Status == STATUS_OBJECT_NAME_EXISTS ||
72 Status == STATUS_OBJECT_NAME_COLLISION)
73 {
74 /* Try an other name, if 'Fat' is already in use. 'Fat' is also used by fastfat.sys on W2K */
75 RtlInitUnicodeString(&DeviceName, L"\\RosFat");
76 Status = IoCreateDevice(DriverObject,
77 sizeof(VFAT_GLOBAL_DATA),
78 &DeviceName,
79 FILE_DEVICE_DISK_FILE_SYSTEM,
80 0,
81 FALSE,
82 &DeviceObject);
83 }
84
85 if (!NT_SUCCESS(Status))
86 {
87 return Status;
88 }
89
90 VfatGlobalData = DeviceObject->DeviceExtension;
91 RtlZeroMemory (VfatGlobalData, sizeof(VFAT_GLOBAL_DATA));
92 VfatGlobalData->DriverObject = DriverObject;
93 VfatGlobalData->DeviceObject = DeviceObject;
94 VfatGlobalData->NumberProcessors = KeNumberProcessors;
95 /* Enable this to enter the debugger when file system corruption
96 * has been detected:
97 VfatGlobalData->Flags = VFAT_BREAK_ON_CORRUPTION; */
98
99 /* Delayed close support */
100 ExInitializeFastMutex(&VfatGlobalData->CloseMutex);
101 InitializeListHead(&VfatGlobalData->CloseListHead);
102 VfatGlobalData->CloseCount = 0;
103 VfatGlobalData->CloseWorkerRunning = FALSE;
104 VfatGlobalData->ShutdownStarted = FALSE;
105 VfatGlobalData->CloseWorkItem = IoAllocateWorkItem(DeviceObject);
106 if (VfatGlobalData->CloseWorkItem == NULL)
107 {
108 IoDeleteDevice(DeviceObject);
109 return STATUS_INSUFFICIENT_RESOURCES;
110 }
111
112 DeviceObject->Flags |= DO_DIRECT_IO;
113 DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest;
114 DriverObject->MajorFunction[IRP_MJ_CREATE] = VfatBuildRequest;
115 DriverObject->MajorFunction[IRP_MJ_READ] = VfatBuildRequest;
116 DriverObject->MajorFunction[IRP_MJ_WRITE] = VfatBuildRequest;
117 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = VfatBuildRequest;
118 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = VfatBuildRequest;
119 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = VfatBuildRequest;
120 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = VfatBuildRequest;
121 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = VfatBuildRequest;
122 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = VfatBuildRequest;
123 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;
124 DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = VfatBuildRequest;
125 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VfatBuildRequest;
126 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = VfatBuildRequest;
127 DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = VfatBuildRequest;
128 DriverObject->MajorFunction[IRP_MJ_PNP] = VfatBuildRequest;
129
130 DriverObject->DriverUnload = NULL;
131
132 /* Cache manager */
133 VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = VfatAcquireForLazyWrite;
134 VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = VfatReleaseFromLazyWrite;
135 VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead = VfatAcquireForLazyWrite;
136 VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = VfatReleaseFromLazyWrite;
137
138 /* Fast I/O */
139 VfatInitFastIoRoutines(&VfatGlobalData->FastIoDispatch);
140 DriverObject->FastIoDispatch = &VfatGlobalData->FastIoDispatch;
141
142 /* Private lists */
143 ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,
144 NULL, NULL, 0, sizeof(VFATFCB), TAG_FCB, 0);
145 ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,
146 NULL, NULL, 0, sizeof(VFATCCB), TAG_CCB, 0);
147 ExInitializeNPagedLookasideList(&VfatGlobalData->IrpContextLookasideList,
148 NULL, NULL, 0, sizeof(VFAT_IRP_CONTEXT), TAG_IRP, 0);
149 ExInitializePagedLookasideList(&VfatGlobalData->CloseContextLookasideList,
150 NULL, NULL, 0, sizeof(VFAT_CLOSE_CONTEXT), TAG_CLOSE, 0);
151
152 ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);
153 InitializeListHead(&VfatGlobalData->VolumeListHead);
154 IoRegisterFileSystem(DeviceObject);
155
156 #ifdef KDBG
157 {
158 BOOLEAN Registered;
159
160 Registered = KdRosRegisterCliCallback(vfatKdbgHandler);
161 DPRINT1("FastFAT KDBG extension registered: %s\n", (Registered ? "yes" : "no"));
162 }
163 #endif
164
165 return STATUS_SUCCESS;
166 }
167
168 /* EOF */