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