3 * Copyright (C) 2002 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.2 2002/05/01 13:15:42 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
)
50 DPRINT("try related for %S\n", pRelativeFileName
);
51 Ccb
= pFileObject
->FsContext2
;
56 /* verify related object is a directory and target name
57 don't start with \. */
58 if (Fcb
->Entry
.FileFlags
& 0x02 == 0 ||
59 pRelativeFileName
[0] == L
'\\')
61 return(STATUS_INVALID_PARAMETER
);
64 /* construct absolute path name */
65 assert(wcslen (Fcb
->PathName
) + 1 + wcslen (pRelativeFileName
) + 1
67 rcName
= ExAllocatePool(NonPagedPool
, MAX_PATH
* sizeof(WCHAR
));
70 return(STATUS_INSUFFICIENT_RESOURCES
);
73 wcscpy(rcName
, Fcb
->PathName
);
74 if (!CdfsFCBIsRoot(Fcb
))
75 wcscat (rcName
, L
"\\");
76 wcscat (rcName
, pRelativeFileName
);
77 *pAbsoluteFilename
= rcName
;
79 return(STATUS_SUCCESS
);
84 CdfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
85 PFILE_OBJECT FileObject
,
88 * FUNCTION: Opens a file
94 PWSTR AbsFileName
= NULL
;
96 DPRINT("CdfsOpenFile(%08lx, %08lx, %S)\n", DeviceExt
, FileObject
, FileName
);
98 if (FileObject
->RelatedFileObject
)
100 DPRINT("Converting relative filename to absolute filename\n");
102 Status
= CdfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
105 FileName
= AbsFileName
;
106 if (!NT_SUCCESS(Status
))
110 return(STATUS_UNSUCCESSFUL
);
113 //FIXME: Get cannonical path name (remove .'s, ..'s and extra separators)
115 DPRINT("PathName to open: %S\n", FileName
);
117 /* try first to find an existing FCB in memory */
118 DPRINT("Checking for existing FCB in memory\n");
119 Fcb
= CdfsGrabFCBFromTable(DeviceExt
,
123 DPRINT("No existing FCB found, making a new one if file exists.\n");
124 Status
= CdfsGetFCBForFile(DeviceExt
,
128 if (ParentFcb
!= NULL
)
130 CdfsReleaseFCB(DeviceExt
,
134 if (!NT_SUCCESS (Status
))
136 DPRINT("Could not make a new FCB, status: %x\n", Status
);
139 ExFreePool(AbsFileName
);
145 DPRINT("Attaching FCB to fileObject\n");
146 Status
= CdfsAttachFCBToFileObject(DeviceExt
,
151 ExFreePool (AbsFileName
);
160 CdfsCreateFile(PDEVICE_OBJECT DeviceObject
,
163 * FUNCTION: Opens a file
166 PDEVICE_EXTENSION DeviceExt
;
167 PIO_STACK_LOCATION Stack
;
168 PFILE_OBJECT FileObject
;
169 ULONG RequestedDisposition
;
170 ULONG RequestedOptions
;
175 DPRINT("CdfsCreateFile() called\n");
177 DeviceExt
= DeviceObject
->DeviceExtension
;
179 Stack
= IoGetCurrentIrpStackLocation (Irp
);
182 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
183 // RequestedOptions =
184 // Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
185 // PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE;
186 // if ((RequestedOptions & FILE_DIRECTORY_FILE)
187 // && RequestedDisposition == FILE_SUPERSEDE)
188 // return STATUS_INVALID_PARAMETER;
190 FileObject
= Stack
->FileObject
;
192 Status
= CdfsOpenFile(DeviceExt
,
194 FileObject
->FileName
.Buffer
);
197 * If the directory containing the file to open doesn't exist then
200 Irp
->IoStatus
.Information
= (NT_SUCCESS(Status
)) ? FILE_OPENED
: 0;
201 Irp
->IoStatus
.Status
= Status
;
208 CdfsCreate(PDEVICE_OBJECT DeviceObject
,
211 PDEVICE_EXTENSION DeviceExt
;
214 if (DeviceObject
->Size
== sizeof(DEVICE_OBJECT
))
216 /* DeviceObject represents FileSystem instead of logical volume */
217 DPRINT("FsdCreate called with file system\n");
218 Irp
->IoStatus
.Information
= FILE_OPENED
;
219 Status
= STATUS_SUCCESS
;
223 DeviceExt
= DeviceObject
->DeviceExtension
;
225 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
227 Status
= CdfsCreateFile(DeviceObject
,
229 ExReleaseResourceLite(&DeviceExt
->DirResource
);
233 Irp
->IoStatus
.Status
= Status
;
234 IoCompleteRequest(Irp
,
235 NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);