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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/create.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMER: Eric Kohl
26 /* INCLUDES *****************************************************************/
33 /* GLOBALS *****************************************************************/
36 /* FUNCTIONS ****************************************************************/
40 NtfsMakeAbsoluteFilename(PFILE_OBJECT pFileObject
,
41 PWSTR pRelativeFileName
,
42 PWSTR
*pAbsoluteFilename
)
47 DPRINT("try related for %S\n", pRelativeFileName
);
48 Fcb
= pFileObject
->FsContext
;
51 /* verify related object is a directory and target name
52 don't start with \. */
53 if (NtfsFCBIsDirectory(Fcb
) == FALSE
||
54 pRelativeFileName
[0] == L
'\\')
56 return STATUS_INVALID_PARAMETER
;
59 /* construct absolute path name */
60 ASSERT(wcslen (Fcb
->PathName
) + 1 + wcslen (pRelativeFileName
) + 1 <= MAX_PATH
);
61 rcName
= ExAllocatePoolWithTag(NonPagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_NTFS
);
64 return STATUS_INSUFFICIENT_RESOURCES
;
67 wcscpy(rcName
, Fcb
->PathName
);
68 if (!NtfsFCBIsRoot(Fcb
))
69 wcscat (rcName
, L
"\\");
70 wcscat (rcName
, pRelativeFileName
);
71 *pAbsoluteFilename
= rcName
;
73 return STATUS_SUCCESS
;
78 * FUNCTION: Opens a file
82 NtfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
83 PFILE_OBJECT FileObject
,
89 PWSTR AbsFileName
= NULL
;
91 DPRINT("NtfsOpenFile(%p, %p, %S)\n", DeviceExt
, FileObject
, FileName
);
93 if (FileObject
->RelatedFileObject
)
95 DPRINT("Converting relative filename to absolute filename\n");
97 Status
= NtfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
100 FileName
= AbsFileName
;
101 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 * FUNCTION: Opens a file
158 NtfsCreateFile(PDEVICE_OBJECT DeviceObject
,
161 PDEVICE_EXTENSION DeviceExt
;
162 PIO_STACK_LOCATION Stack
;
163 PFILE_OBJECT FileObject
;
164 ULONG RequestedDisposition
;
165 // ULONG RequestedOptions;
170 DPRINT("NtfsCreateFile() called\n");
172 DeviceExt
= DeviceObject
->DeviceExtension
;
174 Stack
= IoGetCurrentIrpStackLocation (Irp
);
177 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
178 // RequestedOptions =
179 // Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
180 // PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE;
181 // if ((RequestedOptions & FILE_DIRECTORY_FILE)
182 // && RequestedDisposition == FILE_SUPERSEDE)
183 // return STATUS_INVALID_PARAMETER;
185 FileObject
= Stack
->FileObject
;
187 if (RequestedDisposition
== FILE_CREATE
||
188 RequestedDisposition
== FILE_OVERWRITE_IF
||
189 RequestedDisposition
== FILE_SUPERSEDE
)
191 return STATUS_ACCESS_DENIED
;
194 Status
= NtfsOpenFile(DeviceExt
,
196 FileObject
->FileName
.Buffer
);
199 * If the directory containing the file to open doesn't exist then
202 Irp
->IoStatus
.Information
= (NT_SUCCESS(Status
)) ? FILE_OPENED
: 0;
203 Irp
->IoStatus
.Status
= Status
;
211 NtfsFsdCreate(PDEVICE_OBJECT DeviceObject
,
214 PDEVICE_EXTENSION DeviceExt
;
217 if (DeviceObject
== NtfsGlobalData
->DeviceObject
)
219 /* DeviceObject represents FileSystem instead of logical volume */
220 DPRINT("Opening file system\n");
221 Irp
->IoStatus
.Information
= FILE_OPENED
;
222 Status
= STATUS_SUCCESS
;
226 DeviceExt
= DeviceObject
->DeviceExtension
;
228 FsRtlEnterFileSystem();
229 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
231 Status
= NtfsCreateFile(DeviceObject
,
233 ExReleaseResourceLite(&DeviceExt
->DirResource
);
234 FsRtlExitFileSystem();
237 Irp
->IoStatus
.Status
= Status
;
238 IoCompleteRequest(Irp
,
239 NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);