5be1d5c957afeab6930ea4af89c72bce686cd77d
[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 initalize 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 DPRINT("CDFS 0.0.3\n");
58
59 Status = IoCreateDevice(DriverObject,
60 sizeof(CDFS_GLOBAL_DATA),
61 &DeviceName,
62 FILE_DEVICE_CD_ROM_FILE_SYSTEM,
63 0,
64 FALSE,
65 &DeviceObject);
66 if (!NT_SUCCESS(Status))
67 {
68 return(Status);
69 }
70
71 /* Initialize global data */
72 CdfsGlobalData = DeviceObject->DeviceExtension;
73 RtlZeroMemory(CdfsGlobalData,
74 sizeof(CDFS_GLOBAL_DATA));
75 CdfsGlobalData->DriverObject = DriverObject;
76 CdfsGlobalData->DeviceObject = DeviceObject;
77
78 /* Initialize driver data */
79 DeviceObject->Flags = DO_DIRECT_IO;
80 DriverObject->MajorFunction[IRP_MJ_CLOSE] = CdfsClose;
81 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = CdfsCleanup;
82 DriverObject->MajorFunction[IRP_MJ_CREATE] = CdfsCreate;
83 DriverObject->MajorFunction[IRP_MJ_READ] = CdfsRead;
84 DriverObject->MajorFunction[IRP_MJ_WRITE] = CdfsWrite;
85 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
86 CdfsFileSystemControl;
87 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
88 CdfsDirectoryControl;
89 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
90 CdfsQueryInformation;
91 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
92 CdfsSetInformation;
93 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
94 CdfsQueryVolumeInformation;
95 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] =
96 CdfsSetVolumeInformation;
97 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
98 CdfsDeviceControl;
99
100 DriverObject->DriverUnload = NULL;
101
102 /* Cache manager */
103 CdfsGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = CdfsAcquireForLazyWrite;
104 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = CdfsReleaseFromLazyWrite;
105 CdfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = CdfsAcquireForLazyWrite;
106 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = CdfsReleaseFromLazyWrite;
107
108 DeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
109
110 IoRegisterFileSystem(DeviceObject);
111 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
112
113 return(STATUS_SUCCESS);
114 }
115
116
117 BOOLEAN NTAPI
118 CdfsAcquireForLazyWrite(IN PVOID Context,
119 IN BOOLEAN Wait)
120 {
121 PFCB Fcb = (PFCB)Context;
122 ASSERT(Fcb);
123 DPRINT("CdfsAcquireForLazyWrite(): Fcb %p\n", Fcb);
124
125 if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))
126 {
127 DPRINT("CdfsAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");
128 return FALSE;
129 }
130 return TRUE;
131 }
132
133 VOID NTAPI
134 CdfsReleaseFromLazyWrite(IN PVOID Context)
135 {
136 PFCB Fcb = (PFCB)Context;
137 ASSERT(Fcb);
138 DPRINT("CdfsReleaseFromLazyWrite(): Fcb %p\n", Fcb);
139
140 ExReleaseResourceLite(&(Fcb->MainResource));
141 }