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 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 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * COPYRIGHT: See COPYING in the top level directory 00020 * PROJECT: ReactOS kernel 00021 * FILE: drivers/filesystem/ntfs/create.c 00022 * PURPOSE: NTFS filesystem driver 00023 * PROGRAMMER: Eric Kohl 00024 */ 00025 00026 /* INCLUDES *****************************************************************/ 00027 00028 #include "ntfs.h" 00029 00030 #define NDEBUG 00031 #include <debug.h> 00032 00033 /* GLOBALS *****************************************************************/ 00034 00035 00036 /* FUNCTIONS ****************************************************************/ 00037 00038 static NTSTATUS 00039 NtfsMakeAbsoluteFilename(PFILE_OBJECT pFileObject, 00040 PWSTR pRelativeFileName, 00041 PWSTR *pAbsoluteFilename) 00042 { 00043 PWSTR rcName; 00044 PNTFS_FCB Fcb; 00045 00046 DPRINT("try related for %S\n", pRelativeFileName); 00047 Fcb = pFileObject->FsContext; 00048 ASSERT(Fcb); 00049 00050 /* verify related object is a directory and target name 00051 don't start with \. */ 00052 if (NtfsFCBIsDirectory(Fcb) == FALSE || 00053 pRelativeFileName[0] == L'\\') 00054 { 00055 return(STATUS_INVALID_PARAMETER); 00056 } 00057 00058 /* construct absolute path name */ 00059 ASSERT(wcslen (Fcb->PathName) + 1 + wcslen (pRelativeFileName) + 1 00060 <= MAX_PATH); 00061 rcName = ExAllocatePoolWithTag(NonPagedPool, MAX_PATH * sizeof(WCHAR), TAG_NTFS); 00062 if (!rcName) 00063 { 00064 return(STATUS_INSUFFICIENT_RESOURCES); 00065 } 00066 00067 wcscpy(rcName, Fcb->PathName); 00068 if (!NtfsFCBIsRoot(Fcb)) 00069 wcscat (rcName, L"\\"); 00070 wcscat (rcName, pRelativeFileName); 00071 *pAbsoluteFilename = rcName; 00072 00073 return(STATUS_SUCCESS); 00074 } 00075 00076 00077 static NTSTATUS 00078 NtfsOpenFile(PDEVICE_EXTENSION DeviceExt, 00079 PFILE_OBJECT FileObject, 00080 PWSTR FileName) 00081 /* 00082 * FUNCTION: Opens a file 00083 */ 00084 { 00085 PNTFS_FCB ParentFcb; 00086 PNTFS_FCB Fcb; 00087 NTSTATUS Status; 00088 PWSTR AbsFileName = NULL; 00089 00090 DPRINT("NtfsOpenFile(%p, %p, %S)\n", DeviceExt, FileObject, FileName); 00091 00092 if (FileObject->RelatedFileObject) 00093 { 00094 DPRINT("Converting relative filename to absolute filename\n"); 00095 00096 Status = NtfsMakeAbsoluteFilename(FileObject->RelatedFileObject, 00097 FileName, 00098 &AbsFileName); 00099 FileName = AbsFileName; 00100 if (!NT_SUCCESS(Status)) 00101 { 00102 return(Status); 00103 } 00104 return(STATUS_UNSUCCESSFUL); 00105 } 00106 00107 //FIXME: Get cannonical path name (remove .'s, ..'s and extra separators) 00108 00109 DPRINT("PathName to open: %S\n", FileName); 00110 00111 /* try first to find an existing FCB in memory */ 00112 DPRINT("Checking for existing FCB in memory\n"); 00113 Fcb = NtfsGrabFCBFromTable(DeviceExt, 00114 FileName); 00115 if (Fcb == NULL) 00116 { 00117 DPRINT("No existing FCB found, making a new one if file exists.\n"); 00118 Status = NtfsGetFCBForFile(DeviceExt, 00119 &ParentFcb, 00120 &Fcb, 00121 FileName); 00122 if (ParentFcb != NULL) 00123 { 00124 NtfsReleaseFCB(DeviceExt, 00125 ParentFcb); 00126 } 00127 00128 if (!NT_SUCCESS (Status)) 00129 { 00130 DPRINT("Could not make a new FCB, status: %x\n", Status); 00131 00132 if (AbsFileName) 00133 ExFreePool(AbsFileName); 00134 00135 return(Status); 00136 } 00137 } 00138 00139 DPRINT("Attaching FCB to fileObject\n"); 00140 Status = NtfsAttachFCBToFileObject(DeviceExt, 00141 Fcb, 00142 FileObject); 00143 00144 if (AbsFileName) 00145 ExFreePool (AbsFileName); 00146 00147 return(Status); 00148 } 00149 00150 00151 static NTSTATUS 00152 NtfsCreateFile(PDEVICE_OBJECT DeviceObject, 00153 PIRP Irp) 00154 /* 00155 * FUNCTION: Opens a file 00156 */ 00157 { 00158 PDEVICE_EXTENSION DeviceExt; 00159 PIO_STACK_LOCATION Stack; 00160 PFILE_OBJECT FileObject; 00161 ULONG RequestedDisposition; 00162 // ULONG RequestedOptions; 00163 // PFCB Fcb; 00164 // PWSTR FileName; 00165 NTSTATUS Status; 00166 00167 DPRINT("NtfsCreateFile() called\n"); 00168 00169 DeviceExt = DeviceObject->DeviceExtension; 00170 ASSERT(DeviceExt); 00171 Stack = IoGetCurrentIrpStackLocation (Irp); 00172 ASSERT(Stack); 00173 00174 RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff); 00175 // RequestedOptions = 00176 // Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS; 00177 // PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE; 00178 // if ((RequestedOptions & FILE_DIRECTORY_FILE) 00179 // && RequestedDisposition == FILE_SUPERSEDE) 00180 // return STATUS_INVALID_PARAMETER; 00181 00182 FileObject = Stack->FileObject; 00183 00184 if (RequestedDisposition == FILE_CREATE || 00185 RequestedDisposition == FILE_OVERWRITE_IF || 00186 RequestedDisposition == FILE_SUPERSEDE) 00187 { 00188 return(STATUS_ACCESS_DENIED); 00189 } 00190 00191 Status = NtfsOpenFile(DeviceExt, 00192 FileObject, 00193 FileObject->FileName.Buffer); 00194 00195 /* 00196 * If the directory containing the file to open doesn't exist then 00197 * fail immediately 00198 */ 00199 Irp->IoStatus.Information = (NT_SUCCESS(Status)) ? FILE_OPENED : 0; 00200 Irp->IoStatus.Status = Status; 00201 00202 return(Status); 00203 } 00204 00205 00206 NTSTATUS NTAPI 00207 NtfsFsdCreate(PDEVICE_OBJECT DeviceObject, 00208 PIRP Irp) 00209 { 00210 PDEVICE_EXTENSION DeviceExt; 00211 NTSTATUS Status; 00212 00213 if (DeviceObject == NtfsGlobalData->DeviceObject) 00214 { 00215 /* DeviceObject represents FileSystem instead of logical volume */ 00216 DPRINT("Opening file system\n"); 00217 Irp->IoStatus.Information = FILE_OPENED; 00218 Status = STATUS_SUCCESS; 00219 goto ByeBye; 00220 } 00221 00222 DeviceExt = DeviceObject->DeviceExtension; 00223 00224 FsRtlEnterFileSystem(); 00225 ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, 00226 TRUE); 00227 Status = NtfsCreateFile(DeviceObject, 00228 Irp); 00229 ExReleaseResourceLite(&DeviceExt->DirResource); 00230 FsRtlExitFileSystem(); 00231 00232 ByeBye: 00233 Irp->IoStatus.Status = Status; 00234 IoCompleteRequest(Irp, 00235 NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT); 00236 00237 return(Status); 00238 } 00239 00240 /* EOF */ Generated on Sun May 27 2012 04:16:59 for ReactOS by
1.7.6.1
|