fixed warnings when compiled with -Wmissing-declarations
[reactos.git] / reactos / drivers / fs / fs_rec / fs_rec.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002,2003 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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: drivers/fs/fs_rec/fs_rec.c
23 * PURPOSE: Filesystem recognizer driver
24 * PROGRAMMER: Eric Kohl
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #define NDEBUG
30 #include <debug.h>
31
32 #include "fs_rec.h"
33
34
35 /* FUNCTIONS ****************************************************************/
36
37 static NTSTATUS STDCALL
38 FsRecCreate(IN PDEVICE_OBJECT DeviceObject,
39 IN PIRP Irp)
40 {
41 NTSTATUS Status;
42
43
44 Status = STATUS_SUCCESS;
45
46
47 Irp->IoStatus.Status = Status;
48 IoCompleteRequest(Irp,
49 IO_NO_INCREMENT);
50
51 return(Status);
52 }
53
54
55 static NTSTATUS STDCALL
56 FsRecClose(IN PDEVICE_OBJECT DeviceObject,
57 IN PIRP Irp)
58 {
59 Irp->IoStatus.Status = STATUS_SUCCESS;
60 IoCompleteRequest(Irp,
61 IO_NO_INCREMENT);
62
63 return(STATUS_SUCCESS);
64 }
65
66
67 static NTSTATUS STDCALL
68 FsRecFsControl(IN PDEVICE_OBJECT DeviceObject,
69 IN PIRP Irp)
70 {
71 PDEVICE_EXTENSION DeviceExt;
72 NTSTATUS Status;
73
74 DeviceExt = DeviceObject->DeviceExtension;
75 switch (DeviceExt->FsType)
76 {
77 case FS_TYPE_VFAT:
78 Status = FsRecVfatFsControl(DeviceObject, Irp);
79 break;
80
81 case FS_TYPE_NTFS:
82 Status = FsRecNtfsFsControl(DeviceObject, Irp);
83 break;
84
85 case FS_TYPE_CDFS:
86 Status = FsRecCdfsFsControl(DeviceObject, Irp);
87 break;
88
89 case FS_TYPE_UDFS:
90 Status = FsRecUdfsFsControl(DeviceObject, Irp);
91 break;
92
93 default:
94 Status = STATUS_INVALID_DEVICE_REQUEST;
95 }
96
97 Irp->IoStatus.Status = Status;
98 IoCompleteRequest(Irp,
99 IO_NO_INCREMENT);
100
101 return(Status);
102 }
103
104
105 static VOID STDCALL
106 FsRecUnload(IN PDRIVER_OBJECT DriverObject)
107 {
108 PDEVICE_OBJECT NextDevice;
109 PDEVICE_OBJECT ThisDevice;
110
111 /* Delete all remaining device objects */
112 NextDevice = DriverObject->DeviceObject;
113 while (NextDevice != NULL)
114 {
115 ThisDevice = NextDevice;
116 NextDevice = NextDevice->NextDevice;
117 IoDeleteDevice(ThisDevice);
118 }
119 }
120
121
122 static NTSTATUS
123 FsRecRegisterFs(PDRIVER_OBJECT DriverObject,
124 PWSTR FsName,
125 PWSTR RecognizerName,
126 ULONG DeviceType,
127 ULONG FsType)
128 {
129 OBJECT_ATTRIBUTES ObjectAttributes;
130 IO_STATUS_BLOCK IoStatus;
131 PDEVICE_EXTENSION DeviceExt;
132 UNICODE_STRING DeviceName;
133 UNICODE_STRING FileName;
134 PDEVICE_OBJECT DeviceObject;
135 HANDLE FileHandle;
136 NTSTATUS Status;
137
138 RtlInitUnicodeString(&FileName,
139 FsName);
140
141 InitializeObjectAttributes(&ObjectAttributes,
142 &FileName,
143 OBJ_CASE_INSENSITIVE,
144 0,
145 NULL);
146
147 Status = ZwCreateFile(&FileHandle,
148 0x100000,
149 &ObjectAttributes,
150 &IoStatus,
151 NULL,
152 0,
153 FILE_SHARE_READ | FILE_SHARE_WRITE,
154 FILE_OPEN,
155 0,
156 NULL,
157 0);
158 if (NT_SUCCESS(Status))
159 {
160 ZwClose(FileHandle);
161 return(STATUS_IMAGE_ALREADY_LOADED);
162 }
163
164 /* Create recognizer device object */
165 RtlInitUnicodeString(&DeviceName,
166 RecognizerName);
167
168 Status = IoCreateDevice(DriverObject,
169 sizeof(DEVICE_EXTENSION),
170 &DeviceName,
171 DeviceType,
172 0,
173 FALSE,
174 &DeviceObject);
175
176 if (NT_SUCCESS(Status))
177 {
178 DeviceExt = DeviceObject->DeviceExtension;
179 DeviceExt->FsType = FsType;
180 IoRegisterFileSystem(DeviceObject);
181 DPRINT("Created recognizer device '%wZ'\n", &DeviceName);
182 }
183
184 return(Status);
185 }
186
187
188 NTSTATUS STDCALL
189 DriverEntry(PDRIVER_OBJECT DriverObject,
190 PUNICODE_STRING RegistryPath)
191 {
192 PCONFIGURATION_INFORMATION ConfigInfo;
193 ULONG DeviceCount;
194 NTSTATUS Status;
195
196 DPRINT("FileSystem recognizer 0.0.2\n");
197
198 DeviceCount = 0;
199
200 DriverObject->MajorFunction[IRP_MJ_CREATE] = FsRecCreate;
201 DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsRecClose;
202 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = FsRecClose;
203 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = FsRecFsControl;
204 DriverObject->DriverUnload = FsRecUnload;
205
206 ConfigInfo = IoGetConfigurationInformation();
207
208 if (ConfigInfo->CdRomCount > 0)
209 {
210 Status = FsRecRegisterFs(DriverObject,
211 L"\\Cdfs",
212 L"\\FileSystem\\CdfsRecognizer",
213 FILE_DEVICE_CD_ROM_FILE_SYSTEM,
214 FS_TYPE_CDFS);
215 if (NT_SUCCESS(Status))
216 {
217 DeviceCount++;
218 }
219
220 Status = FsRecRegisterFs(DriverObject,
221 L"\\Udfs",
222 L"\\FileSystem\\UdfsRecognizer",
223 FILE_DEVICE_CD_ROM_FILE_SYSTEM,
224 FS_TYPE_UDFS);
225 if (NT_SUCCESS(Status))
226 {
227 DeviceCount++;
228 }
229 }
230
231 Status = FsRecRegisterFs(DriverObject,
232 L"\\Fat",
233 L"\\FileSystem\\FatRecognizer",
234 FILE_DEVICE_DISK_FILE_SYSTEM,
235 FS_TYPE_VFAT);
236 if (NT_SUCCESS(Status))
237 {
238 DeviceCount++;
239 }
240
241 Status = FsRecRegisterFs(DriverObject,
242 L"\\Ntfs",
243 L"\\FileSystem\\NtfsRecognizer",
244 FILE_DEVICE_DISK_FILE_SYSTEM,
245 FS_TYPE_NTFS);
246 if (NT_SUCCESS(Status))
247 {
248 DeviceCount++;
249 }
250
251 return((DeviceCount > 0) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL);
252 }
253
254 /* EOF */