[CMAKE]
[reactos.git] / 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 /* $Id$
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: drivers/fs/cdfs/cdfs.c
24 * PURPOSE: CDROM (ISO 9660) filesystem driver
25 * PROGRAMMER: Art Yerkes
26 * Eric Kohl
27 */
28
29 /* INCLUDES *****************************************************************/
30
31 #include "cdfs.h"
32
33 #define NDEBUG
34 #include <debug.h>
35
36 /* GLOBALS ******************************************************************/
37
38 PCDFS_GLOBAL_DATA CdfsGlobalData;
39
40
41 /* FUNCTIONS ****************************************************************/
42
43 NTSTATUS NTAPI
44 DriverEntry(PDRIVER_OBJECT DriverObject,
45 PUNICODE_STRING RegistryPath)
46 /*
47 * FUNCTION: Called by the system to initalize the driver
48 * ARGUMENTS:
49 * DriverObject = object describing this driver
50 * RegistryPath = path to our configuration entries
51 * RETURNS: Success or failure
52 */
53 {
54 PDEVICE_OBJECT DeviceObject;
55 NTSTATUS Status;
56 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Cdfs");
57
58 DPRINT("CDFS 0.0.3\n");
59
60 Status = IoCreateDevice(DriverObject,
61 sizeof(CDFS_GLOBAL_DATA),
62 &DeviceName,
63 FILE_DEVICE_CD_ROM_FILE_SYSTEM,
64 0,
65 FALSE,
66 &DeviceObject);
67 if (!NT_SUCCESS(Status))
68 {
69 return(Status);
70 }
71
72 /* Initialize global data */
73 CdfsGlobalData = DeviceObject->DeviceExtension;
74 RtlZeroMemory(CdfsGlobalData,
75 sizeof(CDFS_GLOBAL_DATA));
76 CdfsGlobalData->DriverObject = DriverObject;
77 CdfsGlobalData->DeviceObject = DeviceObject;
78
79 /* Initialize driver data */
80 DeviceObject->Flags = DO_DIRECT_IO;
81 DriverObject->MajorFunction[IRP_MJ_CLOSE] = CdfsClose;
82 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = CdfsCleanup;
83 DriverObject->MajorFunction[IRP_MJ_CREATE] = CdfsCreate;
84 DriverObject->MajorFunction[IRP_MJ_READ] = CdfsRead;
85 DriverObject->MajorFunction[IRP_MJ_WRITE] = CdfsWrite;
86 DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] =
87 CdfsFileSystemControl;
88 DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] =
89 CdfsDirectoryControl;
90 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
91 CdfsQueryInformation;
92 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
93 CdfsSetInformation;
94 DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] =
95 CdfsQueryVolumeInformation;
96 DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] =
97 CdfsSetVolumeInformation;
98 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
99 CdfsDeviceControl;
100
101 DriverObject->DriverUnload = NULL;
102
103 /* Cache manager */
104 CdfsGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = CdfsAcquireForLazyWrite;
105 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = CdfsReleaseFromLazyWrite;
106 CdfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = CdfsAcquireForLazyWrite;
107 CdfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = CdfsReleaseFromLazyWrite;
108
109 DeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
110
111 IoRegisterFileSystem(DeviceObject);
112 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
113
114 return(STATUS_SUCCESS);
115 }
116
117
118 BOOLEAN NTAPI
119 CdfsAcquireForLazyWrite(IN PVOID Context,
120 IN BOOLEAN Wait)
121 {
122 PFCB Fcb = (PFCB)Context;
123 ASSERT(Fcb);
124 DPRINT("CdfsAcquireForLazyWrite(): Fcb %p\n", Fcb);
125
126 if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))
127 {
128 DPRINT("CdfsAcquireForLazyWrite(): ExReleaseResourceLite failed.\n");
129 return FALSE;
130 }
131 return TRUE;
132 }
133
134 VOID NTAPI
135 CdfsReleaseFromLazyWrite(IN PVOID Context)
136 {
137 PFCB Fcb = (PFCB)Context;
138 ASSERT(Fcb);
139 DPRINT("CdfsReleaseFromLazyWrite(): Fcb %p\n", Fcb);
140
141 ExReleaseResourceLite(&(Fcb->MainResource));
142 }