Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencreate.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS kernel 00003 * Copyright (C) 2002, 2003, 2004 ReactOS Team 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 /* $Id: create.c 52546 2011-07-05 13:55:39Z rharabien $ 00020 * 00021 * COPYRIGHT: See COPYING in the top level directory 00022 * PROJECT: ReactOS kernel 00023 * FILE: services/fs/cdfs/cdfs.c 00024 * PURPOSE: CDROM (ISO 9660) filesystem driver 00025 * PROGRAMMER: Art Yerkes 00026 * Eric Kohl 00027 */ 00028 00029 /* INCLUDES *****************************************************************/ 00030 00031 #include "cdfs.h" 00032 00033 #define NDEBUG 00034 #include <debug.h> 00035 00036 /* FUNCTIONS ****************************************************************/ 00037 00038 static NTSTATUS 00039 CdfsMakeAbsoluteFilename(PFILE_OBJECT FileObject, 00040 PUNICODE_STRING RelativeFileName, 00041 PUNICODE_STRING AbsoluteFileName) 00042 { 00043 USHORT Length; 00044 PFCB Fcb; 00045 NTSTATUS Status; 00046 00047 DPRINT("try related for %wZ\n", RelativeFileName); 00048 Fcb = FileObject->FsContext; 00049 ASSERT(Fcb); 00050 00051 /* verify related object is a directory and target name 00052 don't start with \. */ 00053 if ((Fcb->Entry.FileFlags & FILE_FLAG_DIRECTORY) == 0 || 00054 RelativeFileName->Buffer[0] == L'\\') 00055 { 00056 return STATUS_INVALID_PARAMETER; 00057 } 00058 00059 /* construct absolute path name */ 00060 Length = (wcslen(Fcb->PathName) * sizeof(WCHAR)) + 00061 sizeof(WCHAR) + 00062 RelativeFileName->Length + 00063 sizeof(WCHAR); 00064 AbsoluteFileName->Length = 0; 00065 AbsoluteFileName->MaximumLength = Length; 00066 AbsoluteFileName->Buffer = ExAllocatePool(NonPagedPool, 00067 Length); 00068 if (AbsoluteFileName->Buffer == NULL) 00069 { 00070 return STATUS_INSUFFICIENT_RESOURCES; 00071 } 00072 00073 Status = RtlAppendUnicodeToString(AbsoluteFileName, 00074 Fcb->PathName); 00075 if (!NT_SUCCESS(Status)) 00076 { 00077 RtlFreeUnicodeString(AbsoluteFileName); 00078 return Status; 00079 } 00080 00081 if (!CdfsFCBIsRoot(Fcb)) 00082 { 00083 Status = RtlAppendUnicodeToString(AbsoluteFileName, 00084 L"\\"); 00085 if (!NT_SUCCESS(Status)) 00086 { 00087 RtlFreeUnicodeString(AbsoluteFileName); 00088 return Status; 00089 } 00090 } 00091 00092 Status = RtlAppendUnicodeStringToString(AbsoluteFileName, 00093 RelativeFileName); 00094 if (!NT_SUCCESS(Status)) 00095 { 00096 RtlFreeUnicodeString(AbsoluteFileName); 00097 return Status; 00098 } 00099 00100 return STATUS_SUCCESS; 00101 } 00102 00103 00104 /* 00105 * FUNCTION: Opens a file 00106 */ 00107 static NTSTATUS 00108 CdfsOpenFile(PDEVICE_EXTENSION DeviceExt, 00109 PFILE_OBJECT FileObject, 00110 PUNICODE_STRING FileName) 00111 { 00112 PFCB ParentFcb; 00113 PFCB Fcb; 00114 NTSTATUS Status; 00115 UNICODE_STRING AbsFileName; 00116 00117 DPRINT("CdfsOpenFile(%08lx, %08lx, %wZ)\n", DeviceExt, FileObject, FileName); 00118 00119 if (FileObject->RelatedFileObject) 00120 { 00121 DPRINT("Converting relative filename to absolute filename\n"); 00122 00123 Status = CdfsMakeAbsoluteFilename(FileObject->RelatedFileObject, 00124 FileName, 00125 &AbsFileName); 00126 if (!NT_SUCCESS(Status)) 00127 { 00128 return Status; 00129 } 00130 00131 FileName = &AbsFileName; 00132 } 00133 00134 Status = CdfsDeviceIoControl (DeviceExt->StorageDevice, 00135 IOCTL_CDROM_CHECK_VERIFY, 00136 NULL, 00137 0, 00138 NULL, 00139 0, 00140 FALSE); 00141 DPRINT ("Status %lx\n", Status); 00142 if (!NT_SUCCESS(Status)) 00143 { 00144 if (Status == STATUS_NO_MEDIA_IN_DEVICE || Status == STATUS_VERIFY_REQUIRED) 00145 { 00146 DeviceExt->VolumeDevice->Flags |= DO_VERIFY_VOLUME; 00147 } 00148 DPRINT1 ("Status %lx\n", Status); 00149 return Status; 00150 } 00151 00152 DPRINT("PathName to open: %wZ\n", FileName); 00153 00154 /* try first to find an existing FCB in memory */ 00155 DPRINT("Checking for existing FCB in memory\n"); 00156 Fcb = CdfsGrabFCBFromTable(DeviceExt, 00157 FileName); 00158 if (Fcb == NULL) 00159 { 00160 DPRINT("No existing FCB found, making a new one if file exists.\n"); 00161 Status = CdfsGetFCBForFile(DeviceExt, 00162 &ParentFcb, 00163 &Fcb, 00164 FileName); 00165 if (ParentFcb != NULL) 00166 { 00167 CdfsReleaseFCB(DeviceExt, 00168 ParentFcb); 00169 } 00170 00171 if (!NT_SUCCESS (Status)) 00172 { 00173 DPRINT("Could not make a new FCB, status: %x\n", Status); 00174 00175 if (FileName == &AbsFileName) 00176 RtlFreeUnicodeString(&AbsFileName); 00177 00178 return Status; 00179 } 00180 } 00181 00182 DPRINT("Attaching FCB to fileObject\n"); 00183 Status = CdfsAttachFCBToFileObject(DeviceExt, 00184 Fcb, 00185 FileObject); 00186 00187 if ((FileName == &AbsFileName) && AbsFileName.Buffer) 00188 ExFreePool(AbsFileName.Buffer); 00189 00190 return Status; 00191 } 00192 00193 00194 /* 00195 * FUNCTION: Opens a file 00196 */ 00197 static NTSTATUS 00198 CdfsCreateFile(PDEVICE_OBJECT DeviceObject, 00199 PIRP Irp) 00200 { 00201 PDEVICE_EXTENSION DeviceExt; 00202 PIO_STACK_LOCATION Stack; 00203 PFILE_OBJECT FileObject; 00204 ULONG RequestedDisposition; 00205 ULONG RequestedOptions; 00206 PFCB Fcb; 00207 NTSTATUS Status; 00208 00209 DPRINT("CdfsCreateFile() called\n"); 00210 00211 DeviceExt = DeviceObject->DeviceExtension; 00212 ASSERT(DeviceExt); 00213 Stack = IoGetCurrentIrpStackLocation (Irp); 00214 ASSERT(Stack); 00215 00216 RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff); 00217 RequestedOptions = Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS; 00218 DPRINT("RequestedDisposition %x, RequestedOptions %x\n", 00219 RequestedDisposition, RequestedOptions); 00220 00221 FileObject = Stack->FileObject; 00222 00223 if (RequestedDisposition == FILE_CREATE || 00224 RequestedDisposition == FILE_OVERWRITE_IF || 00225 RequestedDisposition == FILE_SUPERSEDE) 00226 { 00227 return STATUS_ACCESS_DENIED; 00228 } 00229 00230 Status = CdfsOpenFile(DeviceExt, 00231 FileObject, 00232 &FileObject->FileName); 00233 if (NT_SUCCESS(Status)) 00234 { 00235 Fcb = FileObject->FsContext; 00236 00237 /* Check whether the file has the requested attributes */ 00238 if (RequestedOptions & FILE_NON_DIRECTORY_FILE && CdfsFCBIsDirectory(Fcb)) 00239 { 00240 CdfsCloseFile (DeviceExt, FileObject); 00241 return STATUS_FILE_IS_A_DIRECTORY; 00242 } 00243 00244 if (RequestedOptions & FILE_DIRECTORY_FILE && !CdfsFCBIsDirectory(Fcb)) 00245 { 00246 CdfsCloseFile (DeviceExt, FileObject); 00247 return STATUS_NOT_A_DIRECTORY; 00248 } 00249 } 00250 00251 /* 00252 * If the directory containing the file to open doesn't exist then 00253 * fail immediately 00254 */ 00255 Irp->IoStatus.Information = (NT_SUCCESS(Status)) ? FILE_OPENED : 0; 00256 Irp->IoStatus.Status = Status; 00257 00258 return Status; 00259 } 00260 00261 00262 NTSTATUS NTAPI 00263 CdfsCreate(PDEVICE_OBJECT DeviceObject, 00264 PIRP Irp) 00265 { 00266 PDEVICE_EXTENSION DeviceExt; 00267 NTSTATUS Status; 00268 00269 if (DeviceObject == CdfsGlobalData->DeviceObject) 00270 { 00271 /* DeviceObject represents FileSystem instead of logical volume */ 00272 DPRINT("Opening file system\n"); 00273 Irp->IoStatus.Information = FILE_OPENED; 00274 Status = STATUS_SUCCESS; 00275 goto ByeBye; 00276 } 00277 00278 DeviceExt = DeviceObject->DeviceExtension; 00279 00280 KeEnterCriticalRegion(); 00281 ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, 00282 TRUE); 00283 Status = CdfsCreateFile(DeviceObject, 00284 Irp); 00285 ExReleaseResourceLite(&DeviceExt->DirResource); 00286 KeLeaveCriticalRegion(); 00287 00288 ByeBye: 00289 Irp->IoStatus.Status = Status; 00290 IoCompleteRequest(Irp, 00291 NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT); 00292 00293 return Status; 00294 } 00295 00296 /* EOF */ Generated on Sat May 26 2012 04:15:52 for ReactOS by
1.7.6.1
|