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/dirctl.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMERS: Eric Kohl
24 * Hervé Poussineau (hpoussin@reactos.org)
27 /* INCLUDES *****************************************************************/
34 /* FUNCTIONS ****************************************************************/
37 * FUNCTION: Retrieve the standard file information
41 NtfsGetStandardInformation(PNTFS_FCB Fcb
,
42 PDEVICE_OBJECT DeviceObject
,
43 PFILE_STANDARD_INFORMATION StandardInfo
,
46 UNREFERENCED_PARAMETER(DeviceObject
);
48 DPRINT("NtfsGetStandardInformation() called\n");
50 if (*BufferLength
< sizeof(FILE_STANDARD_INFORMATION
))
51 return STATUS_BUFFER_OVERFLOW
;
54 ASSERT(StandardInfo
!= NULL
);
57 RtlZeroMemory(StandardInfo
,
58 sizeof(FILE_STANDARD_INFORMATION
));
60 StandardInfo
->AllocationSize
= Fcb
->RFCB
.AllocationSize
;
61 StandardInfo
->EndOfFile
= Fcb
->RFCB
.FileSize
;
62 StandardInfo
->NumberOfLinks
= 0;
63 StandardInfo
->DeletePending
= FALSE
;
64 StandardInfo
->Directory
= NtfsFCBIsDirectory(Fcb
);
66 *BufferLength
-= sizeof(FILE_STANDARD_INFORMATION
);
68 return STATUS_SUCCESS
;
74 NtfsGetPositionInformation(PFILE_OBJECT FileObject
,
75 PFILE_POSITION_INFORMATION PositionInfo
,
78 UNREFERENCED_PARAMETER(FileObject
);
80 DPRINT("NtfsGetPositionInformation() called\n");
82 if (*BufferLength
< sizeof(FILE_POSITION_INFORMATION
))
83 return STATUS_BUFFER_OVERFLOW
;
85 PositionInfo
->CurrentByteOffset
.QuadPart
= 0;
86 // FileObject->CurrentByteOffset.QuadPart;
88 DPRINT("Getting position %I64x\n",
89 PositionInfo
->CurrentByteOffset
.QuadPart
);
91 *BufferLength
-= sizeof(FILE_POSITION_INFORMATION
);
93 return STATUS_SUCCESS
;
99 NtfsGetBasicInformation(PFILE_OBJECT FileObject
,
101 PDEVICE_OBJECT DeviceObject
,
102 PFILE_BASIC_INFORMATION BasicInfo
,
105 DPRINT("NtfsGetBasicInformation() called\n");
107 if (*BufferLength
< sizeof(FILE_BASIC_INFORMATION
))
108 return STATUS_BUFFER_OVERFLOW
;
111 CdfsDateTimeToFileTime(Fcb
,
112 &BasicInfo
->CreationTime
);
113 CdfsDateTimeToFileTime(Fcb
,
114 &BasicInfo
->LastAccessTime
);
115 CdfsDateTimeToFileTime(Fcb
,
116 &BasicInfo
->LastWriteTime
);
117 CdfsDateTimeToFileTime(Fcb
,
118 &BasicInfo
->ChangeTime
);
120 CdfsFileFlagsToAttributes(Fcb
,
121 &BasicInfo
->FileAttributes
);
123 UNREFERENCED_PARAMETER(FileObject
);
124 UNREFERENCED_PARAMETER(Fcb
);
125 UNREFERENCED_PARAMETER(DeviceObject
);
126 UNREFERENCED_PARAMETER(BasicInfo
);
129 *BufferLength
-= sizeof(FILE_BASIC_INFORMATION
);
131 return STATUS_SUCCESS
;
136 * FUNCTION: Retrieve the file name information
140 NtfsGetNameInformation(PFILE_OBJECT FileObject
,
142 PDEVICE_OBJECT DeviceObject
,
143 PFILE_NAME_INFORMATION NameInfo
,
148 UNREFERENCED_PARAMETER(FileObject
);
149 UNREFERENCED_PARAMETER(DeviceObject
);
151 DPRINT("NtfsGetNameInformation() called\n");
153 ASSERT(NameInfo
!= NULL
);
156 /* If buffer can't hold at least the file name length, bail out */
157 if (*BufferLength
< (ULONG
)FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
[0]))
158 return STATUS_BUFFER_OVERFLOW
;
160 /* Save file name length, and as much file len, as buffer length allows */
161 NameInfo
->FileNameLength
= wcslen(Fcb
->PathName
) * sizeof(WCHAR
);
163 /* Calculate amount of bytes to copy not to overflow the buffer */
164 BytesToCopy
= min(NameInfo
->FileNameLength
,
165 *BufferLength
- FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
[0]));
167 /* Fill in the bytes */
168 RtlCopyMemory(NameInfo
->FileName
, Fcb
->PathName
, BytesToCopy
);
170 /* Check if we could write more but are not able to */
171 if (*BufferLength
< NameInfo
->FileNameLength
+ (ULONG
)FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
[0]))
173 /* Return number of bytes written */
174 *BufferLength
-= FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
[0]) + BytesToCopy
;
175 return STATUS_BUFFER_OVERFLOW
;
178 /* We filled up as many bytes, as needed */
179 *BufferLength
-= (FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
[0]) + NameInfo
->FileNameLength
);
181 return STATUS_SUCCESS
;
187 NtfsGetInternalInformation(PNTFS_FCB Fcb
,
188 PFILE_INTERNAL_INFORMATION InternalInfo
,
191 DPRINT("NtfsGetInternalInformation() called\n");
193 ASSERT(InternalInfo
);
196 if (*BufferLength
< sizeof(FILE_INTERNAL_INFORMATION
))
197 return STATUS_BUFFER_OVERFLOW
;
199 /* FIXME: get a real index, that can be used in a create operation */
200 InternalInfo
->IndexNumber
.QuadPart
= 0;
202 *BufferLength
-= sizeof(FILE_INTERNAL_INFORMATION
);
204 return STATUS_SUCCESS
;
209 NtfsGetNetworkOpenInformation(PNTFS_FCB Fcb
,
210 PDEVICE_EXTENSION DeviceExt
,
211 PFILE_NETWORK_OPEN_INFORMATION NetworkInfo
,
214 PFILENAME_ATTRIBUTE FileName
= &Fcb
->Entry
;
216 if (*BufferLength
< sizeof(FILE_NETWORK_OPEN_INFORMATION
))
217 return(STATUS_BUFFER_OVERFLOW
);
219 NetworkInfo
->CreationTime
.QuadPart
= FileName
->CreationTime
;
220 NetworkInfo
->LastAccessTime
.QuadPart
= FileName
->LastAccessTime
;
221 NetworkInfo
->LastWriteTime
.QuadPart
= FileName
->LastWriteTime
;
222 NetworkInfo
->ChangeTime
.QuadPart
= FileName
->ChangeTime
;
224 NetworkInfo
->EndOfFile
.QuadPart
= FileName
->AllocatedSize
;
225 NetworkInfo
->AllocationSize
.QuadPart
= ROUND_UP(FileName
->AllocatedSize
, DeviceExt
->NtfsInfo
.BytesPerCluster
);
227 NtfsFileFlagsToAttributes(FileName
->FileAttributes
, &NetworkInfo
->FileAttributes
);
229 *BufferLength
-= sizeof(FILE_NETWORK_OPEN_INFORMATION
);
230 return STATUS_SUCCESS
;
234 * FUNCTION: Retrieve the specified file information
238 NtfsFsdQueryInformation(PDEVICE_OBJECT DeviceObject
,
241 FILE_INFORMATION_CLASS FileInformationClass
;
242 PIO_STACK_LOCATION Stack
;
243 PFILE_OBJECT FileObject
;
247 NTSTATUS Status
= STATUS_SUCCESS
;
249 DPRINT("NtfsQueryInformation() called\n");
251 Stack
= IoGetCurrentIrpStackLocation(Irp
);
252 FileInformationClass
= Stack
->Parameters
.QueryFile
.FileInformationClass
;
253 FileObject
= Stack
->FileObject
;
254 Fcb
= FileObject
->FsContext
;
256 SystemBuffer
= Irp
->AssociatedIrp
.SystemBuffer
;
257 BufferLength
= Stack
->Parameters
.QueryFile
.Length
;
259 switch (FileInformationClass
)
261 case FileStandardInformation
:
262 Status
= NtfsGetStandardInformation(Fcb
,
268 case FilePositionInformation
:
269 Status
= NtfsGetPositionInformation(FileObject
,
274 case FileBasicInformation
:
275 Status
= NtfsGetBasicInformation(FileObject
,
282 case FileNameInformation
:
283 Status
= NtfsGetNameInformation(FileObject
,
290 case FileInternalInformation
:
291 Status
= NtfsGetInternalInformation(Fcb
,
296 case FileNetworkOpenInformation
:
297 Status
= NtfsGetNetworkOpenInformation(Fcb
,
298 DeviceObject
->DeviceExtension
,
303 case FileAlternateNameInformation
:
304 case FileAllInformation
:
305 Status
= STATUS_NOT_IMPLEMENTED
;
309 DPRINT("Unimplemented information class %u\n", FileInformationClass
);
310 Status
= STATUS_INVALID_PARAMETER
;
313 Irp
->IoStatus
.Status
= Status
;
315 if (NT_SUCCESS(Status
))
316 Irp
->IoStatus
.Information
=
317 Stack
->Parameters
.QueryFile
.Length
- BufferLength
;
319 Irp
->IoStatus
.Information
= 0;
321 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);