903b1af3d6625c4904869070c08cf524e318d810
[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 */
25
26 /* INCLUDES *****************************************************************/
27
28 #include "vfat.h"
29
30 #define NDEBUG
31 #include <debug.h>
32
33 #ifdef KDBG
34 #include <ndk/kdfuncs.h>
35 #include <reactos/kdros.h>
36 #endif
37
38 #if defined(ALLOC_PRAGMA)
39 #pragma alloc_text(INIT, DriverEntry)
40 #endif
41
42 #ifdef KDBG
43 BOOLEAN
44 NTAPI
45 vfatKdbgHandler(
46 IN PCHAR Command,
47 IN ULONG Argc,
48 IN PCH Argv[]);
49 #endif
50
51 /* GLOBALS *****************************************************************/
52
53 PVFAT_GLOBAL_DATA VfatGlobalData;
54
55 /* FUNCTIONS ****************************************************************/
56
57 /*
58 * FUNCTION: Called by the system to initialize the driver
59 * ARGUMENTS:
60 * DriverObject = object describing this driver
61 * RegistryPath = path to our configuration entries
62 * RETURNS: Success or failure
63 */
64 INIT_SECTION
65 NTSTATUS
66 NTAPI
67 DriverEntry(
68 IN PDRIVER_OBJECT DriverObject,
69 IN PUNICODE_STRING RegistryPath)
70 {
71 PDEVICE_OBJECT DeviceObject;
72 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Fat");
73 NTSTATUS Status;
74
75 UNREFERENCED_PARAMETER(RegistryPath);
76
77 Status = IoCreateDevice(DriverObject,
78 sizeof(VFAT_GLOBAL_DATA),
79 &DeviceName,
80 FILE_DEVICE_DISK_FILE_SYSTEM,
81 0,
82 FALSE,
83 &DeviceObject);
84 if (Status == STATUS_OBJECT_NAME_EXISTS ||
85 Status == STATUS_OBJECT_NAME_COLLISION)
86 {
87 /* Try an other name, if 'Fat' is already in use. 'Fat' is also used by fastfat.sys on W2K */
88 RtlInitUnicodeString(&DeviceName, L"\\RosFat");
89 Status = IoCreateDevice(DriverObject,
90 sizeof(VFAT_GLOBAL_DATA),
91 &DeviceName,
92 FILE_DEVICE_DISK_FILE_SYSTEM,
93 0,
94 FALSE,
95 &DeviceObject);
96 }
97
98 if (!NT_SUCCESS(Status))
99 {
100 return Status;
101 }
102
103 VfatGlobalData = DeviceObject->DeviceExtension;
104 RtlZeroMemory (VfatGlobalData, sizeof(VFAT_GLOBAL_DATA));
105 VfatGlobalData->DriverObject = DriverObject;
106 VfatGlobalData->DeviceObject = DeviceObject;
107 VfatGlobalData->NumberProcessors = KeNumberProcessors;
108 /* Enable this to enter the debugger when file system corruption
109 * has been detected:
110 VfatGlobalData->Flags = VFAT_BREAK_ON_CORRUPTION; */
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
150 ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);
151 InitializeListHead(&VfatGlobalData->VolumeListHead);
152 IoRegisterFileSystem(DeviceObject);
153
154 #ifdef KDBG
155 {
156 BOOLEAN Registered;
157
158 Registered = KdRosRegisterCliCallback(vfatKdbgHandler);
159 DPRINT1("FastFAT KDBG extension registered: %s\n", (Registered ? "yes" : "no"));
160 }
161 #endif
162
163 return STATUS_SUCCESS;
164 }
165
166 /* EOF */