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)
48 DPRINT("try related for %S\n", pRelativeFileName);
49 Fcb = pFileObject->FsContext;
52 /* verify related object is a directory and target name
53 don't start with \. */
54 if (NtfsFCBIsDirectory(Fcb) == FALSE ||
55 pRelativeFileName[0] == L'\\')
57 return(STATUS_INVALID_PARAMETER);
60 /* construct absolute path name */
61 assert(wcslen (Fcb->PathName) + 1 + wcslen (pRelativeFileName) + 1
63 rcName = ExAllocatePool(NonPagedPool, MAX_PATH * sizeof(WCHAR));
66 return(STATUS_INSUFFICIENT_RESOURCES);
69 wcscpy(rcName, Fcb->PathName);
70 if (!NtfsFCBIsRoot(Fcb))
71 wcscat (rcName, L"\\");
72 wcscat (rcName, pRelativeFileName);
73 *pAbsoluteFilename = rcName;
75 return(STATUS_SUCCESS);
80 NtfsOpenFile(PDEVICE_EXTENSION DeviceExt,
81 PFILE_OBJECT FileObject,
84 * FUNCTION: Opens a file
90 PWSTR AbsFileName = NULL;
92 DPRINT("NtfsOpenFile(%08lx, %08lx, %S)\n", DeviceExt, FileObject, FileName);
94 if (FileObject->RelatedFileObject)
96 DPRINT("Converting relative filename to absolute filename\n");
98 Status = NtfsMakeAbsoluteFilename(FileObject->RelatedFileObject,
101 FileName = AbsFileName;
102 if (!NT_SUCCESS(Status))
106 return(STATUS_UNSUCCESSFUL);
109 //FIXME: Get cannonical path name (remove .'s, ..'s and extra separators)
111 DPRINT("PathName to open: %S\n", FileName);
113 /* try first to find an existing FCB in memory */
114 DPRINT("Checking for existing FCB in memory\n");
115 Fcb = NtfsGrabFCBFromTable(DeviceExt,
119 DPRINT("No existing FCB found, making a new one if file exists.\n");
120 Status = NtfsGetFCBForFile(DeviceExt,
124 if (ParentFcb != NULL)
126 NtfsReleaseFCB(DeviceExt,
130 if (!NT_SUCCESS (Status))
132 DPRINT("Could not make a new FCB, status: %x\n", Status);
135 ExFreePool(AbsFileName);
141 DPRINT("Attaching FCB to fileObject\n");
142 Status = NtfsAttachFCBToFileObject(DeviceExt,
147 ExFreePool (AbsFileName);
154 NtfsCreateFile(PDEVICE_OBJECT DeviceObject,
157 * FUNCTION: Opens a file
160 PDEVICE_EXTENSION DeviceExt;
161 PIO_STACK_LOCATION Stack;
162 PFILE_OBJECT FileObject;
163 ULONG RequestedDisposition;
164 ULONG RequestedOptions;
169 DPRINT("NtfsCreateFile() called\n");
171 DeviceExt = DeviceObject->DeviceExtension;
173 Stack = IoGetCurrentIrpStackLocation (Irp);
176 RequestedDisposition = ((Stack->Parameters.Create.Options >> 24) & 0xff);
177 // RequestedOptions =
178 // Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
179 // PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE;
180 // if ((RequestedOptions & FILE_DIRECTORY_FILE)
181 // && RequestedDisposition == FILE_SUPERSEDE)
182 // return STATUS_INVALID_PARAMETER;
184 FileObject = Stack->FileObject;
186 if (RequestedDisposition == FILE_CREATE ||
187 RequestedDisposition == FILE_OVERWRITE_IF ||
188 RequestedDisposition == FILE_SUPERSEDE)
190 return(STATUS_ACCESS_DENIED);
193 Status = NtfsOpenFile(DeviceExt,
195 FileObject->FileName.Buffer);
198 * If the directory containing the file to open doesn't exist then
201 Irp->IoStatus.Information = (NT_SUCCESS(Status)) ? FILE_OPENED : 0;
202 Irp->IoStatus.Status = Status;
209 NtfsCreate(PDEVICE_OBJECT DeviceObject,
212 PDEVICE_EXTENSION DeviceExt;
215 if (DeviceObject == NtfsGlobalData->DeviceObject)
217 /* DeviceObject represents FileSystem instead of logical volume */
218 DPRINT("Opening file system\n");
219 Irp->IoStatus.Information = FILE_OPENED;
220 Status = STATUS_SUCCESS;
224 DeviceExt = DeviceObject->DeviceExtension;
226 ExAcquireResourceExclusiveLite(&DeviceExt->DirResource,
228 Status = NtfsCreateFile(DeviceObject,
230 ExReleaseResourceLite(&DeviceExt->DirResource);
233 Irp->IoStatus.Status = Status;
234 IoCompleteRequest(Irp,
235 NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT);