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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 *****************************************************************/
31 #include <ddk/ntddk.h>
39 /* FUNCTIONS ****************************************************************/
42 CdfsMakeAbsoluteFilename(PFILE_OBJECT FileObject
,
43 PUNICODE_STRING RelativeFileName
,
44 PUNICODE_STRING AbsoluteFileName
)
50 DPRINT("try related for %wZ\n", RelativeFileName
);
51 Fcb
= FileObject
->FsContext
;
54 /* verify related object is a directory and target name
55 don't start with \. */
56 if ((Fcb
->Entry
.FileFlags
& FILE_FLAG_DIRECTORY
) == 0 ||
57 RelativeFileName
->Buffer
[0] == L
'\\')
59 return STATUS_INVALID_PARAMETER
;
62 /* construct absolute path name */
63 Length
= (wcslen(Fcb
->PathName
) * sizeof(WCHAR
)) +
65 RelativeFileName
->Length
+
67 AbsoluteFileName
->Length
= 0;
68 AbsoluteFileName
->MaximumLength
= Length
;
69 AbsoluteFileName
->Buffer
= ExAllocatePool(NonPagedPool
,
71 if (AbsoluteFileName
->Buffer
== NULL
)
73 return STATUS_INSUFFICIENT_RESOURCES
;
76 Status
= RtlAppendUnicodeToString(AbsoluteFileName
,
78 if (!NT_SUCCESS(Status
))
80 RtlFreeUnicodeString(AbsoluteFileName
);
84 if (!CdfsFCBIsRoot(Fcb
))
86 Status
= RtlAppendUnicodeToString(AbsoluteFileName
,
88 if (!NT_SUCCESS(Status
))
90 RtlFreeUnicodeString(AbsoluteFileName
);
95 Status
= RtlAppendUnicodeStringToString(AbsoluteFileName
,
97 if (!NT_SUCCESS(Status
))
99 RtlFreeUnicodeString(AbsoluteFileName
);
103 return STATUS_SUCCESS
;
108 * FUNCTION: Opens a file
111 CdfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
112 PFILE_OBJECT FileObject
,
113 PUNICODE_STRING FileName
)
118 UNICODE_STRING AbsFileName
;
120 DPRINT("CdfsOpenFile(%08lx, %08lx, %wZ)\n", DeviceExt
, FileObject
, FileName
);
122 if (FileObject
->RelatedFileObject
)
124 DPRINT("Converting relative filename to absolute filename\n");
126 Status
= CdfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
129 if (!NT_SUCCESS(Status
))
134 FileName
= &AbsFileName
;
137 Status
= CdfsDeviceIoControl (DeviceExt
->StorageDevice
,
138 IOCTL_CDROM_CHECK_VERIFY
,
144 DPRINT ("Status %lx\n", Status
);
145 if (!NT_SUCCESS(Status
))
147 DPRINT1 ("Status %lx\n", Status
);
151 DPRINT("PathName to open: %wZ\n", FileName
);
153 /* try first to find an existing FCB in memory */
154 DPRINT("Checking for existing FCB in memory\n");
155 Fcb
= CdfsGrabFCBFromTable(DeviceExt
,
159 DPRINT("No existing FCB found, making a new one if file exists.\n");
160 Status
= CdfsGetFCBForFile(DeviceExt
,
164 if (ParentFcb
!= NULL
)
166 CdfsReleaseFCB(DeviceExt
,
170 if (!NT_SUCCESS (Status
))
172 DPRINT("Could not make a new FCB, status: %x\n", Status
);
174 if (FileName
== &AbsFileName
)
175 RtlFreeUnicodeString(&AbsFileName
);
181 DPRINT("Attaching FCB to fileObject\n");
182 Status
= CdfsAttachFCBToFileObject(DeviceExt
,
186 if ((FileName
== &AbsFileName
) && AbsFileName
.Buffer
)
187 ExFreePool(AbsFileName
.Buffer
);
194 * FUNCTION: Opens a file
197 CdfsCreateFile(PDEVICE_OBJECT DeviceObject
,
200 PDEVICE_EXTENSION DeviceExt
;
201 PIO_STACK_LOCATION Stack
;
202 PFILE_OBJECT FileObject
;
203 ULONG RequestedDisposition
;
204 ULONG RequestedOptions
;
208 DPRINT("CdfsCreateFile() called\n");
210 DeviceExt
= DeviceObject
->DeviceExtension
;
212 Stack
= IoGetCurrentIrpStackLocation (Irp
);
215 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
216 RequestedOptions
= Stack
->Parameters
.Create
.Options
& FILE_VALID_OPTION_FLAGS
;
217 DPRINT("RequestedDisposition %x, RequestedOptions %x\n",
218 RequestedDisposition
, RequestedOptions
);
220 FileObject
= Stack
->FileObject
;
222 if (RequestedDisposition
== FILE_CREATE
||
223 RequestedDisposition
== FILE_OVERWRITE_IF
||
224 RequestedDisposition
== FILE_SUPERSEDE
)
226 return STATUS_ACCESS_DENIED
;
229 Status
= CdfsOpenFile(DeviceExt
,
231 &FileObject
->FileName
);
232 if (NT_SUCCESS(Status
))
234 Fcb
= FileObject
->FsContext
;
236 /* Check whether the file has the requested attributes */
237 if (RequestedOptions
& FILE_NON_DIRECTORY_FILE
&& CdfsFCBIsDirectory(Fcb
))
239 CdfsCloseFile (DeviceExt
, FileObject
);
240 return STATUS_FILE_IS_A_DIRECTORY
;
243 if (RequestedOptions
& FILE_DIRECTORY_FILE
&& !CdfsFCBIsDirectory(Fcb
))
245 CdfsCloseFile (DeviceExt
, FileObject
);
246 return STATUS_NOT_A_DIRECTORY
;
251 * If the directory containing the file to open doesn't exist then
254 Irp
->IoStatus
.Information
= (NT_SUCCESS(Status
)) ? FILE_OPENED
: 0;
255 Irp
->IoStatus
.Status
= Status
;
262 CdfsCreate(PDEVICE_OBJECT DeviceObject
,
265 PDEVICE_EXTENSION DeviceExt
;
268 if (DeviceObject
== CdfsGlobalData
->DeviceObject
)
270 /* DeviceObject represents FileSystem instead of logical volume */
271 DPRINT("Opening file system\n");
272 Irp
->IoStatus
.Information
= FILE_OPENED
;
273 Status
= STATUS_SUCCESS
;
277 DeviceExt
= DeviceObject
->DeviceExtension
;
279 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
281 Status
= CdfsCreateFile(DeviceObject
,
283 ExReleaseResourceLite(&DeviceExt
->DirResource
);
286 Irp
->IoStatus
.Status
= Status
;
287 IoCompleteRequest(Irp
,
288 NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);