[CDFS]
[reactos.git] / reactos / drivers / filesystems / cdfs / cdfs.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 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 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
22 * FILE: drivers/filesystems/cdfs/cdfs.c
23 * PURPOSE: CDROM (ISO 9660) filesystem driver
24 * PROGRAMMER: Art Yerkes
25 * Eric Kohl
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include "cdfs.h"
31
32 #define NDEBUG
33 #include <debug.h>
34
35 #if defined(ALLOC_PRAGMA)
36 #pragma alloc_text(INIT, DriverEntry)
37 #endif
38
39 /* GLOBALS ******************************************************************/
40
41 PCDFS_GLOBAL_DATA CdfsGlobalData;
42
43
44 /* FUNCTIONS ****************************************************************/
45
46 INIT_SECTION
47 NTSTATUS NTAPI
48 DriverEntry(PDRIVER_OBJECT DriverObject,
49 PUNICODE_STRING RegistryPath)
50 /*
51 * FUNCTION: Called by the system to initialize the driver
52 * ARGUMENTS:
53 * DriverObject = object describing this driver
54 * RegistryPath = path to our configuration entries
55 * RETURNS: Success or failure
56 */
57 {
58 NTSTATUS Status;
59 PDEVICE_OBJECT CdFsDeviceObject;
60 PDEVICE_OBJECT HddFsDeviceObject;
61 UNICODE_STRING CdFsDeviceName = RTL_CONSTANT_STRING(L"\\Cdfs");
62 UNICODE_STRING HddFsDeviceName = RTL_CONSTANT_STRING(L"\\CdfsHdd");
63
64 UNREFERENCED_PARAMETER(RegistryPath);
65
66 DPRINT("CDFS 0.0.3\n");
67
68 Status = IoCreateDevice(DriverObject,
69 sizeof(CDFS_GLOBAL_DATA),
70 &CdFsDeviceName,
71 FILE_DEVICE_CD_ROM_FILE_SYSTEM,
72 0,
73 FALSE,
74 &CdFsDeviceObject);
75 if (!NT_SUCCESS(Status))
76 {
77 return(Status);
78 }
79
80 Status = IoCreateDevice(DriverObject,
81 0,
82 &HddFsDeviceName,
83 FILE_DEVICE_DISK_FILE_SYSTEM,
84 0,
85 FALSE,
86 &HddFsDeviceObject);
87 if (!NT_SUCCESS(Status))
88 {
89 return(Status);
90 }
91
92 /* Initialize global data */
93 CdfsGlobalData = CdFsDeviceObject->DeviceExtension;
94 RtlZeroMemory(CdfsGlobalData,
95 sizeof(CDFS_GLOBAL_DATA));
96 CdfsGlobalData->DriverObject = DriverObject;
97 CdfsGlobalData->CdFsDeviceObject = CdFsDeviceObject;
98 CdfsGlobalData->HddFsDeviceObject = HddFsDeviceObject;
99 HddFsDeviceObject->DeviceExtension = CdfsGlobalData;
100
101 /* Initialize driver data */
102 DriverObject->MajorFunction[IRP_MJ_CLOSE] = CdfsFsdDispatch;
103 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = CdfsFsdDispatch;
104 DriverObject->MajorFunction[IRP_MJ_CREATE] = CdfsFsdDispatch;
105 DriverObject->MajorFunction[IRP_MJ_READ] = CdfsFsdDispatch;
106 DriverObject->MajorFunction[IRP_MJ_WRITE] = CdfsFsdDispatch;
107 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = CdfsFsdDispatch;
108 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = CdfsFsdDispatch;
109 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = CdfsFsdDispatch;
110 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = CdfsFsdDispatch;
111 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = CdfsFsdDispatch;
112 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = CdfsFsdDispatch;
113 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = CdfsFsdDispatch;
114 DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = CdfsFsdDispatch;
115
116 CdfsGlobalData->FastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
117 CdfsGlobalData->FastIoDispatch.FastIoCheckIfPossible = CdfsFastIoCheckIfPossible;
118 CdfsGlobalData->FastIoDispatch.FastIoRead = CdfsFastIoRead;
119 CdfsGlobalData->FastIoDispatch.FastIoWrite = CdfsFastIoWrite;
120 DriverObject->FastIoDispatch = &CdfsGlobalData->FastIoDispatch;
121
122 /* Initialize lookaside list for IRP contexts */
123 ExInitializeNPagedLookasideList(&CdfsGlobalData->IrpContextLookasideList,
124 NULL, NULL, 0, sizeof(CDFS_IRP_CONTEXT), 'PRIC', 0);
125
126 DriverObject->DriverUnload = NULL;
127
128 /* Cache manager */
129 CdfsGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = CdfsAcquireForLazyWrite;
130 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = CdfsReleaseFromLazyWrite;
131 CdfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = CdfsAcquireForLazyWrite;
132 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = CdfsReleaseFromLazyWrite;
133
134 CdFsDeviceObject->Flags |= DO_DIRECT_IO | DO_LOW_PRIORITY_FILESYSTEM;
135 HddFsDeviceObject->Flags |= DO_DIRECT_IO | DO_LOW_PRIORITY_FILESYSTEM;
136
137 IoRegisterFileSystem(CdFsDeviceObject);
138 IoRegisterFileSystem(HddFsDeviceObject);
139
140 return(STATUS_SUCCESS);
141 }