Fix the FSDs to use the INIT_SECTION-style and add the alloc_text-s required for...
[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 #if defined(ALLOC_PRAGMA)
34 #pragma alloc_text(INIT, DriverEntry)
35 #endif
36
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_SECTION
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
95 DeviceObject->Flags |= DO_DIRECT_IO;
96 DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest;
97 DriverObject->MajorFunction[IRP_MJ_CREATE] = VfatBuildRequest;
98 DriverObject->MajorFunction[IRP_MJ_READ] = VfatBuildRequest;
99 DriverObject->MajorFunction[IRP_MJ_WRITE] = VfatBuildRequest;
100 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = VfatBuildRequest;
101 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = VfatBuildRequest;
102 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = VfatBuildRequest;
103 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = VfatBuildRequest;
104 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = VfatBuildRequest;
105 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = VfatBuildRequest;
106 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;
107 DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = VfatBuildRequest;
108 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VfatBuildRequest;
109 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = VfatBuildRequest;
110 DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = VfatBuildRequest;
111 DriverObject->MajorFunction[IRP_MJ_PNP] = VfatBuildRequest;
112
113 DriverObject->DriverUnload = NULL;
114
115 /* Cache manager */
116 VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = VfatAcquireForLazyWrite;
117 VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = VfatReleaseFromLazyWrite;
118 VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead = VfatAcquireForReadAhead;
119 VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = VfatReleaseFromReadAhead;
120
121 /* Fast I/O */
122 VfatInitFastIoRoutines(&VfatGlobalData->FastIoDispatch);
123 DriverObject->FastIoDispatch = &VfatGlobalData->FastIoDispatch;
124
125 /* Private lists */
126 ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,
127 NULL, NULL, 0, sizeof(VFATFCB), TAG_FCB, 0);
128 ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,
129 NULL, NULL, 0, sizeof(VFATCCB), TAG_CCB, 0);
130 ExInitializeNPagedLookasideList(&VfatGlobalData->IrpContextLookasideList,
131 NULL, NULL, 0, sizeof(VFAT_IRP_CONTEXT), TAG_IRP, 0);
132
133 ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);
134 InitializeListHead(&VfatGlobalData->VolumeListHead);
135 IoRegisterFileSystem(DeviceObject);
136 return STATUS_SUCCESS;
137 }
138
139 /* EOF */