9faa5a12e24163c81df64e93d4b11cb461db1dce
[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/fs/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 /* GLOBALS ******************************************************************/
36
37 PCDFS_GLOBAL_DATA CdfsGlobalData;
38
39
40 /* FUNCTIONS ****************************************************************/
41
42 NTSTATUS NTAPI
43 DriverEntry(PDRIVER_OBJECT DriverObject,
44 PUNICODE_STRING RegistryPath)
45 /*
46 * FUNCTION: Called by the system to initialize the driver
47 * ARGUMENTS:
48 * DriverObject = object describing this driver
49 * RegistryPath = path to our configuration entries
50 * RETURNS: Success or failure
51 */
52 {
53 PDEVICE_OBJECT DeviceObject;
54 NTSTATUS Status;
55 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Cdfs");
56
57 UNREFERENCED_PARAMETER(RegistryPath);
58
59 DPRINT("CDFS 0.0.3\n");
60
61 Status = IoCreateDevice(DriverObject,
62 sizeof(CDFS_GLOBAL_DATA),
63 &DeviceName,
64 FILE_DEVICE_CD_ROM_FILE_SYSTEM,
65 0,
66 FALSE,
67 &DeviceObject);
68 if (!NT_SUCCESS(Status))
69 {
70 return(Status);
71 }
72
73 /* Initialize global data */
74 CdfsGlobalData = DeviceObject->DeviceExtension;
75 RtlZeroMemory(CdfsGlobalData,
76 sizeof(CDFS_GLOBAL_DATA));
77 CdfsGlobalData->DriverObject = DriverObject;
78 CdfsGlobalData->DeviceObject = DeviceObject;
79
80 /* Initialize driver data */
81 DeviceObject->Flags = DO_DIRECT_IO;
82 DriverObject->MajorFunction[IRP_MJ_CLOSE] = CdfsClose;
83 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = CdfsCleanup;
84 DriverObject->MajorFunction[IRP_MJ_CREATE] = CdfsCreate;
85 DriverObject->MajorFunction[IRP_MJ_READ] = CdfsRead;
86 DriverObject->MajorFunction[IRP_MJ_WRITE] = CdfsWrite;
87 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
88 CdfsFileSystemControl;
89 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
90 CdfsDirectoryControl;
91 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
92 CdfsQueryInformation;
93 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
94 CdfsSetInformation;
95 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
96 CdfsQueryVolumeInformation;
97 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] =
98 CdfsSetVolumeInformation;
99 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
100 CdfsDeviceControl;
101
102 CdfsGlobalData->FastIoDispatch.FastIoRead = CdfsFastIoRead;
103 CdfsGlobalData->FastIoDispatch.FastIoWrite = CdfsFastIoWrite;
104 DriverObject->FastIoDispatch = &CdfsGlobalData->FastIoDispatch;
105
106 DriverObject->DriverUnload = NULL;
107
108 /* Cache manager */
109 CdfsGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = CdfsAcquireForLazyWrite;
110 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = CdfsReleaseFromLazyWrite;
111 CdfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = CdfsAcquireForLazyWrite;
112 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = CdfsReleaseFromLazyWrite;
113
114 DeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
115
116 IoRegisterFileSystem(DeviceObject);
117 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
118
119 return(STATUS_SUCCESS);
120 }
121
122
123 BOOLEAN NTAPI
124 CdfsAcquireForLazyWrite(IN PVOID Context,
125 IN BOOLEAN Wait)
126 {
127 PFCB Fcb = (PFCB)Context;
128 ASSERT(Fcb);
129 DPRINT("CdfsAcquireForLazyWrite(): Fcb %p\n", Fcb);
130
131 if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))
132 {
133 DPRINT("CdfsAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");
134 return FALSE;
135 }
136 return TRUE;
137 }
138
139 VOID NTAPI
140 CdfsReleaseFromLazyWrite(IN PVOID Context)
141 {
142 PFCB Fcb = (PFCB)Context;
143 ASSERT(Fcb);
144 DPRINT("CdfsReleaseFromLazyWrite(): Fcb %p\n", Fcb);
145
146 ExReleaseResourceLite(&(Fcb->MainResource));
147 }
148
149 BOOLEAN
150 NTAPI
151 CdfsFastIoRead(
152 _In_ PFILE_OBJECT FileObject,
153 _In_ PLARGE_INTEGER FileOffset,
154 _In_ ULONG Length,
155 _In_ BOOLEAN Wait,
156 _In_ ULONG LockKey,
157 _Out_ PVOID Buffer,
158 _Out_ PIO_STATUS_BLOCK IoStatus,
159 _In_ PDEVICE_OBJECT DeviceObject)
160 {
161 DBG_UNREFERENCED_PARAMETER(FileObject);
162 DBG_UNREFERENCED_PARAMETER(FileOffset);
163 DBG_UNREFERENCED_PARAMETER(Length);
164 DBG_UNREFERENCED_PARAMETER(Wait);
165 DBG_UNREFERENCED_PARAMETER(LockKey);
166 DBG_UNREFERENCED_PARAMETER(Buffer);
167 DBG_UNREFERENCED_PARAMETER(IoStatus);
168 DBG_UNREFERENCED_PARAMETER(DeviceObject);
169 return FALSE;
170 }
171
172 BOOLEAN
173 NTAPI
174 CdfsFastIoWrite(
175 _In_ PFILE_OBJECT FileObject,
176 _In_ PLARGE_INTEGER FileOffset,
177 _In_ ULONG Length,
178 _In_ BOOLEAN Wait,
179 _In_ ULONG LockKey,
180 _In_ PVOID Buffer,
181 _Out_ PIO_STATUS_BLOCK IoStatus,
182 _In_ PDEVICE_OBJECT DeviceObject)
183 {
184 DBG_UNREFERENCED_PARAMETER(FileObject);
185 DBG_UNREFERENCED_PARAMETER(FileOffset);
186 DBG_UNREFERENCED_PARAMETER(Length);
187 DBG_UNREFERENCED_PARAMETER(Wait);
188 DBG_UNREFERENCED_PARAMETER(LockKey);
189 DBG_UNREFERENCED_PARAMETER(Buffer);
190 DBG_UNREFERENCED_PARAMETER(IoStatus);
191 DBG_UNREFERENCED_PARAMETER(DeviceObject);
192 return FALSE;
193 }