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 /* FUNCTIONS ****************************************************************/
37 NtfsMakeAbsoluteFilename(PFILE_OBJECT pFileObject
,
38 PWSTR pRelativeFileName
,
39 PWSTR
*pAbsoluteFilename
)
44 DPRINT("try related for %S\n", pRelativeFileName
);
45 Fcb
= pFileObject
->FsContext
;
48 /* verify related object is a directory and target name
49 don't start with \. */
50 if (NtfsFCBIsDirectory(Fcb
) == FALSE
||
51 pRelativeFileName
[0] == L
'\\')
53 return STATUS_INVALID_PARAMETER
;
56 /* construct absolute path name */
57 ASSERT(wcslen (Fcb
->PathName
) + 1 + wcslen (pRelativeFileName
) + 1 <= MAX_PATH
);
58 rcName
= ExAllocatePoolWithTag(NonPagedPool
, MAX_PATH
* sizeof(WCHAR
), TAG_NTFS
);
61 return STATUS_INSUFFICIENT_RESOURCES
;
64 wcscpy(rcName
, Fcb
->PathName
);
65 if (!NtfsFCBIsRoot(Fcb
))
66 wcscat (rcName
, L
"\\");
67 wcscat (rcName
, pRelativeFileName
);
68 *pAbsoluteFilename
= rcName
;
70 return STATUS_SUCCESS
;
75 * FUNCTION: Opens a file
79 NtfsOpenFile(PDEVICE_EXTENSION DeviceExt
,
80 PFILE_OBJECT FileObject
,
86 PWSTR AbsFileName
= NULL
;
88 DPRINT("NtfsOpenFile(%p, %p, %S)\n", DeviceExt
, FileObject
, FileName
);
90 if (FileObject
->RelatedFileObject
)
92 DPRINT("Converting relative filename to absolute filename\n");
94 Status
= NtfsMakeAbsoluteFilename(FileObject
->RelatedFileObject
,
97 FileName
= AbsFileName
;
98 if (!NT_SUCCESS(Status
))
103 return STATUS_UNSUCCESSFUL
;
106 //FIXME: Get cannonical path name (remove .'s, ..'s and extra separators)
108 DPRINT("PathName to open: %S\n", FileName
);
110 /* try first to find an existing FCB in memory */
111 DPRINT("Checking for existing FCB in memory\n");
112 Fcb
= NtfsGrabFCBFromTable(DeviceExt
,
116 DPRINT("No existing FCB found, making a new one if file exists.\n");
117 Status
= NtfsGetFCBForFile(DeviceExt
,
121 if (ParentFcb
!= NULL
)
123 NtfsReleaseFCB(DeviceExt
,
127 if (!NT_SUCCESS (Status
))
129 DPRINT("Could not make a new FCB, status: %x\n", Status
);
132 ExFreePool(AbsFileName
);
138 DPRINT("Attaching FCB to fileObject\n");
139 Status
= NtfsAttachFCBToFileObject(DeviceExt
,
144 ExFreePool(AbsFileName
);
151 * FUNCTION: Opens a file
155 NtfsCreateFile(PDEVICE_OBJECT DeviceObject
,
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
;
208 NtfsFsdCreate(PDEVICE_OBJECT DeviceObject
,
211 PDEVICE_EXTENSION DeviceExt
;
214 if (DeviceObject
== NtfsGlobalData
->DeviceObject
)
216 /* DeviceObject represents FileSystem instead of logical volume */
217 DPRINT("Opening file system\n");
218 Irp
->IoStatus
.Information
= FILE_OPENED
;
219 Status
= STATUS_SUCCESS
;
223 DeviceExt
= DeviceObject
->DeviceExtension
;
225 FsRtlEnterFileSystem();
226 ExAcquireResourceExclusiveLite(&DeviceExt
->DirResource
,
228 Status
= NtfsCreateFile(DeviceObject
,
230 ExReleaseResourceLite(&DeviceExt
->DirResource
);
231 FsRtlExitFileSystem();
234 Irp
->IoStatus
.Status
= Status
;
235 IoCompleteRequest(Irp
,
236 NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);