3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
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.
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.
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.
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)
27 /* INCLUDES *****************************************************************/
34 /* GLOBALS *****************************************************************/
36 PVFAT_GLOBAL_DATA VfatGlobalData
;
38 /* FUNCTIONS ****************************************************************/
41 * FUNCTION: Called by the system to initialize the driver
43 * DriverObject = object describing this driver
44 * RegistryPath = path to our configuration entries
45 * RETURNS: Success or failure
51 IN PDRIVER_OBJECT DriverObject
,
52 IN PUNICODE_STRING RegistryPath
)
54 PDEVICE_OBJECT DeviceObject
;
55 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Fat");
58 UNREFERENCED_PARAMETER(RegistryPath
);
60 Status
= IoCreateDevice(DriverObject
,
61 sizeof(VFAT_GLOBAL_DATA
),
63 FILE_DEVICE_DISK_FILE_SYSTEM
,
67 if (Status
== STATUS_OBJECT_NAME_EXISTS
||
68 Status
== STATUS_OBJECT_NAME_COLLISION
)
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
),
75 FILE_DEVICE_DISK_FILE_SYSTEM
,
81 if (!NT_SUCCESS(Status
))
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
93 VfatGlobalData->Flags = VFAT_BREAK_ON_CORRUPTION; */
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
)
104 IoDeleteDevice(DeviceObject
);
105 return STATUS_INSUFFICIENT_RESOURCES
;
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
;
126 DriverObject
->DriverUnload
= NULL
;
129 VfatGlobalData
->CacheMgrCallbacks
.AcquireForLazyWrite
= VfatAcquireForLazyWrite
;
130 VfatGlobalData
->CacheMgrCallbacks
.ReleaseFromLazyWrite
= VfatReleaseFromLazyWrite
;
131 VfatGlobalData
->CacheMgrCallbacks
.AcquireForReadAhead
= VfatAcquireForLazyWrite
;
132 VfatGlobalData
->CacheMgrCallbacks
.ReleaseFromReadAhead
= VfatReleaseFromLazyWrite
;
135 VfatInitFastIoRoutines(&VfatGlobalData
->FastIoDispatch
);
136 DriverObject
->FastIoDispatch
= &VfatGlobalData
->FastIoDispatch
;
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);
148 ExInitializeResourceLite(&VfatGlobalData
->VolumeListLock
);
149 InitializeListHead(&VfatGlobalData
->VolumeListHead
);
150 IoRegisterFileSystem(DeviceObject
);
156 Registered
= KdRosRegisterCliCallback(vfatKdbgHandler
);
157 DPRINT1("FastFAT KDBG extension registered: %s\n", (Registered
? "yes" : "no"));
161 return STATUS_SUCCESS
;