0a509b37f57f10ec44dc01baeb14dbd0569b8bad
[reactos.git] / reactos / 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 /* GLOBALS *****************************************************************/
34
35 PVFAT_GLOBAL_DATA VfatGlobalData;
36
37 /* FUNCTIONS ****************************************************************/
38
39 /*
40 * FUNCTION: Called by the system to initialize the driver
41 * ARGUMENTS:
42 * DriverObject = object describing this driver
43 * RegistryPath = path to our configuration entries
44 * RETURNS: Success or failure
45 */
46 INIT_FUNCTION
47 NTSTATUS
48 NTAPI
49 DriverEntry(
50 IN PDRIVER_OBJECT DriverObject,
51 IN PUNICODE_STRING RegistryPath)
52 {
53 PDEVICE_OBJECT DeviceObject;
54 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Fat");
55 NTSTATUS Status;
56
57 UNREFERENCED_PARAMETER(RegistryPath);
58
59 Status = IoCreateDevice(DriverObject,
60 sizeof(VFAT_GLOBAL_DATA),
61 &DeviceName,
62 FILE_DEVICE_DISK_FILE_SYSTEM,
63 0,
64 FALSE,
65 &DeviceObject);
66 if (Status == STATUS_OBJECT_NAME_EXISTS ||
67 Status == STATUS_OBJECT_NAME_COLLISION)
68 {
69 /* Try an other name, if 'Fat' is already in use. 'Fat' is also used by fastfat.sys on W2K */
70 RtlInitUnicodeString(&DeviceName, L"\\RosFat");
71 Status = IoCreateDevice(DriverObject,
72 sizeof(VFAT_GLOBAL_DATA),
73 &DeviceName,
74 FILE_DEVICE_DISK_FILE_SYSTEM,
75 0,
76 FALSE,
77 &DeviceObject);
78 }
79
80 if (!NT_SUCCESS(Status))
81 {
82 return Status;
83 }
84
85 VfatGlobalData = DeviceObject->DeviceExtension;
86 RtlZeroMemory (VfatGlobalData, sizeof(VFAT_GLOBAL_DATA));
87 VfatGlobalData->DriverObject = DriverObject;
88 VfatGlobalData->DeviceObject = DeviceObject;
89
90 DeviceObject->Flags |= DO_DIRECT_IO;
91 DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest;
92 DriverObject->MajorFunction[IRP_MJ_CREATE] = VfatBuildRequest;
93 DriverObject->MajorFunction[IRP_MJ_READ] = VfatBuildRequest;
94 DriverObject->MajorFunction[IRP_MJ_WRITE] = VfatBuildRequest;
95 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = VfatBuildRequest;
96 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = VfatBuildRequest;
97 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = VfatBuildRequest;
98 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = VfatBuildRequest;
99 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = VfatBuildRequest;
100 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = VfatBuildRequest;
101 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;
102 DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = VfatBuildRequest;
103 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VfatBuildRequest;
104 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = VfatBuildRequest;
105 DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = VfatBuildRequest;
106 DriverObject->MajorFunction[IRP_MJ_PNP] = VfatBuildRequest;
107
108 DriverObject->DriverUnload = NULL;
109
110 /* Cache manager */
111 VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = VfatAcquireForLazyWrite;
112 VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = VfatReleaseFromLazyWrite;
113 VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead = VfatAcquireForReadAhead;
114 VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = VfatReleaseFromReadAhead;
115
116 /* Fast I/O */
117 VfatInitFastIoRoutines(&VfatGlobalData->FastIoDispatch);
118 DriverObject->FastIoDispatch = &VfatGlobalData->FastIoDispatch;
119
120 /* Private lists */
121 ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,
122 NULL, NULL, 0, sizeof(VFATFCB), TAG_FCB, 0);
123 ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,
124 NULL, NULL, 0, sizeof(VFATCCB), TAG_CCB, 0);
125 ExInitializeNPagedLookasideList(&VfatGlobalData->IrpContextLookasideList,
126 NULL, NULL, 0, sizeof(VFAT_IRP_CONTEXT), TAG_IRP, 0);
127
128 ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);
129 InitializeListHead(&VfatGlobalData->VolumeListHead);
130 IoRegisterFileSystem(DeviceObject);
131 return STATUS_SUCCESS;
132 }
133
134 /* EOF */