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.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/cdfs/cdfs.c
24 * PURPOSE: CDROM (ISO 9660) filesystem driver
25 * PROGRAMMER: Art Yerkes
29 /* INCLUDES *****************************************************************/
36 /* FUNCTIONS ****************************************************************/
39 CdfsMakeAbsoluteFilename(PFILE_OBJECT FileObject
,
40 PUNICODE_STRING RelativeFileName
,
41 PUNICODE_STRING AbsoluteFileName
)
47 DPRINT("try related for %wZ\n", RelativeFileName
);
48 Fcb
= FileObject
->FsContext
;
51 /* verify related object is a directory and target name
52 don't start with \. */
53 if ((Fcb
->Entry
.FileFlags
& FILE_FLAG_DIRECTORY
) == 0 ||
54 RelativeFileName
->Buffer
[0] == L
'\\')
56 return STATUS_INVALID_PARAMETER
;
59 /* construct absolute path name */
60 Length
= (wcslen(Fcb
->PathName
) * sizeof(WCHAR
)) +
62 RelativeFileName
->Length
+
64 AbsoluteFileName
->Length
= 0;
65 AbsoluteFileName
->MaximumLength
= Length
;
66 AbsoluteFileName
->Buffer
= ExAllocatePool(NonPagedPool
,
68 if (AbsoluteFileName
->Buffer
== NULL
)
70 return STATUS_INSUFFICIENT_RESOURCES
;
73 Status
= RtlAppendUnicodeToString(AbsoluteFileName
,
75 if (!NT_SUCCESS(Status
))
77 RtlFreeUnicodeString(AbsoluteFileName
);
81 if (!CdfsFCBIsRoot(Fcb
))
83 Status
= RtlAppendUnicodeToString(AbsoluteFileName
,
85 if (!NT_SUCCESS(Status
))
87 RtlFreeUnicodeString(AbsoluteFileName
);
92 Status
= RtlAppendUnicodeStringToString(AbsoluteFileName
,
94 if (!NT_SUCCESS(Status
))
96 RtlFreeUnicodeString(AbsoluteFileName
);
100 return STATUS_SUCCESS
;
105 * FUNCTION: Opens a file
108 CdfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
109 PFILE_OBJECT FileObject
,
110 PUNICODE_STRING FileName
)
115 UNICODE_STRING AbsFileName
;
117 DPRINT("CdfsOpenFile(%08lx, %08lx, %wZ)\n", DeviceExt
, FileObject
, FileName
);
119 if (FileObject
->RelatedFileObject
)
121 DPRINT("Converting relative filename to absolute filename\n");
123 Status
= CdfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
126 if (!NT_SUCCESS(Status
))
131 FileName
= &AbsFileName
;
134 Status
= CdfsDeviceIoControl (DeviceExt
->StorageDevice
,
135 IOCTL_CDROM_CHECK_VERIFY
,
141 DPRINT ("Status %lx\n", Status
);
142 if (!NT_SUCCESS(Status
))
144 if (Status
== STATUS_NO_MEDIA_IN_DEVICE
|| Status
== STATUS_VERIFY_REQUIRED
)
146 DeviceExt
->VolumeDevice
->Flags
|= DO_VERIFY_VOLUME
;
148 DPRINT1 ("Status %lx\n", Status
);
152 DPRINT("PathName to open: %wZ\n", FileName
);
154 /* try first to find an existing FCB in memory */
155 DPRINT("Checking for existing FCB in memory\n");
156 Fcb
= CdfsGrabFCBFromTable(DeviceExt
,
160 DPRINT("No existing FCB found, making a new one if file exists.\n");
161 Status
= CdfsGetFCBForFile(DeviceExt
,
165 if (ParentFcb
!= NULL
)
167 CdfsReleaseFCB(DeviceExt
,
171 if (!NT_SUCCESS (Status
))
173 DPRINT("Could not make a new FCB, status: %x\n", Status
);
175 if (FileName
== &AbsFileName
)
176 RtlFreeUnicodeString(&AbsFileName
);
182 DPRINT("Attaching FCB to fileObject\n");
183 Status
= CdfsAttachFCBToFileObject(DeviceExt
,
187 if ((FileName
== &AbsFileName
) && AbsFileName
.Buffer
)
188 ExFreePool(AbsFileName
.Buffer
);
195 * FUNCTION: Opens a file
198 CdfsCreateFile(PDEVICE_OBJECT DeviceObject
,
201 PDEVICE_EXTENSION DeviceExt
;
202 PIO_STACK_LOCATION Stack
;
203 PFILE_OBJECT FileObject
;
204 ULONG RequestedDisposition
;
205 ULONG RequestedOptions
;
209 DPRINT("CdfsCreateFile() called\n");
211 DeviceExt
= DeviceObject
->DeviceExtension
;
213 Stack
= IoGetCurrentIrpStackLocation (Irp
);
216 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
217 RequestedOptions
= Stack
->Parameters
.Create
.Options
& FILE_VALID_OPTION_FLAGS
;
218 DPRINT("RequestedDisposition %x, RequestedOptions %x\n",
219 RequestedDisposition
, RequestedOptions
);
221 FileObject
= Stack
->FileObject
;
223 if (RequestedDisposition
== FILE_CREATE
||
224 RequestedDisposition
== FILE_OVERWRITE_IF
||
225 RequestedDisposition
== FILE_SUPERSEDE
)
227 return STATUS_ACCESS_DENIED
;
230 Status
= CdfsOpenFile(DeviceExt
,
232 &FileObject
->FileName
);
233 if (NT_SUCCESS(Status
))
235 Fcb
= FileObject
->FsContext
;
237 /* Check whether the file has the requested attributes */
238 if (RequestedOptions
& FILE_NON_DIRECTORY_FILE
&& CdfsFCBIsDirectory(Fcb
))
240 CdfsCloseFile (DeviceExt
, FileObject
);
241 return STATUS_FILE_IS_A_DIRECTORY
;
244 if (RequestedOptions
& FILE_DIRECTORY_FILE
&& !CdfsFCBIsDirectory(Fcb
))
246 CdfsCloseFile (DeviceExt
, FileObject
);
247 return STATUS_NOT_A_DIRECTORY
;
252 * If the directory containing the file to open doesn't exist then
255 Irp
->IoStatus
.Information
= (NT_SUCCESS(Status
)) ? FILE_OPENED
: 0;
256 Irp
->IoStatus
.Status
= Status
;
263 CdfsCreate(PDEVICE_OBJECT DeviceObject
,
266 PDEVICE_EXTENSION DeviceExt
;
269 if (DeviceObject
== CdfsGlobalData
->DeviceObject
)
271 /* DeviceObject represents FileSystem instead of logical volume */
272 DPRINT("Opening file system\n");
273 Irp
->IoStatus
.Information
= FILE_OPENED
;
274 Status
= STATUS_SUCCESS
;
278 DeviceExt
= DeviceObject
->DeviceExtension
;
280 KeEnterCriticalRegion();
281 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
283 Status
= CdfsCreateFile(DeviceObject
,
285 ExReleaseResourceLite(&DeviceExt
->DirResource
);
286 KeLeaveCriticalRegion();
289 Irp
->IoStatus
.Status
= Status
;
290 IoCompleteRequest(Irp
,
291 NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);