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 ****************************************************************/
39 NtfsMakeAbsoluteFilename(PFILE_OBJECT pFileObject
,
40 PWSTR pRelativeFileName
,
41 PWSTR
*pAbsoluteFilename
)
46 DPRINT("try related for %S\n", pRelativeFileName
);
47 Fcb
= pFileObject
->FsContext
;
50 /* verify related object is a directory and target name
51 don't start with \. */
52 if (NtfsFCBIsDirectory(Fcb
) == FALSE
||
53 pRelativeFileName
[0] == L
'\\')
55 return(STATUS_INVALID_PARAMETER
);
58 /* construct absolute path name */
59 ASSERT(wcslen (Fcb
->PathName
) + 1 + wcslen (pRelativeFileName
) + 1
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 NtfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
79 PFILE_OBJECT FileObject
,
82 * FUNCTION: Opens a file
88 PWSTR AbsFileName
= NULL
;
90 DPRINT("NtfsOpenFile(%p, %p, %S)\n", DeviceExt
, FileObject
, FileName
);
92 if (FileObject
->RelatedFileObject
)
94 DPRINT("Converting relative filename to absolute filename\n");
96 Status
= NtfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
99 FileName
= AbsFileName
;
100 if (!NT_SUCCESS(Status
))
104 return(STATUS_UNSUCCESSFUL
);
107 //FIXME: Get cannonical path name (remove .'s, ..'s and extra separators)
109 DPRINT("PathName to open: %S\n", FileName
);
111 /* try first to find an existing FCB in memory */
112 DPRINT("Checking for existing FCB in memory\n");
113 Fcb
= NtfsGrabFCBFromTable(DeviceExt
,
117 DPRINT("No existing FCB found, making a new one if file exists.\n");
118 Status
= NtfsGetFCBForFile(DeviceExt
,
122 if (ParentFcb
!= NULL
)
124 NtfsReleaseFCB(DeviceExt
,
128 if (!NT_SUCCESS (Status
))
130 DPRINT("Could not make a new FCB, status: %x\n", Status
);
133 ExFreePool(AbsFileName
);
139 DPRINT("Attaching FCB to fileObject\n");
140 Status
= NtfsAttachFCBToFileObject(DeviceExt
,
145 ExFreePool (AbsFileName
);
152 NtfsCreateFile(PDEVICE_OBJECT DeviceObject
,
155 * FUNCTION: Opens a file
158 PDEVICE_EXTENSION DeviceExt
;
159 PIO_STACK_LOCATION Stack
;
160 PFILE_OBJECT FileObject
;
161 ULONG RequestedDisposition
;
162 // ULONG RequestedOptions;
167 DPRINT("NtfsCreateFile() called\n");
169 DeviceExt
= DeviceObject
->DeviceExtension
;
171 Stack
= IoGetCurrentIrpStackLocation (Irp
);
174 RequestedDisposition
= ((Stack
->Parameters
.Create
.Options
>> 24) & 0xff);
175 // RequestedOptions =
176 // Stack->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
177 // PagingFileCreate = (Stack->Flags & SL_OPEN_PAGING_FILE) ? TRUE : FALSE;
178 // if ((RequestedOptions & FILE_DIRECTORY_FILE)
179 // && RequestedDisposition == FILE_SUPERSEDE)
180 // return STATUS_INVALID_PARAMETER;
182 FileObject
= Stack
->FileObject
;
184 if (RequestedDisposition
== FILE_CREATE
||
185 RequestedDisposition
== FILE_OVERWRITE_IF
||
186 RequestedDisposition
== FILE_SUPERSEDE
)
188 return(STATUS_ACCESS_DENIED
);
191 Status
= NtfsOpenFile(DeviceExt
,
193 FileObject
->FileName
.Buffer
);
196 * If the directory containing the file to open doesn't exist then
199 Irp
->IoStatus
.Information
= (NT_SUCCESS(Status
)) ? FILE_OPENED
: 0;
200 Irp
->IoStatus
.Status
= Status
;
207 NtfsFsdCreate(PDEVICE_OBJECT DeviceObject
,
210 PDEVICE_EXTENSION DeviceExt
;
213 if (DeviceObject
== NtfsGlobalData
->DeviceObject
)
215 /* DeviceObject represents FileSystem instead of logical volume */
216 DPRINT("Opening file system\n");
217 Irp
->IoStatus
.Information
= FILE_OPENED
;
218 Status
= STATUS_SUCCESS
;
222 DeviceExt
= DeviceObject
->DeviceExtension
;
224 FsRtlEnterFileSystem();
225 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
227 Status
= NtfsCreateFile(DeviceObject
,
229 ExReleaseResourceLite(&DeviceExt
->DirResource
);
230 FsRtlExitFileSystem();
233 Irp
->IoStatus
.Status
= Status
;
234 IoCompleteRequest(Irp
,
235 NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);