3 * Copyright (C) 2002, 2003, 2004 ReactOS Team
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.
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.
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.
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
28 /* INCLUDES *****************************************************************/
35 /* FUNCTIONS ****************************************************************/
38 CdfsMakeAbsoluteFilename(PFILE_OBJECT FileObject
,
39 PUNICODE_STRING RelativeFileName
,
40 PUNICODE_STRING AbsoluteFileName
)
46 DPRINT("try related for %wZ\n", RelativeFileName
);
47 Fcb
= FileObject
->FsContext
;
50 /* verify related object is a directory and target name
51 don't start with \. */
52 if ((Fcb
->Entry
.FileFlags
& FILE_FLAG_DIRECTORY
) == 0 ||
53 RelativeFileName
->Buffer
[0] == L
'\\')
55 return STATUS_INVALID_PARAMETER
;
58 /* construct absolute path name */
59 Length
= Fcb
->PathName
.Length
+
61 RelativeFileName
->Length
+
63 AbsoluteFileName
->Length
= 0;
64 AbsoluteFileName
->MaximumLength
= Length
;
65 AbsoluteFileName
->Buffer
= ExAllocatePoolWithTag(NonPagedPool
, Length
, CDFS_FILENAME_TAG
);
66 if (AbsoluteFileName
->Buffer
== NULL
)
68 return STATUS_INSUFFICIENT_RESOURCES
;
71 Status
= RtlAppendUnicodeStringToString(AbsoluteFileName
,
73 if (!NT_SUCCESS(Status
))
75 RtlFreeUnicodeString(AbsoluteFileName
);
79 if (!CdfsFCBIsRoot(Fcb
))
81 Status
= RtlAppendUnicodeToString(AbsoluteFileName
,
83 if (!NT_SUCCESS(Status
))
85 RtlFreeUnicodeString(AbsoluteFileName
);
90 Status
= RtlAppendUnicodeStringToString(AbsoluteFileName
,
92 if (!NT_SUCCESS(Status
))
94 RtlFreeUnicodeString(AbsoluteFileName
);
98 return STATUS_SUCCESS
;
103 * FUNCTION: Opens a file
106 CdfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
107 PFILE_OBJECT FileObject
,
108 PUNICODE_STRING FileName
)
113 UNICODE_STRING AbsFileName
;
115 DPRINT("CdfsOpenFile(%p, %p, %wZ)\n", DeviceExt
, FileObject
, FileName
);
117 if (FileObject
->RelatedFileObject
)
119 DPRINT("Converting relative filename to absolute filename\n");
121 Status
= CdfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
124 if (!NT_SUCCESS(Status
))
129 FileName
= &AbsFileName
;
132 Status
= CdfsDeviceIoControl (DeviceExt
->StorageDevice
,
133 IOCTL_CDROM_CHECK_VERIFY
,
139 DPRINT ("Status %lx\n", Status
);
140 if (!NT_SUCCESS(Status
))
142 DPRINT1 ("Status %lx\n", Status
);
146 DPRINT("PathName to open: %wZ\n", FileName
);
148 /* try first to find an existing FCB in memory */
149 DPRINT("Checking for existing FCB in memory\n");
150 Fcb
= CdfsGrabFCBFromTable(DeviceExt
,
154 DPRINT("No existing FCB found, making a new one if file exists.\n");
155 Status
= CdfsGetFCBForFile(DeviceExt
,
159 if (ParentFcb
!= NULL
)
161 CdfsReleaseFCB(DeviceExt
,
165 if (!NT_SUCCESS (Status
))
167 DPRINT("Could not make a new FCB, status: %x\n", Status
);
169 if (FileName
== &AbsFileName
)
170 RtlFreeUnicodeString(&AbsFileName
);
176 DPRINT("Attaching FCB to fileObject\n");
177 Status
= CdfsAttachFCBToFileObject(DeviceExt
,
181 if ((FileName
== &AbsFileName
) && AbsFileName
.Buffer
)
182 ExFreePoolWithTag(AbsFileName
.Buffer
, CDFS_FILENAME_TAG
);
189 * FUNCTION: Opens a file
192 CdfsCreateFile(PDEVICE_OBJECT DeviceObject
,
195 PDEVICE_EXTENSION DeviceExt
;
196 PIO_STACK_LOCATION Stack
;
197 PFILE_OBJECT FileObject
;
198 ULONG RequestedDisposition
;
199 ULONG RequestedOptions
;
203 DPRINT("CdfsCreateFile() called\n");
205 DeviceExt
= DeviceObject
->DeviceExtension
;
207 Stack
= IoGetCurrentIrpStackLocation (Irp
);
210 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
211 RequestedOptions
= Stack
->Parameters
.Create
.Options
& FILE_VALID_OPTION_FLAGS
;
212 DPRINT("RequestedDisposition %x, RequestedOptions %x\n",
213 RequestedDisposition
, RequestedOptions
);
215 FileObject
= Stack
->FileObject
;
217 if (RequestedDisposition
== FILE_CREATE
||
218 RequestedDisposition
== FILE_OVERWRITE_IF
||
219 RequestedDisposition
== FILE_SUPERSEDE
)
221 return STATUS_ACCESS_DENIED
;
224 Status
= CdfsOpenFile(DeviceExt
,
226 &FileObject
->FileName
);
227 if (NT_SUCCESS(Status
))
229 Fcb
= FileObject
->FsContext
;
231 /* Check whether the file has the requested attributes */
232 if (RequestedOptions
& FILE_NON_DIRECTORY_FILE
&& CdfsFCBIsDirectory(Fcb
))
234 CdfsCloseFile (DeviceExt
, FileObject
);
235 return STATUS_FILE_IS_A_DIRECTORY
;
238 if (RequestedOptions
& FILE_DIRECTORY_FILE
&& !CdfsFCBIsDirectory(Fcb
))
240 CdfsCloseFile (DeviceExt
, FileObject
);
241 return STATUS_NOT_A_DIRECTORY
;
246 * If the directory containing the file to open doesn't exist then
249 Irp
->IoStatus
.Information
= (NT_SUCCESS(Status
)) ? FILE_OPENED
: 0;
257 PCDFS_IRP_CONTEXT IrpContext
)
259 PDEVICE_OBJECT DeviceObject
;
260 PDEVICE_EXTENSION DeviceExt
;
263 DPRINT("CdfsCreate()\n");
267 DeviceObject
= IrpContext
->DeviceObject
;
268 if (DeviceObject
== CdfsGlobalData
->DeviceObject
)
270 /* DeviceObject represents FileSystem instead of logical volume */
271 DPRINT("Opening file system\n");
272 IrpContext
->Irp
->IoStatus
.Information
= FILE_OPENED
;
273 return STATUS_SUCCESS
;
276 DeviceExt
= DeviceObject
->DeviceExtension
;
278 KeEnterCriticalRegion();
279 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
281 Status
= CdfsCreateFile(DeviceObject
,
283 ExReleaseResourceLite(&DeviceExt
->DirResource
);
284 KeLeaveCriticalRegion();