3 * Copyright (C) 2002, 2003 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.
19 /* $Id: create.c,v 1.11 2003/11/13 15:25:08 ekohl Exp $
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 pFileObject
,
43 PWSTR pRelativeFileName
,
44 PWSTR
*pAbsoluteFilename
)
49 DPRINT("try related for %S\n", pRelativeFileName
);
50 Fcb
= pFileObject
->FsContext
;
53 /* verify related object is a directory and target name
54 don't start with \. */
55 if ((Fcb
->Entry
.FileFlags
& 0x02) == 0 ||
56 pRelativeFileName
[0] == L
'\\')
58 return(STATUS_INVALID_PARAMETER
);
61 /* construct absolute path name */
62 assert(wcslen (Fcb
->PathName
) + 1 + wcslen (pRelativeFileName
) + 1
64 rcName
= ExAllocatePool(NonPagedPool
, MAX_PATH
* sizeof(WCHAR
));
67 return(STATUS_INSUFFICIENT_RESOURCES
);
70 wcscpy(rcName
, Fcb
->PathName
);
71 if (!CdfsFCBIsRoot(Fcb
))
72 wcscat (rcName
, L
"\\");
73 wcscat (rcName
, pRelativeFileName
);
74 *pAbsoluteFilename
= rcName
;
76 return(STATUS_SUCCESS
);
81 CdfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
82 PFILE_OBJECT FileObject
,
85 * FUNCTION: Opens a file
91 PWSTR AbsFileName
= NULL
;
93 DPRINT("CdfsOpenFile(%08lx, %08lx, %S)\n", DeviceExt
, FileObject
, FileName
);
95 if (FileObject
->RelatedFileObject
)
97 DPRINT("Converting relative filename to absolute filename\n");
99 Status
= CdfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
102 FileName
= AbsFileName
;
103 if (!NT_SUCCESS(Status
))
108 return STATUS_UNSUCCESSFUL
;
111 Status
= CdfsDeviceIoControl (DeviceExt
->StorageDevice
,
112 IOCTL_CDROM_CHECK_VERIFY
,
118 DPRINT ("Status %lx\n", Status
);
119 if (Status
== STATUS_VERIFY_REQUIRED
)
121 PDEVICE_OBJECT DeviceToVerify
;
123 DPRINT1 ("Media change detected!\n");
124 DPRINT1 ("Device %p\n", DeviceExt
->VolumeDevice
);
126 DeviceToVerify
= IoGetDeviceToVerify (PsGetCurrentThread ());
127 IoSetDeviceToVerify (PsGetCurrentThread (),
130 Status
= IoVerifyVolume (DeviceToVerify
,
132 if (!NT_SUCCESS(Status
))
134 DPRINT1 ("Status %lx\n", Status
);
138 else if (!NT_SUCCESS(Status
))
140 DPRINT1 ("Status %lx\n", Status
);
144 //FIXME: Get cannonical path name (remove .'s, ..'s and extra separators)
146 DPRINT("PathName to open: %S\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
);
170 ExFreePool(AbsFileName
);
176 DPRINT("Attaching FCB to fileObject\n");
177 Status
= CdfsAttachFCBToFileObject(DeviceExt
,
182 ExFreePool (AbsFileName
);
189 CdfsCreateFile(PDEVICE_OBJECT DeviceObject
,
192 * FUNCTION: Opens a file
195 PDEVICE_EXTENSION DeviceExt
;
196 PIO_STACK_LOCATION Stack
;
197 PFILE_OBJECT FileObject
;
198 ULONG RequestedDisposition
;
199 ULONG RequestedOptions
;
204 DPRINT("CdfsCreateFile() called\n");
206 DeviceExt
= DeviceObject
->DeviceExtension
;
208 Stack
= IoGetCurrentIrpStackLocation (Irp
);
211 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
212 RequestedOptions
= Stack
->Parameters
.Create
.Options
& FILE_VALID_OPTION_FLAGS
;
213 DPRINT("RequestedDisposition %x, RequestedOptions %x\n",
214 RequestedDisposition
, RequestedOptions
);
216 FileObject
= Stack
->FileObject
;
218 if (RequestedDisposition
== FILE_CREATE
||
219 RequestedDisposition
== FILE_OVERWRITE_IF
||
220 RequestedDisposition
== FILE_SUPERSEDE
)
222 return(STATUS_ACCESS_DENIED
);
225 Status
= CdfsOpenFile(DeviceExt
,
227 FileObject
->FileName
.Buffer
);
229 if (NT_SUCCESS(Status
))
231 Fcb
= FileObject
->FsContext
;
233 /* Check whether the file has the requested attributes */
234 if (RequestedOptions
& FILE_NON_DIRECTORY_FILE
&& CdfsFCBIsDirectory(Fcb
))
236 CdfsCloseFile (DeviceExt
, FileObject
);
237 return STATUS_FILE_IS_A_DIRECTORY
;
240 if (RequestedOptions
& FILE_DIRECTORY_FILE
&& !CdfsFCBIsDirectory(Fcb
))
242 CdfsCloseFile (DeviceExt
, FileObject
);
243 return STATUS_NOT_A_DIRECTORY
;
248 * If the directory containing the file to open doesn't exist then
251 Irp
->IoStatus
.Information
= (NT_SUCCESS(Status
)) ? FILE_OPENED
: 0;
252 Irp
->IoStatus
.Status
= Status
;
259 CdfsCreate(PDEVICE_OBJECT DeviceObject
,
262 PDEVICE_EXTENSION DeviceExt
;
265 if (DeviceObject
== CdfsGlobalData
->DeviceObject
)
267 /* DeviceObject represents FileSystem instead of logical volume */
268 DPRINT("Opening file system\n");
269 Irp
->IoStatus
.Information
= FILE_OPENED
;
270 Status
= STATUS_SUCCESS
;
274 DeviceExt
= DeviceObject
->DeviceExtension
;
276 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
278 Status
= CdfsCreateFile(DeviceObject
,
280 ExReleaseResourceLite(&DeviceExt
->DirResource
);
283 Irp
->IoStatus
.Status
= Status
;
284 IoCompleteRequest(Irp
,
285 NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);