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.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/ntfs/create.c
24 * PURPOSE: NTFS filesystem driver
25 * PROGRAMMER: Eric Kohl
28 /* INCLUDES *****************************************************************/
30 #include <ddk/ntddk.h>
38 /* FUNCTIONS ****************************************************************/
41 NtfsMakeAbsoluteFilename(PFILE_OBJECT pFileObject,
42 PWSTR pRelativeFileName,
43 PWSTR *pAbsoluteFilename)
49 DPRINT("try related for %S\n", pRelativeFileName);
50 Ccb = pFileObject->FsContext2;
55 /* verify related object is a directory and target name
56 don't start with \. */
57 if (NtfsFCBIsDirectory(Fcb) == FALSE ||
58 pRelativeFileName[0] == L'\\')
60 return(STATUS_INVALID_PARAMETER);
63 /* construct absolute path name */
64 assert(wcslen (Fcb->PathName) + 1 + wcslen (pRelativeFileName) + 1
66 rcName = ExAllocatePool(NonPagedPool, MAX_PATH * sizeof(WCHAR));
69 return(STATUS_INSUFFICIENT_RESOURCES);
72 wcscpy(rcName, Fcb->PathName);
73 if (!NtfsFCBIsRoot(Fcb))
74 wcscat (rcName, L"\\");
75 wcscat (rcName, pRelativeFileName);
76 *pAbsoluteFilename = rcName;
78 return(STATUS_SUCCESS);
83 NtfsOpenFile(PDEVICE_EXTENSION DeviceExt,
84 PFILE_OBJECT FileObject,
87 * FUNCTION: Opens a file
93 PWSTR AbsFileName = NULL;
95 DPRINT("NtfsOpenFile(%08lx, %08lx, %S)\n", DeviceExt, FileObject, FileName);
97 if (FileObject->RelatedFileObject)
99 DPRINT("Converting relative filename to absolute filename\n");
101 Status = NtfsMakeAbsoluteFilename(FileObject->RelatedFileObject,
104 FileName = AbsFileName;
105 if (!NT_SUCCESS(Status))
109 return(STATUS_UNSUCCESSFUL);
112 //FIXME: Get cannonical path name (remove .'s, ..'s and extra separators)
114 DPRINT("PathName to open: %S\n", FileName);
116 /* try first to find an existing FCB in memory */
117 DPRINT("Checking for existing FCB in memory\n");
118 Fcb = NtfsGrabFCBFromTable(DeviceExt,
122 DPRINT("No existing FCB found, making a new one if file exists.\n");
123 Status = NtfsGetFCBForFile(DeviceExt,
127 if (ParentFcb != NULL)
129 NtfsReleaseFCB(DeviceExt,
133 if (!NT_SUCCESS (Status))
135 DPRINT("Could not make a new FCB, status: %x\n", Status);
138 ExFreePool(AbsFileName);
144 DPRINT("Attaching FCB to fileObject\n");
145 Status = NtfsAttachFCBToFileObject(DeviceExt,
150 ExFreePool (AbsFileName);
157 NtfsCreateFile(PDEVICE_OBJECT DeviceObject,
160 * FUNCTION: Opens a file
163 PDEVICE_EXTENSION DeviceExt;
164 PIO_STACK_LOCATION Stack;
165 PFILE_OBJECT FileObject;
166 ULONG RequestedDisposition;
167 ULONG RequestedOptions;
172 DPRINT("NtfsCreateFile() called\n");
174 DeviceExt = DeviceObject->DeviceExtension;
176 Stack = IoGetCurrentIrpStackLocation (Irp);
179 RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff);
180 // RequestedOptions =
181 // Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
182 // PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE;
183 // if ((RequestedOptions & FILE_DIRECTORY_FILE)
184 // && RequestedDisposition == FILE_SUPERSEDE)
185 // return STATUS_INVALID_PARAMETER;
187 FileObject = Stack->FileObject;
189 if (RequestedDisposition == FILE_CREATE ||
190 RequestedDisposition == FILE_OVERWRITE_IF ||
191 RequestedDisposition == FILE_SUPERSEDE)
193 return(STATUS_ACCESS_DENIED);
196 Status = NtfsOpenFile(DeviceExt,
198 FileObject->FileName.Buffer);
201 * If the directory containing the file to open doesn't exist then
204 Irp->IoStatus.Information = (NT_SUCCESS(Status)) ? FILE_OPENED : 0;
205 Irp->IoStatus.Status = Status;
212 NtfsCreate(PDEVICE_OBJECT DeviceObject,
215 PDEVICE_EXTENSION DeviceExt;
218 if (DeviceObject == NtfsGlobalData->DeviceObject)
220 /* DeviceObject represents FileSystem instead of logical volume */
221 DPRINT("Opening file system\n");
222 Irp->IoStatus.Information = FILE_OPENED;
223 Status = STATUS_SUCCESS;
227 DeviceExt = DeviceObject->DeviceExtension;
229 ExAcquireResourceExclusiveLite(&DeviceExt->DirResource,
231 Status = NtfsCreateFile(DeviceObject,
233 ExReleaseResourceLite(&DeviceExt->DirResource);
236 Irp->IoStatus.Status = Status;
237 IoCompleteRequest(Irp,
238 NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT);